Package htsjdk.samtools
Class SAMRecordSetBuilder
java.lang.Object
htsjdk.samtools.SAMRecordSetBuilder
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final DuplicateScoringStrategy.ScoringStrategy
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new SAMRecordSetBuilder with all the data needed to keep the records sorted in coordinate order.SAMRecordSetBuilder
(boolean sortForMe, SAMFileHeader.SortOrder sortOrder) Construct a new SAMRecordSetBuilder.SAMRecordSetBuilder
(boolean sortForMe, SAMFileHeader.SortOrder sortOrder, boolean addReadGroup) SAMRecordSetBuilder
(boolean sortForMe, SAMFileHeader.SortOrder sortOrder, boolean addReadGroup, int defaultChromosomeLength) SAMRecordSetBuilder
(boolean sortForMe, SAMFileHeader.SortOrder sortOrder, boolean addReadGroup, int defaultChromosomeLength, DuplicateScoringStrategy.ScoringStrategy duplicateScoringStrategy) -
Method Summary
Modifier and TypeMethodDescriptionAdds a skeletal fragment (non-PE) record to the set using the provided contig start and strand information.addFrag
(String name, int contig, int start, boolean negativeStrand, boolean recordUnmapped, String cigar, String qualityString, int defaultQuality) 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.addFrag
(String name, int contig, int start, boolean negativeStrand, boolean recordUnmapped, String cigar, String qualityString, int defaultQuality, boolean isSecondary) 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.addFrag
(String name, int contig, int start, boolean negativeStrand, boolean recordUnmapped, String cigar, String qualityString, int defaultQuality, boolean isSecondary, boolean isSupplementary) 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.void
Adds a skeletal pair of records to the set using the provided contig starts.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.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.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.void
The record should already have the DS and MC tags computedvoid
addUnmappedFragment
(String name) Adds an unmapped fragment read to the builder.void
addUnmappedPair
(String name) Adds a pair with both ends unmapped to the builder.Returns the accumulated list of sam records.Creates samFileReader from the data in instance of this classiterator()
Returns a CloseableIterator over the collection of SAMRecords.static SAMFileHeader
makeDefaultHeader
(SAMFileHeader.SortOrder sortOrder, int contigLength, boolean addReadGroup) creates a simple headervoid
setHeader
(SAMFileHeader header) 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.void
setRandomSeed
(long seed) Set the seed of the random number generator for cases in which repeatable result is desired.void
setReadGroup
(SAMReadGroupRecord readGroup) void
setReadLength
(int readLength) void
setUnmappedHasBasesAndQualities
(boolean value) 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.void
setUseNmFlag
(boolean useNmFlag) int
size()
static void
writeRandomReference
(SAMFileHeader header, Path fasta) Writes a random (but deterministic) reference file given aSAMFileHeader
output file is expected to have a non-compressed fasta suffix.void
writeRandomReference
(Path fasta) Writes a random (but deterministic) reference file given aSAMFileHeader
output file is expected to have a non-compressed fasta suffix.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_CHROMOSOME_LENGTH
public static final int DEFAULT_CHROMOSOME_LENGTH- See Also:
-
DEFAULT_DUPLICATE_SCORING_STRATEGY
-
-
Constructor Details
-
SAMRecordSetBuilder
public SAMRecordSetBuilder()Constructs a new SAMRecordSetBuilder with all the data needed to keep the records sorted in coordinate order. -
SAMRecordSetBuilder
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) -
SAMRecordSetBuilder
public SAMRecordSetBuilder(boolean sortForMe, SAMFileHeader.SortOrder sortOrder, boolean addReadGroup, int defaultChromosomeLength, DuplicateScoringStrategy.ScoringStrategy duplicateScoringStrategy)
-
-
Method Details
-
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. -
setProgramRecord
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) -
setReadGroup
-
getRecords
Returns the accumulated list of sam records. -
setHeader
-
addRecord
The record should already have the DS and MC tags computed -
iterator
Returns a CloseableIterator over the collection of SAMRecords. -
addFrag
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
Adds an unmapped fragment read to the builder. -
addPair
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
Adds a pair with both ends unmapped to the builder. -
getSamReader
Creates samFileReader from the data in instance of this class- Returns:
- SamReader
-
getHeader
-
setReadLength
public void setReadLength(int readLength) -
makeDefaultHeader
public static SAMFileHeader makeDefaultHeader(SAMFileHeader.SortOrder sortOrder, int contigLength, boolean addReadGroup) creates a simple header- Parameters:
sortOrder
- Use this sort order in the headercontigLength
- length of the other contigs- Returns:
- newly formed header
-
writeRandomReference
Writes a random (but deterministic) reference file given aSAMFileHeader
output file is expected to have a non-compressed fasta suffix. Method will also write .dict and .fai files next to the reference file. files next to the provided. Will use the currentSAMFileHeader
to model the reference on.- Parameters:
fasta
- Path to output reference where it will be written. No checks will be performed regarding the writability, or existence of the files prior to writing.- Throws:
IOException
- In case of problem during writing the files.
-
writeRandomReference
Writes a random (but deterministic) reference file given aSAMFileHeader
output file is expected to have a non-compressed fasta suffix. Method will also write .dict and .fai files next to the reference file. files next to the provided- Parameters:
header
- Header file to base the reference on. Length and names of sequences will be taken from here, as will the order of the contigs in the reference.fasta
- Path to output reference where it will be written. No checks will be performed regarding the writability, or existence of the files prior to writing.- Throws:
IOException
- In case of problem during writing the files.
-