예제 #1
0
  private boolean addAnnotationsFromString(VariantRec var, String str)
      throws OperationFailedException {
    String[] toks = str.split("\t");
    if (!toks[0].equals(var.getContig())) {
      // We expect that sometimes we'll not get the right contig
      return false;
    }
    if (!toks[1].equals("" + var.getStart())) {
      // We expect that sometimes we'll not get the right position (not sure why exactly... tabix
      // doesn't work perfectly I guess			return;
    }

    if (toks[4].equals(var.getAlt())) {
      String rsNum = toks[2];
      var.addAnnotation(VariantRec.RSNUM, rsNum);
      return true;
    }
    return false;
  }
예제 #2
0
 /**
  * Parses allele frequency annotation from the given string and converts it to a property on the
  * variant
  *
  * @param var
  * @param str
  * @throws OperationFailedException
  */
 @Override
 protected boolean addAnnotationsFromString(VariantRec var, String val, int altIndex) {
   String[] toks = val.split("\t");
   String[] formatToks = toks[7].split(";");
   String overallFreqStr = valueForKey(formatToks, "AF=");
   if (overallFreqStr != null) {
     Double af = Double.parseDouble(overallFreqStr);
     var.addProperty(VariantRec.UK10K_ALLELE_FREQ, af);
   }
   return true;
 }
예제 #3
0
  @Override
  public void annotateVariant(VariantRec var) throws OperationFailedException {
    if (reader == null) {
      initializeReader();
    }

    if (reader == null) {
      throw new OperationFailedException("Could not initialize tabix reader", this);
    }

    String contig = var.getContig();
    Integer pos = var.getStart();

    String queryStr = contig + ":" + pos + "-" + (pos);
    // int count = 0;
    try {
      TabixReader.Iterator iter = reader.query(queryStr);

      if (iter != null) {
        try {
          String val = iter.next();
          while (val != null) {
            boolean ok = addAnnotationsFromString(var, val);
            if (ok) {
              break;
            }
            val = iter.next();
          }
        } catch (IOException e) {
          throw new OperationFailedException(
              "Error reading dbSNP data file: " + e.getMessage(), this);
        }
      }
    } catch (RuntimeException rex) {
      // Bad contigs will cause an array out-of-bounds exception to be thrown by
      // the tabix reader. There's not much we can do about this since the methods
      // are private... right now we just ignore it and skip this variant
    }
  }