Package htsjdk.samtools
Class BAMRecordCodec
- java.lang.Object
-
- htsjdk.samtools.BAMRecordCodec
-
- All Implemented Interfaces:
SortingCollection.Codec<SAMRecord>
,Cloneable
public class BAMRecordCodec extends Object implements SortingCollection.Codec<SAMRecord>
Class for translating between in-memory and disk representation of BAMRecord.
-
-
Constructor Summary
Constructors Constructor Description BAMRecordCodec(SAMFileHeader header)
BAMRecordCodec(SAMFileHeader header, SAMRecordFactory factory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BAMRecordCodec
clone()
Must return a cloned copy of the codec that can be used independently of the original instance.SAMRecord
decode()
Read the next record from the input stream and convert into a java object.void
encode(SAMRecord alignment)
Write object to OutputStream.static Cigar
makeSentinelCigar(Cigar cigar)
Create a "Sentinel" cigar that will be placed in BAM file when the actual cigar has more than 0xffff operator, which are not supported by the bam format.void
setInputStream(InputStream is)
Sets the input stream that records will be read from.void
setInputStream(InputStream is, String filename)
Sets the input stream that records will be read from.void
setOutputStream(OutputStream os)
Sets the output stream that records will be written to.void
setOutputStream(OutputStream os, String filename)
Sets the output stream that records will be written to.
-
-
-
Constructor Detail
-
BAMRecordCodec
public BAMRecordCodec(SAMFileHeader header)
-
BAMRecordCodec
public BAMRecordCodec(SAMFileHeader header, SAMRecordFactory factory)
-
-
Method Detail
-
clone
public BAMRecordCodec clone()
Description copied from interface:SortingCollection.Codec
Must return a cloned copy of the codec that can be used independently of the original instance. This is required so that multiple codecs can exist simultaneously that each is reading a separate file.- Specified by:
clone
in interfaceSortingCollection.Codec<SAMRecord>
- Overrides:
clone
in classObject
-
setOutputStream
public void setOutputStream(OutputStream os)
Sets the output stream that records will be written to.- Specified by:
setOutputStream
in interfaceSortingCollection.Codec<SAMRecord>
-
setOutputStream
public void setOutputStream(OutputStream os, String filename)
Sets the output stream that records will be written to.
-
setInputStream
public void setInputStream(InputStream is)
Sets the input stream that records will be read from.- Specified by:
setInputStream
in interfaceSortingCollection.Codec<SAMRecord>
-
setInputStream
public void setInputStream(InputStream is, String filename)
Sets the input stream that records will be read from.
-
encode
public void encode(SAMRecord alignment)
Write object to OutputStream. Reference and mate reference indices must be resolvable, which either means that these have been set into the SAMRecord directly, or the SAMRecord must have a header assigned into it so that reference names can be resolved into indices.- Specified by:
encode
in interfaceSortingCollection.Codec<SAMRecord>
- Parameters:
alignment
- Record to be written.
-
makeSentinelCigar
public static Cigar makeSentinelCigar(Cigar cigar)
Create a "Sentinel" cigar that will be placed in BAM file when the actual cigar has more than 0xffff operator, which are not supported by the bam format. The actual cigar will be encoded and placed in the CG attribute.- Parameters:
cigar
- actual cigar to create sentinel cigar for- Returns:
- sentinel cigar xSyN with readLength (x) and referenceLength (y) matching the input cigar.
-
decode
public SAMRecord decode()
Read the next record from the input stream and convert into a java object.- Specified by:
decode
in interfaceSortingCollection.Codec<SAMRecord>
- Returns:
- null if no more records. Should throw exception if EOF is encountered in the middle of a record.
-
-