# Class SAMFileHeader

java.lang.Object
htsjdk.samtools.AbstractSAMHeaderRecord
htsjdk.samtools.SAMFileHeader

All Implemented Interfaces:
  `HtsHeader, Serializable`

public class SAMFileHeader extends AbstractSAMHeaderRecord implements HtsHeader
Header information from a SAM or BAM file.

See Also:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`SAMFileHeader.GroupOrder`
`static class`
`SAMFileHeader.PgIdGenerator`
Little class to generate program group IDs
`static enum`
`SAMFileHeader.SortOrder`
Ways in which a SAM or BAM may be sorted.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Set<String>`
`ACCEPTABLE_VERSIONS`
`static final String`
`CURRENT_VERSION`
`static final String`
`GROUP_ORDER_TAG`
`static final String`
`SORT_ORDER_TAG`
`static final Set<String>`
`STANDARD_TAGS`
These tags are of known type, so don't need a type field in the text representation.
`static final String`
`VERSION_TAG`

### Fields inherited from class AbstractSAMHeaderRecord

`serialVersionUID`

## Constructor Summary

Constructors
Constructor
Description
`SAMFileHeader()`
`SAMFileHeader(SAMSequenceDictionary dict)`
Constructor that initializes the sequence dictionary with the provided one.

## Method Summary

Modifier and Type
Method
Description
`void`
`addComment(String comment)`
`void`
`addProgramRecord(SAMProgramRecord programRecord)`
`void`
`addReadGroup(SAMReadGroupRecord readGroup)`
`void`
`addSequence(SAMSequenceRecord sequenceRecord)`
`void`
`addValidationError(SAMValidationError error)`
`final SAMFileHeader`
`clone()`
`SAMProgramRecord`
`createProgramRecord()`
`boolean`
`equals(Object o)`
`List<String>`
`getComments()`
`String`
`getCreator()`
`SAMFileHeader.GroupOrder`
`getGroupOrder()`
`SAMProgramRecord`
`getProgramRecord(String pgId)`
`List<SAMProgramRecord>`
`getProgramRecords()`
`SAMReadGroupRecord`
`getReadGroup(String name)`
Look up read group record by name.
`List<SAMReadGroupRecord>`
`getReadGroups()`
`String`
`getSAMString()`
Returns the record in the SAM line-based text format.
`SAMSequenceRecord`
`getSequence(int sequenceIndex)`
Look up a sequence record by index.
`SAMSequenceRecord`
`getSequence(String name)`
Look up sequence record by name.
`SAMSequenceDictionary`
`getSequenceDictionary()`
`int`
`getSequenceIndex(String sequenceName)`
`SAMFileHeader.SortOrder`
`getSortOrder()`
`String`
`getTextHeader()`
Deprecated.
since May 1st 2019 - text version of header is no longer stored.
`List<SAMValidationError>`
`getValidationErrors()`
`String`
`getVersion()`
`int`
`hashCode()`
`void`
`setAttribute(String key, Object value)`
Deprecated.
Use `setAttribute(String, String)` instead
`void`
`setAttribute(String key, String value)`
Set the given value for the attribute named 'key'.
`void`
`setComments(Collection<String> comments)`
Replace existing comments with the contents of the given collection.
`void`
`setGroupOrder(SAMFileHeader.GroupOrder go)`
`void`
`setProgramRecords(List<SAMProgramRecord> programRecords)`
Replace entire list of program records
`void`
`setReadGroups(List<SAMReadGroupRecord> readGroups)`
Replace entire list of read groups.
`void`
`setSequenceDictionary(SAMSequenceDictionary sequenceDictionary)`
Replace entire sequence dictionary.
`void`
`setSortOrder(SAMFileHeader.SortOrder so)`
`void`
`setTextHeader(String textHeader)`
Deprecated.
since May 1st 2019 - text version of header is no longer stored.
`void`
`setValidationErrors(Collection<SAMValidationError> errors)`
Replace list of validation errors with the elements of the given list.

### Methods inherited from class AbstractSAMHeaderRecord

`attributesEqual, attributesHashCode, getAttribute, getAttributes, getId, setAttribute, toString`

### Methods inherited from class Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### 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

### ACCEPTABLE_VERSIONS

public static final Set<String> ACCEPTABLE_VERSIONS

### STANDARD_TAGS

public static final Set<String> STANDARD_TAGS
These tags are of known type, so don't need a type field in the text representation.

## Constructor Details

### SAMFileHeader

public SAMFileHeader()

### SAMFileHeader

public SAMFileHeader(SAMSequenceDictionary dict)
Constructor that initializes the sequence dictionary with the provided one.

## Method Details

### 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.
Use `setAttribute(String, String)` instead
Set 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:
  `setAttribute` in class `AbstractSAMHeaderRecord`
Parameters:
  `key` - attribute name
  `value` - 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:
  `setAttribute` in class `AbstractSAMHeaderRecord`
Parameters:
  `key` - attribute name
  `value` - attribute value

### getTextHeader

@Deprecated public String getTextHeader()
Deprecated.
since May 1st 2019 - text version of header is no longer stored.

### setTextHeader

@Deprecated public void setTextHeader(String textHeader)
Deprecated.
since May 1st 2019 - text version of header is no longer stored.

### getComments

public List<String> getComments()

### 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.

### equals

public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### clone

public final SAMFileHeader clone()

Overrides:
  `clone` in class `Object`

### getSAMString

public String getSAMString()
Description copied from class: `AbstractSAMHeaderRecord`
Returns the record in the SAM line-based text format. Fields are separated by '\t' characters. The String is NOT terminated by '\n'.

Specified by:
  `getSAMString` in class `AbstractSAMHeaderRecord`