Package htsjdk.variant.vcf
Class VCFHeader
- java.lang.Object
-
- htsjdk.variant.vcf.VCFHeader
-
- All Implemented Interfaces:
Serializable
public class VCFHeader extends Object implements Serializable
A class to represent a VCF header- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VCFHeader.HEADER_FIELDS
-
Field Summary
Fields Modifier and Type Field Description static String
CONTIG_KEY
static String
EXCLUDE_INTERVALS_KEY
static String
HEADER_INDICATOR
static String
INTERVAL_MERGING_KEY
static String
INTERVAL_PADDING_KEY
static String
INTERVAL_SET_RULE_KEY
static String
INTERVALS_KEY
static String
METADATA_INDICATOR
static String
REFERENCE_KEY
static long
serialVersionUID
static String
SOURCE_KEY
-
Constructor Summary
Constructors Constructor Description VCFHeader()
Create an empty VCF header with no header lines and no samplesVCFHeader(VCFHeader toCopy)
Creates a deep copy of the given VCFHeader, duplicating all its metadata and sample names.VCFHeader(VCFHeaderVersion vcfHeaderVersion, Set<VCFHeaderLine> metaData, Set<String> genotypeSampleNames)
create a VCF header, given a target version, a list of meta data and auxiliary tagsVCFHeader(Set<VCFHeaderLine> metaData)
create a VCF header, given a list of meta data and auxiliary tagsVCFHeader(Set<VCFHeaderLine> metaData, List<String> genotypeSampleNames)
VCFHeader(Set<VCFHeaderLine> metaData, Set<String> genotypeSampleNames)
create a VCF header, given a list of meta data and auxiliary tags
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMetaDataLine(VCFHeaderLine headerLine)
Adds a new line to the VCFHeader.int
getColumnCount()
List<VCFContigHeaderLine>
getContigLines()
VCFFilterHeaderLine
getFilterHeaderLine(String id)
List<VCFFilterHeaderLine>
getFilterLines()
VCFFormatHeaderLine
getFormatHeaderLine(String id)
Collection<VCFFormatHeaderLine>
getFormatHeaderLines()
Returns the FORMAT HeaderLines in their original orderingList<String>
getGenotypeSamples()
get the genotyping sample namesSet<VCFHeader.HEADER_FIELDS>
getHeaderFields()
get the header fields in order they're presented in the input file (which is now required to be the order presented in the spec).List<VCFIDHeaderLine>
getIDHeaderLines()
VCFInfoHeaderLine
getInfoHeaderLine(String id)
Collection<VCFInfoHeaderLine>
getInfoHeaderLines()
Returns the INFO HeaderLines in their original orderingSet<VCFHeaderLine>
getMetaDataInInputOrder()
get the meta data, associated with this header, in sorted orderSet<VCFHeaderLine>
getMetaDataInSortedOrder()
VCFHeaderLine
getMetaDataLine(String key)
Get the VCFHeaderLine whose key equals key.int
getNGenotypeSamples()
VCFHeaderLine
getOtherHeaderLine(String key)
Collection<VCFHeaderLine>
getOtherHeaderLines()
Returns the other HeaderLines in their original orderingArrayList<String>
getSampleNamesInOrder()
Get the genotype sample names, sorted in ascending order.HashMap<String,Integer>
getSampleNameToOffset()
SAMSequenceDictionary
getSequenceDictionary()
Returns the contigs in this VCF file as a SAMSequenceDictionary.VCFHeaderVersion
getVCFHeaderVersion()
VariantContextComparator
getVCFRecordComparator()
boolean
hasFilterLine(String id)
boolean
hasFormatLine(String id)
boolean
hasGenotypingData()
do we have genotyping data?boolean
hasInfoLine(String id)
boolean
isWriteCommandLine()
If true, and isWriteEngineHeaders also returns true, the command line will be written to the VCF.boolean
isWriteEngineHeaders()
If true additional engine headers will be written to the VCF, otherwise only the walker headers will be output.boolean
samplesWereAlreadySorted()
were the input samples sorted originally?void
setSequenceDictionary(SAMSequenceDictionary dictionary)
Completely replaces the contig records in this header with those in the given SAMSequenceDictionary.void
setVCFHeaderVersion(VCFHeaderVersion vcfHeaderVersion)
Establish the header version for this header.void
setWriteCommandLine(boolean writeCommandLine)
If true, and isWriteEngineHeaders also returns true, the command line will be written to the VCF.void
setWriteEngineHeaders(boolean writeEngineHeaders)
If true additional engine headers will be written to the VCF, otherwise only the walker headers will be output.String
toString()
static void
validateVersionTransition(VCFHeaderVersion fromVersion, VCFHeaderVersion toVersion)
Throw iffromVersion
is not compatible with atoVersion
.
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
METADATA_INDICATOR
public static final String METADATA_INDICATOR
- See Also:
- Constant Field Values
-
HEADER_INDICATOR
public static final String HEADER_INDICATOR
- See Also:
- Constant Field Values
-
SOURCE_KEY
public static final String SOURCE_KEY
- See Also:
- Constant Field Values
-
REFERENCE_KEY
public static final String REFERENCE_KEY
- See Also:
- Constant Field Values
-
CONTIG_KEY
public static final String CONTIG_KEY
- See Also:
- Constant Field Values
-
INTERVALS_KEY
public static final String INTERVALS_KEY
- See Also:
- Constant Field Values
-
EXCLUDE_INTERVALS_KEY
public static final String EXCLUDE_INTERVALS_KEY
- See Also:
- Constant Field Values
-
INTERVAL_MERGING_KEY
public static final String INTERVAL_MERGING_KEY
- See Also:
- Constant Field Values
-
INTERVAL_SET_RULE_KEY
public static final String INTERVAL_SET_RULE_KEY
- See Also:
- Constant Field Values
-
INTERVAL_PADDING_KEY
public static final String INTERVAL_PADDING_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VCFHeader
public VCFHeader()
Create an empty VCF header with no header lines and no samples
-
VCFHeader
public VCFHeader(Set<VCFHeaderLine> metaData)
create a VCF header, given a list of meta data and auxiliary tags- Parameters:
metaData
- the meta data associated with this header
-
VCFHeader
public VCFHeader(VCFHeader toCopy)
Creates a deep copy of the given VCFHeader, duplicating all its metadata and sample names.
-
VCFHeader
public VCFHeader(Set<VCFHeaderLine> metaData, Set<String> genotypeSampleNames)
create a VCF header, given a list of meta data and auxiliary tags- Parameters:
metaData
- the meta data associated with this headergenotypeSampleNames
- the sample names
-
VCFHeader
public VCFHeader(VCFHeaderVersion vcfHeaderVersion, Set<VCFHeaderLine> metaData, Set<String> genotypeSampleNames)
create a VCF header, given a target version, a list of meta data and auxiliary tags- Parameters:
vcfHeaderVersion
- the vcf header version for this header, can not be nullmetaData
- the meta data associated with this headergenotypeSampleNames
- the sample names
-
VCFHeader
public VCFHeader(Set<VCFHeaderLine> metaData, List<String> genotypeSampleNames)
-
-
Method Detail
-
setVCFHeaderVersion
public void setVCFHeaderVersion(VCFHeaderVersion vcfHeaderVersion)
Establish the header version for this header. If the header version has already been established for this header, the new version will be subject to version transition validation.- Parameters:
vcfHeaderVersion
-- Throws:
TribbleException
- if the requested header version is not compatible with the existing version
-
validateVersionTransition
public static void validateVersionTransition(VCFHeaderVersion fromVersion, VCFHeaderVersion toVersion)
Throw iffromVersion
is not compatible with atoVersion
. Generally, any version before version 4.2 can be up-converted to version 4.2, but not to version 4.3. Once a header is established as version 4.3, it cannot be up or down converted, and it must remain at version 4.3.- Parameters:
fromVersion
- current version. May be null, in which casetoVersion
can be any versiontoVersion
- new version. Cannot be null.- Throws:
TribbleException
- iffromVersion
is not compatible withtoVersion
-
getVCFHeaderVersion
public VCFHeaderVersion getVCFHeaderVersion()
- Returns:
- the VCFHeaderVersion for this header. Can be null.
-
addMetaDataLine
public void addMetaDataLine(VCFHeaderLine headerLine)
Adds a new line to the VCFHeader. If there is an existing header line of the same type with the same key, the new line is not added and the existing line is preserved.- Parameters:
headerLine
- header line to attempt to add
-
getContigLines
public List<VCFContigHeaderLine> getContigLines()
- Returns:
- all of the VCF header lines of the ##contig form in order, or an empty list if none were present
-
getSequenceDictionary
public SAMSequenceDictionary getSequenceDictionary()
Returns the contigs in this VCF file as a SAMSequenceDictionary. Returns null if contigs lines are not present in the header. If contig lines are missing length tags, they will be created with length set to SAMSequenceRecord.UNKNOWN_SEQUENCE_LENGTH. Records with unknown length will match any record with the same name when evaluated by SAMSequenceRecord.isSameSequence.
-
setSequenceDictionary
public void setSequenceDictionary(SAMSequenceDictionary dictionary)
Completely replaces the contig records in this header with those in the given SAMSequenceDictionary.
-
getVCFRecordComparator
public VariantContextComparator getVCFRecordComparator()
-
getFilterLines
public List<VCFFilterHeaderLine> getFilterLines()
- Returns:
- all of the VCF FILTER lines in their original file order, or an empty list if none were present
-
getIDHeaderLines
public List<VCFIDHeaderLine> getIDHeaderLines()
- Returns:
- all of the VCF ID-based header lines in their original file order, or an empty list if none were present
-
getHeaderFields
public Set<VCFHeader.HEADER_FIELDS> getHeaderFields()
get the header fields in order they're presented in the input file (which is now required to be the order presented in the spec).- Returns:
- a set of the header fields, in order
-
getMetaDataInInputOrder
public Set<VCFHeaderLine> getMetaDataInInputOrder()
get the meta data, associated with this header, in sorted order- Returns:
- a set of the meta data
-
getMetaDataInSortedOrder
public Set<VCFHeaderLine> getMetaDataInSortedOrder()
-
getMetaDataLine
public VCFHeaderLine getMetaDataLine(String key)
Get the VCFHeaderLine whose key equals key. Returns null if no such line exists- Parameters:
key
-- Returns:
-
getGenotypeSamples
public List<String> getGenotypeSamples()
get the genotyping sample names- Returns:
- a list of the genotype column names, which may be empty if hasGenotypingData() returns false
-
getNGenotypeSamples
public int getNGenotypeSamples()
-
hasGenotypingData
public boolean hasGenotypingData()
do we have genotyping data?- Returns:
- true if we have genotyping columns, false otherwise
-
samplesWereAlreadySorted
public boolean samplesWereAlreadySorted()
were the input samples sorted originally?- Returns:
- true if the input samples were sorted originally, false otherwise
-
getColumnCount
public int getColumnCount()
- Returns:
- the column count
-
getInfoHeaderLines
public Collection<VCFInfoHeaderLine> getInfoHeaderLines()
Returns the INFO HeaderLines in their original ordering
-
getFormatHeaderLines
public Collection<VCFFormatHeaderLine> getFormatHeaderLines()
Returns the FORMAT HeaderLines in their original ordering
-
getInfoHeaderLine
public VCFInfoHeaderLine getInfoHeaderLine(String id)
- Parameters:
id
- the header key name- Returns:
- the meta data line, or null if there is none
-
getFormatHeaderLine
public VCFFormatHeaderLine getFormatHeaderLine(String id)
- Parameters:
id
- the header key name- Returns:
- the meta data line, or null if there is none
-
getFilterHeaderLine
public VCFFilterHeaderLine getFilterHeaderLine(String id)
- Parameters:
id
- the header key name- Returns:
- the meta data line, or null if there is none
-
hasInfoLine
public boolean hasInfoLine(String id)
-
hasFormatLine
public boolean hasFormatLine(String id)
-
hasFilterLine
public boolean hasFilterLine(String id)
-
getOtherHeaderLine
public VCFHeaderLine getOtherHeaderLine(String key)
- Parameters:
key
- the header key name- Returns:
- the meta data line, or null if there is none
-
getOtherHeaderLines
public Collection<VCFHeaderLine> getOtherHeaderLines()
Returns the other HeaderLines in their original ordering
-
isWriteEngineHeaders
public boolean isWriteEngineHeaders()
If true additional engine headers will be written to the VCF, otherwise only the walker headers will be output.- Returns:
- true if additional engine headers will be written to the VCF
-
setWriteEngineHeaders
public void setWriteEngineHeaders(boolean writeEngineHeaders)
If true additional engine headers will be written to the VCF, otherwise only the walker headers will be output.- Parameters:
writeEngineHeaders
- true if additional engine headers will be written to the VCF
-
isWriteCommandLine
public boolean isWriteCommandLine()
If true, and isWriteEngineHeaders also returns true, the command line will be written to the VCF.- Returns:
- true if the command line will be written to the VCF
-
setWriteCommandLine
public void setWriteCommandLine(boolean writeCommandLine)
If true, and isWriteEngineHeaders also returns true, the command line will be written to the VCF.- Parameters:
writeCommandLine
- true if the command line will be written to the VCF
-
getSampleNamesInOrder
public ArrayList<String> getSampleNamesInOrder()
Get the genotype sample names, sorted in ascending order. Note: this will not necessarily match the order in the VCF.- Returns:
- The sorted genotype samples. May be empty if hasGenotypingData() returns false.
-
-