Package htsjdk.samtools
Class SAMFileHeader
- java.lang.Object
-
- htsjdk.samtools.AbstractSAMHeaderRecord
-
- htsjdk.samtools.SAMFileHeader
-
- All Implemented Interfaces:
Serializable
public class SAMFileHeader extends AbstractSAMHeaderRecord
Header information from a SAM or BAM file.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSAMFileHeader.GroupOrderstatic classSAMFileHeader.PgIdGeneratorLittle class to generate program group IDsstatic classSAMFileHeader.SortOrderWays in which a SAM or BAM may be sorted.
-
Field Summary
Fields Modifier and Type Field Description static Set<String>ACCEPTABLE_VERSIONSstatic StringCURRENT_VERSIONstatic StringGROUP_ORDER_TAGstatic StringSORT_ORDER_TAGstatic Set<String>STANDARD_TAGSThese tags are of known type, so don't need a type field in the text representation.static StringVERSION_TAG-
Fields inherited from class htsjdk.samtools.AbstractSAMHeaderRecord
serialVersionUID
-
-
Constructor Summary
Constructors Constructor Description SAMFileHeader()SAMFileHeader(SAMSequenceDictionary dict)Constructor that initializes the sequence dictionary with the provided one.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddComment(String comment)voidaddProgramRecord(SAMProgramRecord programRecord)voidaddReadGroup(SAMReadGroupRecord readGroup)voidaddSequence(SAMSequenceRecord sequenceRecord)voidaddValidationError(SAMValidationError error)SAMFileHeaderclone()SAMProgramRecordcreateProgramRecord()booleanequals(Object o)List<String>getComments()StringgetCreator()SAMFileHeader.GroupOrdergetGroupOrder()SAMProgramRecordgetProgramRecord(String pgId)List<SAMProgramRecord>getProgramRecords()SAMReadGroupRecordgetReadGroup(String name)Look up read group record by name.List<SAMReadGroupRecord>getReadGroups()StringgetSAMString()Returns the record in the SAM line-based text format.SAMSequenceRecordgetSequence(int sequenceIndex)Look up a sequence record by index.SAMSequenceRecordgetSequence(String name)Look up sequence record by name.SAMSequenceDictionarygetSequenceDictionary()intgetSequenceIndex(String sequenceName)SAMFileHeader.SortOrdergetSortOrder()StringgetTextHeader()If this SAMHeader was read from a file, this property contains the header as it appeared in the file, otherwise it is null.List<SAMValidationError>getValidationErrors()StringgetVersion()inthashCode()voidsetAttribute(String key, Object value)Deprecated.UseinsteadvoidsetAttribute(String key, String value)Set the given value for the attribute named 'key'.voidsetComments(Collection<String> comments)Replace existing comments with the contents of the given collection.voidsetGroupOrder(SAMFileHeader.GroupOrder go)voidsetProgramRecords(List<SAMProgramRecord> programRecords)Replace entire list of program recordsvoidsetReadGroups(List<SAMReadGroupRecord> readGroups)Replace entire list of read groups.voidsetSequenceDictionary(SAMSequenceDictionary sequenceDictionary)Replace entire sequence dictionary.voidsetSortOrder(SAMFileHeader.SortOrder so)voidsetTextHeader(String textHeader)voidsetValidationErrors(Collection<SAMValidationError> errors)Replace list of validation errors with the elements of the given list.-
Methods inherited from class htsjdk.samtools.AbstractSAMHeaderRecord
attributesEqual, attributesHashCode, getAttribute, getAttributes, getId, toString
-
-
-
-
Field Detail
-
VERSION_TAG
public static final String VERSION_TAG
- See Also:
- Constant Field Values
-
SORT_ORDER_TAG
public static final String SORT_ORDER_TAG
- See Also:
- Constant Field Values
-
GROUP_ORDER_TAG
public static final String GROUP_ORDER_TAG
- See Also:
- Constant Field Values
-
CURRENT_VERSION
public static final String CURRENT_VERSION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SAMFileHeader
public SAMFileHeader()
-
SAMFileHeader
public SAMFileHeader(SAMSequenceDictionary dict)
Constructor that initializes the sequence dictionary with the provided one.
-
-
Method Detail
-
getVersion
public String getVersion()
-
getCreator
public String getCreator()
-
getSequenceDictionary
public SAMSequenceDictionary getSequenceDictionary()
-
getReadGroups
public List<SAMReadGroupRecord> getReadGroups()
-
getSequence
public SAMSequenceRecord getSequence(String name)
Look up sequence record by name.- Returns:
- sequence record if it's found by name, or null if sequence dictionary is empty or if the sequence is not found in the dictionary.
-
getReadGroup
public SAMReadGroupRecord getReadGroup(String name)
Look up read group record by name.
-
setSequenceDictionary
public void setSequenceDictionary(SAMSequenceDictionary sequenceDictionary)
Replace entire sequence dictionary. The given sequence dictionary is stored, not copied.
-
addSequence
public void addSequence(SAMSequenceRecord sequenceRecord)
-
getSequence
public SAMSequenceRecord getSequence(int sequenceIndex)
Look up a sequence record by index. First sequence in the header is the 0th.- Returns:
- The corresponding sequence record, or null if the index is out of range.
-
getSequenceIndex
public int getSequenceIndex(String sequenceName)
- Returns:
- Sequence index for the given sequence name, or -1 if the name is not found.
-
setReadGroups
public void setReadGroups(List<SAMReadGroupRecord> readGroups)
Replace entire list of read groups. The given list is stored, not copied.
-
addReadGroup
public void addReadGroup(SAMReadGroupRecord readGroup)
-
getProgramRecords
public List<SAMProgramRecord> getProgramRecords()
-
addProgramRecord
public void addProgramRecord(SAMProgramRecord programRecord)
-
getProgramRecord
public SAMProgramRecord getProgramRecord(String pgId)
-
setProgramRecords
public void setProgramRecords(List<SAMProgramRecord> programRecords)
Replace entire list of program records- Parameters:
programRecords- This list is used directly, not copied.
-
createProgramRecord
public SAMProgramRecord createProgramRecord()
- Returns:
- a new SAMProgramRecord with an ID guaranteed to not exist in this SAMFileHeader
-
getSortOrder
public SAMFileHeader.SortOrder getSortOrder()
-
setSortOrder
public void setSortOrder(SAMFileHeader.SortOrder so)
-
getGroupOrder
public SAMFileHeader.GroupOrder getGroupOrder()
-
setGroupOrder
public void setGroupOrder(SAMFileHeader.GroupOrder go)
-
setAttribute
@Deprecated public void setAttribute(String key, Object value)
Deprecated.UseinsteadSet the given value for the attribute named 'key'. Replaces an existing value, if any. If value is null, the attribute is removed. Otherwise, the value will be converted to a String with toString.- Overrides:
setAttributein classAbstractSAMHeaderRecord- Parameters:
key- attribute namevalue- attribute value
-
setAttribute
public void setAttribute(String key, String value)
Set the given value for the attribute named 'key'. Replaces an existing value, if any. If value is null, the attribute is removed.- Overrides:
setAttributein classAbstractSAMHeaderRecord- Parameters:
key- attribute namevalue- attribute value
-
getTextHeader
public String getTextHeader()
If this SAMHeader was read from a file, this property contains the header as it appeared in the file, otherwise it is null. Note that this is not a toString() operation. Changes to the SAMFileHeader object after reading from the file are not reflected in this value. In addition this value is only set if one of the following is true: - The size of the header is < 1,048,576 characters (1MB ascii, 2MB unicode) - There are either validation or parsing errors associated with the header Invalid header lines may appear in value but are not stored in the SAMFileHeader object.
-
setTextHeader
public void setTextHeader(String textHeader)
-
addComment
public void addComment(String comment)
-
setComments
public void setComments(Collection<String> comments)
Replace existing comments with the contents of the given collection.
-
getValidationErrors
public List<SAMValidationError> getValidationErrors()
-
addValidationError
public void addValidationError(SAMValidationError error)
-
setValidationErrors
public void setValidationErrors(Collection<SAMValidationError> errors)
Replace list of validation errors with the elements of the given list.
-
clone
public final SAMFileHeader clone()
-
getSAMString
public String getSAMString()
Description copied from class:AbstractSAMHeaderRecordReturns the record in the SAM line-based text format. Fields are separated by '\t' characters. The String is NOT terminated by '\n'.- Specified by:
getSAMStringin classAbstractSAMHeaderRecord
-
-