Package vcf
Class Marker
java.lang.Object
vcf.Marker
- All Implemented Interfaces:
Comparable<Marker>
Class Marker
represents a VCF record's CHROM, POS, ID, REF,
ALT, QUAL, FILTER, and INFO fields. The number of alleles in the VCF
record must be less than or equal to Marker.MAX_N_ALLELES
.
Instances of class Marker
are immutable.
-
Method Summary
Modifier and TypeMethodDescriptionalleles()
Returns the tab-separated VCF REF and ALT fieldsvoid
Appends the first eight tab-delimited fields of a VCF record for this marker (the CHROM, POS, ID, REF, ALT, QUAL, FILTER, and INFO fields) to the specifiedStringBuilder
.void
appendFirst8Fields
(StringBuilder sb, int an, int[] alleleCounts) Appends the first eight tab-delimited fields of a VCF record for this marker (the CHROM, POS, ID, REF, ALT, QUAL, FILTER, and INFO fields) and add the specified INFO/AN and INFO/AC fields.int
Returns the minimum number of bits required to store a non-missing allele.chrom()
Returns the VCF CHROM field.int
Returns the chromosome index.int
Compares this marker with the specified marker for order, and returns a negative integer, 0, or a positive integer depending on whether this marker is less than, equal to, or greater than the specified marker.endValue()
Returns the INFO/END value.boolean
Returnstrue
if the specified object is aMarker
with the same chromosome, position, alleles, and INFO/END value, and returnsfalse
otherwise.filter()
Returns the VCF FILTER field.boolean
Returnstrue
if the VCF INFO/END field is defined, and returnsfalse
otherwise.boolean
Returnstrue
if the VCF FILTER field has non-missing data, and returnsfalse
otherwise.int
hashCode()
Returns the hash code value for this object.boolean
Returnstrue
if the VCF ID field has non-missing data, and returnsfalse
otherwise.boolean
Returnstrue
if the VCF INFO field has non-missing data, and returnsfalse
otherwise.boolean
Returnstrue
if the VCF QUAL field has non-missing data, and returnsfalse
otherwise.id()
Returns the VCF ID field.info()
Returns the VCF INFO field.static Marker
instance
(String rec, MarkerParser markerParser) Constructs a newMarker
instance from the data.int
nAlleles()
Returns the number of alleles for the marker, including the REF allele.int
Returns the number of nucleotides in the reference allele.int
pos()
Returns the VCF POS fieldqual()
Returns the VCF QUAL field.static Marker
readNonPosFields
(short chromIndex, int pos, DataInput in) Reads the VCF record ID, REF, ALT, QUAL, FILTER, and INFO fields and returns a marker with these fields and the specified CHROM and POS fields.toString()
Returns a string equal to the first five tab-delimited fields of a VCF record corresponding to this marker (the CHROM, POS, ID, REF, and ALT fields).void
Writes a representation of the VCF record ID, REF, ALT, QUAL, FILTER, and INFO fields to the specified output.
-
Method Details
-
instance
Constructs a newMarker
instance from the data. If the specified VCF record contains an INFO/END field, the INFO/END field will be stored.- Parameters:
rec
- a VCF recordmarkerParser
- an object that filters and parses a VCF record's ID, QUAL, FILTER, and INFO subfields- Returns:
- a new
Marker
instance - Throws:
IllegalArgumentException
- if the specified VCF record does not contain at least 8 tab charactersIllegalArgumentException
- if the VCF CHROM field contains whitespaceIllegalArgumentException
- if the specified VCF record has more than 255 allelesIndexOutOfBoundsException
- if the index of the VCF CHROM field exceedsShort.MAX_VALUE
NullPointerException
- if(vcfRecord == null) || (vcfFields==null)
NumberFormatException
- if the VCF record POS field is not a parsable integer
-
chrom
Returns the VCF CHROM field.- Returns:
- the VCF CHROM field
-
chromIndex
public int chromIndex()Returns the chromosome index.- Returns:
- the chromosome index
-
pos
public int pos()Returns the VCF POS field- Returns:
- the VCF POS field
-
hasIdData
public boolean hasIdData()Returnstrue
if the VCF ID field has non-missing data, and returnsfalse
otherwise.- Returns:
true
if the VCF ID field has non-missing data, and returnsfalse
otherwise
-
hasQualData
public boolean hasQualData()Returnstrue
if the VCF QUAL field has non-missing data, and returnsfalse
otherwise.- Returns:
true
if the VCF QUAL field has non-missing data, and returnsfalse
otherwise
-
hasFilterData
public boolean hasFilterData()Returnstrue
if the VCF FILTER field has non-missing data, and returnsfalse
otherwise.- Returns:
true
if the VCF FILTER field has non-missing data, and returnsfalse
otherwise
-
hasInfoData
public boolean hasInfoData()Returnstrue
if the VCF INFO field has non-missing data, and returnsfalse
otherwise.- Returns:
true
if the VCF INFO field has non-missing data, and returnsfalse
otherwise
-
hasEndValue
public boolean hasEndValue()Returnstrue
if the VCF INFO/END field is defined, and returnsfalse
otherwise.- Returns:
true
if the VCF INFO/END field has is defined
-
id
Returns the VCF ID field.- Returns:
- the VCF ID field
-
alleles
Returns the tab-separated VCF REF and ALT fields- Returns:
- the tab-separated VCF REF and ALT fields
-
nRefBases
public int nRefBases()Returns the number of nucleotides in the reference allele.- Returns:
- the number of nucleotides in the reference allele
-
nAlleles
public int nAlleles()Returns the number of alleles for the marker, including the REF allele.- Returns:
- the number of alleles for the marker, including the REF allele
-
bitsPerAllele
public int bitsPerAllele()Returns the minimum number of bits required to store a non-missing allele.- Returns:
- the minimum number of bits required to store a non-missing allele
-
qual
Returns the VCF QUAL field.- Returns:
- the VCF QUAL field
-
filter
Returns the VCF FILTER field.- Returns:
- the VCF FILTER field.
-
info
Returns the VCF INFO field.- Returns:
- the VCF INFO field.
-
endValue
Returns the INFO/END value. Returns "" if the INFO/END value is not defined.- Returns:
- the INFO/END value
-
hashCode
public int hashCode()Returns the hash code value for this object. The hash code is defined by the following calculation:
int hash = 5; hash = 29 * hash + this.chromIndex(); hash = 29 * hash + this.pos(); hash = 29 * hash + this.alleles().hashCode(); hash = 29 * hash + this.endValue().hashCode();
-
equals
Returnstrue
if the specified object is aMarker
with the same chromosome, position, alleles, and INFO/END value, and returnsfalse
otherwise. -
compareTo
Compares this marker with the specified marker for order, and returns a negative integer, 0, or a positive integer depending on whether this marker is less than, equal to, or greater than the specified marker. Markers are compared using the values returned by thechromIndex()
,pos()
,alleles()
, andendValue()
methods. The returned value is defined by the following calculation:if (this.chromIndex() != other.chromIndex()) { return (this.chromIndex < other.chromIndex()) ? -1 : 1; } if (this.pos() != other.pos()) { return (this.pos < other.pos()) ? -1 : 1; } int value = this.alleles().compareTo(other.alleles()); if (value!=0) { return value; } return this.endValue().compareTo(other.endValue());
- Specified by:
compareTo
in interfaceComparable<Marker>
- Parameters:
other
- theMarker
to be compared- Returns:
- a negative integer, 0, or a positive integer depending on whether this marker is less than, equal, or greater than the specified marker
-
writeNonPosFields
Writes a representation of the VCF record ID, REF, ALT, QUAL, FILTER, and INFO fields to the specified output. The exact details of the representation are unspecified and subject to change. The written data can be read with theMarker.readNonPosFields()
method.- Parameters:
out
- the output destination- Throws:
IOException
- if an I/O error occursNullPointerException
- ifout == null
-
readNonPosFields
Reads the VCF record ID, REF, ALT, QUAL, FILTER, and INFO fields and returns a marker with these fields and the specified CHROM and POS fields. The contract for this method is unspecified ifchromIndex
is not a valid chromosome index.- Parameters:
chromIndex
- the chromosome indexpos
- the chromosome positionin
- the input source- Returns:
- a
Marker
- Throws:
IOException
- if an I/O error occursNullPointerException
- ifin == null
-
toString
Returns a string equal to the first five tab-delimited fields of a VCF record corresponding to this marker (the CHROM, POS, ID, REF, and ALT fields). -
appendFirst8Fields
Appends the first eight tab-delimited fields of a VCF record for this marker (the CHROM, POS, ID, REF, ALT, QUAL, FILTER, and INFO fields) to the specifiedStringBuilder
.- Parameters:
sb
- theStringBuilder
to be appended- Throws:
NullPointerException
- if(sb == null)
-
appendFirst8Fields
Appends the first eight tab-delimited fields of a VCF record for this marker (the CHROM, POS, ID, REF, ALT, QUAL, FILTER, and INFO fields) and add the specified INFO/AN and INFO/AC fields. If the INFO/AN or iNFO/AC fields exist inthis.info()
, the fields will be replaced with the specified INFO/AN and INFO/AC fields.- Parameters:
sb
- theStringBuilder
to be appendedan
- the total number of alleles in called genotypesalleleCounts
- an array of lengththis.nAlleles()
whosek-th
entry is the allele count in called genotypes for thek
-th allele- Throws:
IllegalArgumentException
- if(this.nAlleles() != alleleCounts.length)
NullPointerException
- if((sb == null) || (alleleCounts == null))
-