Beispiel #1
1
 public static String prettyPrintSequenceRecords(SAMSequenceDictionary sequenceDictionary) {
   String[] sequenceRecordNames = new String[sequenceDictionary.size()];
   int sequenceRecordIndex = 0;
   for (SAMSequenceRecord sequenceRecord : sequenceDictionary.getSequences())
     sequenceRecordNames[sequenceRecordIndex++] = sequenceRecord.getSequenceName();
   return Arrays.deepToString(sequenceRecordNames);
 }
 private static void setIndexSequenceDictionary(
     final Index index, final SAMSequenceDictionary dict) {
   for (final SAMSequenceRecord seq : dict.getSequences()) {
     final String contig = SequenceDictionaryPropertyPredicate + seq.getSequenceName();
     final String length = String.valueOf(seq.getSequenceLength());
     index.addProperty(contig, length);
   }
 }
Beispiel #3
0
 /**
  * create a list of genomic locations, given a reference sequence
  *
  * @param dict the sequence dictionary to create a collection from
  * @return the GenomeLocSet of all references sequences as GenomeLoc's
  */
 public static GenomeLocSortedSet createSetFromSequenceDictionary(SAMSequenceDictionary dict) {
   GenomeLocParser parser = new GenomeLocParser(dict);
   GenomeLocSortedSet returnSortedSet = new GenomeLocSortedSet(parser);
   for (SAMSequenceRecord record : dict.getSequences()) {
     returnSortedSet.add(
         parser.createGenomeLoc(record.getSequenceName(), 1, record.getSequenceLength()));
   }
   return returnSortedSet;
 }
Beispiel #4
0
 /**
  * Throw an exception if all the "to" sequence names in the chains are not found in the given
  * sequence dictionary.
  */
 public void validateToSequences(final SAMSequenceDictionary sequenceDictionary) {
   for (final Chain chain : chains.getAll()) {
     if (sequenceDictionary.getSequence(chain.toSequenceName) == null) {
       throw new PicardException(
           "Sequence "
               + chain.toSequenceName
               + " from chain file is not found in sequence dictionary.");
     }
   }
 }
Beispiel #5
0
  // copied from LocusViewTemplate
  protected GATKSAMRecord buildSAMRecord(
      final String readName, final String contig, final int alignmentStart) {
    GATKSAMRecord record = new GATKSAMRecord(header);

    record.setReadName(readName);
    record.setReferenceIndex(dictionary.getSequenceIndex(contig));
    record.setAlignmentStart(alignmentStart);

    record.setCigarString("1M");
    record.setReadString("A");
    record.setBaseQualityString("A");
    record.setReadGroup(readGroup);

    return record;
  }
Beispiel #6
0
 public static Interval parseOne(SAMSequenceDictionary dict, String s) {
   int colon = s.indexOf(':');
   if (colon < 1 || colon + 1 == s.length()) return null;
   int hyphen = s.indexOf('-', colon + 1);
   if (hyphen == -1) return null;
   int start, end;
   try {
     SAMSequenceRecord ssr = null;
     String chrom = s.substring(0, colon);
     if (dict != null) {
       ssr = dict.getSequence(chrom);
       if (ssr == null) return null;
     }
     start = Integer.parseInt(s.substring(colon + 1, hyphen));
     end = Integer.parseInt(s.substring(hyphen + 1));
     if (end < start) return null;
     return new Interval(s.substring(0, colon), start, end);
   } catch (Exception e) {
     return null;
   }
 }
Beispiel #7
0
  public Datum map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
    GenomeLoc cur = context.getLocation();

    if (verbose && showSkipped) {
      for (long i = context.getSkippedBases(); i >= 0; i--) {
        SAMSequenceDictionary dictionary =
            getToolkit().getReferenceDataSource().getReference().getSequenceDictionary();
        SAMSequenceRecord contig = dictionary.getSequence(cur.getContig());
        if (cur.getStop() < contig.getSequenceLength())
          cur = getToolkit().getGenomeLocParser().incPos(cur, 1);
        else
          cur =
              getToolkit()
                  .getGenomeLocParser()
                  .createGenomeLoc(
                      dictionary.getSequence(contig.getSequenceIndex() + 1).getSequenceName(),
                      1,
                      1);
        out.printf("%s: skipped%n", cur);
      }
    }

    long nRodsHere = 0;
    long nTotalBases = 0;

    if (ref == null) {
      // we're getting the last skipped update
      if (verbose)
        out.printf(
            "Last position was %s: skipping %d bases%n",
            context.getLocation(), context.getSkippedBases());
      nRodsHere = -1; // don't update this
      nTotalBases = context.getSkippedBases();
    } else {
      Collection<RODRecordList> rods = new LinkedList<RODRecordList>();
      for (RODRecordList rod : tracker.getBoundRodTracks()) {
        // System.out.printf("Considering rod %s%n", rod);
        if (rod.getLocation().getStart() == context.getLocation().getStart()
            && !rod.getName().equals("interval")) {
          // only consider the first element
          // System.out.printf("adding it%n");
          rods.add(rod);
        }
      }

      nRodsHere = rods.size();

      if (nRodsHere > 0) {
        if (verbose) {
          List<String> names = new ArrayList<String>();
          for (RODRecordList rod : rods) {
            names.add(rod.getName());
          }

          // System.out.printf("context is %s", context.getSkippedBases());
          out.printf(
              "At %s: found %d rod(s) [%s] after skipping %d bases%n",
              context.getLocation(), nRodsHere, Utils.join(",", names), context.getSkippedBases());
        }
      }

      nTotalBases = context.getSkippedBases() + 1;
    }

    return new Datum(nRodsHere, context.getSkippedBases(), nTotalBases);
  }