Class SAMRecordSetBuilder

  • All Implemented Interfaces:
    Iterable<SAMRecord>

    public class SAMRecordSetBuilder
    extends Object
    implements Iterable<SAMRecord>
    Factory class for creating SAMRecords for testing purposes. Various methods can be called to add new SAM records (or pairs of records) to a list which can then be returned at any point. The records must reference human chromosomes (excluding randoms etc.).

    Although this is a class for testing, it is in the src tree because it is included in the sam jarfile.

    • Constructor Detail

      • SAMRecordSetBuilder

        public SAMRecordSetBuilder()
        Constructs a new SAMRecordSetBuilder with all the data needed to keep the records sorted in coordinate order.
      • SAMRecordSetBuilder

        public SAMRecordSetBuilder​(boolean sortForMe,
                                   SAMFileHeader.SortOrder sortOrder)
        Construct a new SAMRecordSetBuilder.
        Parameters:
        sortOrder - If sortForMe, defines the sort order.
        sortForMe - If true, keep the records created in sorted order.
      • SAMRecordSetBuilder

        public SAMRecordSetBuilder​(boolean sortForMe,
                                   SAMFileHeader.SortOrder sortOrder,
                                   boolean addReadGroup)
      • SAMRecordSetBuilder

        public SAMRecordSetBuilder​(boolean sortForMe,
                                   SAMFileHeader.SortOrder sortOrder,
                                   boolean addReadGroup,
                                   int defaultChromosomeLength)
    • Method Detail

      • setUseBamFile

        public void setUseBamFile​(boolean useBamFile)
        Determine whether the class will use a bam (default) or a sam file to hold the records when providing a reader to them.
        Parameters:
        useBamFile - if true will use a BAM file, otherwise it will use a SAM file to hold the records.
      • setUnmappedHasBasesAndQualities

        public void setUnmappedHasBasesAndQualities​(boolean value)
      • size

        public int size()
      • setRandomSeed

        public void setRandomSeed​(long seed)
        Set the seed of the random number generator for cases in which repeatable result is desired.
        Parameters:
        seed -
      • setProgramRecord

        public void setProgramRecord​(SAMProgramRecord programRecord)
        Adds the given program record to the header, and assigns the PG tag to any SAMRecords created after it has been added. May be called multiple times in order to assign different PG IDs to different SAMRecords. programRecord may be null to stop assignment of PG tag. It is up to the caller to ensure that program record IDs do not collide.
      • setUseNmFlag

        public void setUseNmFlag​(boolean useNmFlag)
      • getRecords

        public Collection<SAMRecord> getRecords()
        Returns the accumulated list of sam records.
      • addRecord

        public void addRecord​(SAMRecord record)
        The record should already have the DS and MC tags computed
      • addFrag

        public SAMRecord addFrag​(String name,
                                 int contig,
                                 int start,
                                 boolean negativeStrand)
        Adds a skeletal fragment (non-PE) record to the set using the provided contig start and strand information.
      • addFrag

        public SAMRecord addFrag​(String name,
                                 int contig,
                                 int start,
                                 boolean negativeStrand,
                                 boolean recordUnmapped,
                                 String cigar,
                                 String qualityString,
                                 int defaultQuality)
                          throws SAMException
        Adds a fragment record (mapped or unmapped) to the set using the provided contig start and optionally the strand, cigar string, quality string or default quality score.
        Throws:
        SAMException
      • addFrag

        public SAMRecord addFrag​(String name,
                                 int contig,
                                 int start,
                                 boolean negativeStrand,
                                 boolean recordUnmapped,
                                 String cigar,
                                 String qualityString,
                                 int defaultQuality,
                                 boolean isSecondary)
                          throws SAMException
        Adds a fragment record (mapped or unmapped) to the set using the provided contig start and optionally the strand, cigar string, quality string or default quality score.
        Throws:
        SAMException
      • addFrag

        public SAMRecord addFrag​(String name,
                                 int contig,
                                 int start,
                                 boolean negativeStrand,
                                 boolean recordUnmapped,
                                 String cigar,
                                 String qualityString,
                                 int defaultQuality,
                                 boolean isSecondary,
                                 boolean isSupplementary)
                          throws SAMException
        Adds a fragment record (mapped or unmapped) to the set using the provided contig start and optionally the strand, cigar string, quality string or default quality score.
        Throws:
        SAMException
      • addUnmappedFragment

        public void addUnmappedFragment​(String name)
        Adds an unmapped fragment read to the builder.
      • addPair

        public void addPair​(String name,
                            int contig,
                            int start1,
                            int start2)
        Adds a skeletal pair of records to the set using the provided contig starts. The pair is assumed to be a well formed pair sitting on a single contig.
      • addPair

        public List<SAMRecord> addPair​(String name,
                                       int contig,
                                       int start1,
                                       int start2,
                                       boolean record1Unmapped,
                                       boolean record2Unmapped,
                                       String cigar1,
                                       String cigar2,
                                       boolean strand1,
                                       boolean strand2,
                                       int defaultQuality)
        Adds a pair of records (mapped or unmmapped) to the set using the provided contig starts. The pair is assumed to be a well formed pair sitting on a single contig.
      • addPair

        public List<SAMRecord> addPair​(String name,
                                       int contig1,
                                       int contig2,
                                       int start1,
                                       int start2,
                                       boolean record1Unmapped,
                                       boolean record2Unmapped,
                                       String cigar1,
                                       String cigar2,
                                       boolean strand1,
                                       boolean strand2,
                                       boolean record1NonPrimary,
                                       boolean record2NonPrimary,
                                       int defaultQuality)
        Adds a pair of records (mapped or unmmapped) to the set using the provided contig starts. The pair is assumed to be a well formed pair sitting on a single contig.
      • addPair

        public List<SAMRecord> addPair​(String name,
                                       int contig,
                                       int start1,
                                       int start2,
                                       boolean record1Unmapped,
                                       boolean record2Unmapped,
                                       String cigar1,
                                       String cigar2,
                                       boolean strand1,
                                       boolean strand2,
                                       boolean record1NonPrimary,
                                       boolean record2NonPrimary,
                                       int defaultQuality)
        Adds a pair of records (mapped or unmmapped) to the set using the provided contig starts. The pair is assumed to be a well formed pair sitting on a single contig.
      • addUnmappedPair

        public void addUnmappedPair​(String name)
        Adds a pair with both ends unmapped to the builder.
      • getSamReader

        public SamReader getSamReader()
        Creates samFileReader from the data in instance of this class
        Returns:
        SamReader
      • setReadLength

        public void setReadLength​(int readLength)