예제 #1
0
  /**
   * Calculate snp effect for a list of snps
   *
   * @param snpEffFile
   */
  public void snpEffect(String vcfFile, String txtFile, String aaHgsv, String genotype) {
    // Create command
    String argsVcf[] = {"-classic", "-cancer", "-hgvs", "testHg3766Chr1", vcfFile};
    String argsTxt[] = {
      "-classic", "-cancer", "-cancerSamples", txtFile, "-hgvs", "testHg3766Chr1", vcfFile
    };
    String args[] = (txtFile == null ? argsVcf : argsTxt);

    SnpEff cmd = new SnpEff(args);
    SnpEffCmdEff cmdEff = (SnpEffCmdEff) cmd.snpEffCmd();

    // Run command
    List<VcfEntry> list = cmdEff.run(true);

    // Find AA change for a genotype
    boolean found = false;
    for (VcfEntry vcfEntry : list) {
      for (VcfEffect eff : vcfEntry.parseEffects()) {
        if (genotype.equals(eff.getGenotype())) {
          if (debug) Gpr.debug("AA: " + eff.getAa() + "\t" + eff.getGenotype() + "\t" + eff);
          Assert.assertEquals(aaHgsv, eff.getAa());
          found = true;
        }
      }
    }

    // Not found? Error
    if (!found) throw new RuntimeException("Genotype '" + genotype + "' not found.");
  }
예제 #2
0
  /** Add some lines to header before showing it */
  @Override
  public boolean addHeaders(VcfFileIterator vcfFile) {
    super.addHeaders(vcfFile);
    for (String key : fieldsToAdd.keySet()) {
      // Get type
      String type = fieldsType.get(key);
      if (type == null) {
        System.err.println("WARNING: Cannot find type for field '" + key + "', using 'String'.");
        type = VcfInfoType.String.toString();
      }

      String infoKey = VcfEntry.vcfInfoKeySafe(DBNSFP_VCF_INFO_PREFIX + key);
      vcfFile
          .getVcfHeader()
          .addLine(
              "##INFO=<ID="
                  + infoKey
                  + ",Number=A,Type="
                  + type
                  + ",Description=\""
                  + fieldsToAdd.get(key)
                  + "\">");
    }

    return false;
  }
예제 #3
0
  @Override
  public boolean annotate(VcfEntry vcfEntry) {
    boolean annotated = false;
    Map<String, String> info = new HashMap<>();

    // Find annotations for each variant in this VcfEntry
    for (Variant var : vcfEntry.variants()) annotated |= annotate(var, info);

    // Add annotations to VcfEntry
    if (annotated) {
      // Sort keys and add them to VcfEntry
      ArrayList<String> keys = new ArrayList<>();
      keys.addAll(info.keySet());
      Collections.sort(keys);

      // Add INFO fields
      for (String key : keys) {
        String infoKey = VcfEntry.vcfInfoKeySafe(DBNSFP_VCF_INFO_PREFIX + key);
        vcfEntry.addInfo(infoKey, info.get(key));
      }
    }

    return annotated;
  }
예제 #4
0
  /** Annotate a VCF file using dbNSFP */
  ArrayList<VcfEntry> annotate(boolean createList) {
    ArrayList<VcfEntry> list = (createList ? new ArrayList<VcfEntry>() : null);

    // Open VCF file
    vcfFile = new VcfFileIterator(vcfFileName);
    vcfFile.setDebug(debug);

    // Initialize annotations
    try {
      annotateInit(vcfFile);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // Annotate VCF file
    if (verbose) Timer.showStdErr("Annotating file '" + vcfFileName + "'");
    boolean showHeader = true;
    int pos = -1;
    String chr = "";
    for (VcfEntry vcfEntry : vcfFile) {
      try {
        // Show header?
        if (showHeader) {
          // Add VCF header
          addHeaders(vcfFile);
          String headerStr = vcfFile.getVcfHeader().toString();
          if (!headerStr.isEmpty()) print(headerStr);
          showHeader = false;

          // Check that the fields we want to add are actually in the database
          checkFieldsToAdd();
        }

        // Check if file is sorted
        if (vcfEntry.getChromosomeName().equals(chr) && vcfEntry.getStart() < pos) {
          fatalError(
              "Your VCF file should be sorted!" //
                  + "\n\tPrevious entry "
                  + chr
                  + ":"
                  + pos //
                  + "\n\tCurrent entry  "
                  + vcfEntry.getChromosomeName()
                  + ":"
                  + (vcfEntry.getStart() + 1) //
              );
        }

        // Annotate
        annotate(vcfEntry);

        // Show
        print(vcfEntry);
        if (list != null) list.add(vcfEntry);
        count++;

        // Update chr:pos
        chr = vcfEntry.getChromosomeName();
        pos = vcfEntry.getStart();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }

    annotateFinish();
    vcfFile.close();

    // Show some stats
    if (verbose) {
      double perc = (100.0 * countAnnotated) / count;
      Timer.showStdErr(
          "Done." //
              + "\n\tTotal annotated entries : "
              + countAnnotated //
              + "\n\tTotal entries           : "
              + count //
              + "\n\tPercent                 : "
              + String.format("%.2f%%", perc) //
          );
    }

    return list;
  }