Ejemplo n.º 1
0
    /**
     * Record any index information for a given BAM record
     *
     * @param rec The BAM record. Requires rec.getFileSource() is non-null.
     */
    public void processAlignment(final SAMRecord rec) {

      // metadata
      indexStats.recordMetaData(rec);

      if (rec.getAlignmentStart() == SAMRecord.NO_ALIGNMENT_START) {
        return; // do nothing for records without coordinates, but count them
      }

      // various checks
      final int reference = rec.getReferenceIndex();
      if (reference != currentReference) {
        throw new SAMException(
            "Unexpected reference "
                + reference
                + " when constructing index for "
                + currentReference
                + " for record "
                + rec);
      }

      binningIndexBuilder.processFeature(
          new BinningIndexBuilder.FeatureToBeIndexed() {
            @Override
            public int getStart() {
              return rec.getAlignmentStart();
            }

            @Override
            public int getEnd() {
              return rec.getAlignmentEnd();
            }

            @Override
            public Integer getIndexingBin() {
              final Integer binNumber = rec.getIndexingBin();
              return (binNumber == null ? rec.computeIndexingBin() : binNumber);
            }

            @Override
            public Chunk getChunk() {
              final SAMFileSource source = rec.getFileSource();
              if (source == null) {
                throw new SAMException(
                    "No source (virtual file offsets); needed for indexing on BAM Record " + rec);
              }
              return ((BAMFileSpan) source.getFilePointer()).getSingleChunk();
            }
          });
    }
Ejemplo n.º 2
0
    /**
     * Creates the BAMIndexContent for this reference. Requires all alignments of the reference have
     * already been processed.
     *
     * @return Null if there are no features for this reference.
     */
    public BAMIndexContent processReference(final int reference) {

      if (reference != currentReference) {
        throw new SAMException(
            "Unexpected reference "
                + reference
                + " when constructing index for "
                + currentReference);
      }

      final BinningIndexContent indexContent = binningIndexBuilder.generateIndexContent();
      if (indexContent == null) return null;
      return new BAMIndexContent(
          indexContent.getReferenceSequence(),
          indexContent.getBins(),
          indexStats,
          indexContent.getLinearIndex());
    }