Package vcf

Class Marker

java.lang.Object
vcf.Marker
All Implemented Interfaces:
Comparable<Marker>

public final class Marker extends Object implements 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 Type
    Method
    Description
    Returns the tab-separated VCF REF and ALT fields
    void
    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 specified StringBuilder.
    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.
    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.
    Returns the INFO/END value.
    boolean
    Returns true if the specified object is a Marker with the same chromosome, position, alleles, and INFO/END value, and returns false otherwise.
    Returns the VCF FILTER field.
    boolean
    Returns true if the VCF INFO/END field is defined, and returns false otherwise.
    boolean
    Returns true if the VCF FILTER field has non-missing data, and returns false otherwise.
    int
    Returns the hash code value for this object.
    boolean
    Returns true if the VCF ID field has non-missing data, and returns false otherwise.
    boolean
    Returns true if the VCF INFO field has non-missing data, and returns false otherwise.
    boolean
    Returns true if the VCF QUAL field has non-missing data, and returns false otherwise.
    id()
    Returns the VCF ID field.
    Returns the VCF INFO field.
    static Marker
    instance(String rec, MarkerParser markerParser)
    Constructs a new Marker instance from the data.
    int
    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 field
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • instance

      public static Marker instance(String rec, MarkerParser markerParser)
      Constructs a new Marker 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 record
      markerParser - 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 characters
      IllegalArgumentException - if the VCF CHROM field contains whitespace
      IllegalArgumentException - if the specified VCF record has more than 255 alleles
      IndexOutOfBoundsException - if the index of the VCF CHROM field exceeds Short.MAX_VALUE
      NullPointerException - if (vcfRecord == null) || (vcfFields==null)
      NumberFormatException - if the VCF record POS field is not a parsable integer
    • chrom

      public String 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()
      Returns true if the VCF ID field has non-missing data, and returns false otherwise.
      Returns:
      true if the VCF ID field has non-missing data, and returns false otherwise
    • hasQualData

      public boolean hasQualData()
      Returns true if the VCF QUAL field has non-missing data, and returns false otherwise.
      Returns:
      true if the VCF QUAL field has non-missing data, and returns false otherwise
    • hasFilterData

      public boolean hasFilterData()
      Returns true if the VCF FILTER field has non-missing data, and returns false otherwise.
      Returns:
      true if the VCF FILTER field has non-missing data, and returns false otherwise
    • hasInfoData

      public boolean hasInfoData()
      Returns true if the VCF INFO field has non-missing data, and returns false otherwise.
      Returns:
      true if the VCF INFO field has non-missing data, and returns false otherwise
    • hasEndValue

      public boolean hasEndValue()
      Returns true if the VCF INFO/END field is defined, and returns false otherwise.
      Returns:
      true if the VCF INFO/END field has is defined
    • id

      public String id()
      Returns the VCF ID field.
      Returns:
      the VCF ID field
    • alleles

      public String 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

      public String qual()
      Returns the VCF QUAL field.
      Returns:
      the VCF QUAL field
    • filter

      public String filter()
      Returns the VCF FILTER field.
      Returns:
      the VCF FILTER field.
    • info

      public String info()
      Returns the VCF INFO field.
      Returns:
      the VCF INFO field.
    • endValue

      public String 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();
         
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this marker
    • equals

      public boolean equals(Object obj)
      Returns true if the specified object is a Marker with the same chromosome, position, alleles, and INFO/END value, and returns false otherwise.
      Overrides:
      equals in class Object
      Parameters:
      obj - object to be compared with this for equality
      Returns:
      true if the specified object is a Marker with the same chromosome, position, alleles, and INFO/END value
    • compareTo

      public int compareTo(Marker other)
      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 the chromIndex(), pos(), alleles(), and endValue() 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 interface Comparable<Marker>
      Parameters:
      other - the Marker 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

      public void writeNonPosFields(DataOutput out) throws IOException
      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 the Marker.readNonPosFields() method.
      Parameters:
      out - the output destination
      Throws:
      IOException - if an I/O error occurs
      NullPointerException - if out == null
    • readNonPosFields

      public static Marker readNonPosFields(short chromIndex, int pos, DataInput in) throws IOException
      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 if chromIndex is not a valid chromosome index.
      Parameters:
      chromIndex - the chromosome index
      pos - the chromosome position
      in - the input source
      Returns:
      a Marker
      Throws:
      IOException - if an I/O error occurs
      NullPointerException - if in == null
    • toString

      public String 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).
      Overrides:
      toString in class Object
      Returns:
      a string equal to the first five tab-delimited fields of a VCF record corresponding to this marker
    • appendFirst8Fields

      public void appendFirst8Fields(StringBuilder sb)
      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 specified StringBuilder.
      Parameters:
      sb - the StringBuilder to be appended
      Throws:
      NullPointerException - if (sb == null)
    • appendFirst8Fields

      public 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. If the INFO/AN or iNFO/AC fields exist in this.info(), the fields will be replaced with the specified INFO/AN and INFO/AC fields.
      Parameters:
      sb - the StringBuilder to be appended
      an - the total number of alleles in called genotypes
      alleleCounts - an array of length this.nAlleles() whose k-th entry is the allele count in called genotypes for the k-th allele
      Throws:
      IllegalArgumentException - if (this.nAlleles() != alleleCounts.length)
      NullPointerException - if ((sb == null) || (alleleCounts == null))