Package vcf

Class BasicMarker

  • All Implemented Interfaces:
    java.lang.Comparable<Marker>, Marker

    public class BasicMarker
    extends java.lang.Object
    implements Marker

    Class BasicMarker represents a genetic marker.

    Instances of class BasicMarker are immutable.

    • Constructor Summary

      Constructors 
      Constructor Description
      BasicMarker​(int chrom, int pos, java.lang.String[] ids, java.lang.String[] alleles)
      Constructs a new BasicMarker instance from the specified data.
      BasicMarker​(int chrom, int pos, java.lang.String[] ids, java.lang.String[] alleles, int end)
      Constructs a new BasicMarker instance from the specified data.
      BasicMarker​(java.lang.String vcfRecord)
      Constructs a new BasicMarker instance from the specified string VCF record prefix.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String allele​(int index)
      Returns the specified allele.
      java.lang.String[] alleles()
      Returns the alleles.
      int bitsPerAllele()
      Returns the minimum number of bits required to store a non-missing allele.
      java.lang.String chrom()
      Returns the chromosome.
      int chromIndex()
      Returns the chromosome index.
      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.
      int end()
      Returns the INFO END field, or -1 if there is no INFO END field.
      boolean equals​(java.lang.Object obj)
      Returns true if the specified object is a Marker with the same chromosome, position, allele lists, and INFO END field, and returns false otherwise.
      static java.lang.String flipStrand​(java.lang.String allele)
      Returns the string allele obtained by changing the specified allele to the opposite chromosome strand
      static Marker flipStrand​(Marker marker)
      Constructs and returns a new marker obtained from the specified marker by changing the marker's non-symbolic alleles to the alleles on the opposite chromosome strand.
      int hashCode()
      Returns the hash code value for this object.
      java.lang.String id()
      Returns the first marker identifier if there is at least one identifier in the VCF record ID field, and returns this.chr() + ":" + this.pos() otherwise.
      java.lang.String id​(int index)
      Returns the specified marker identifier.
      int nAlleles()
      Returns the number of alleles for the marker, including the REF allele.
      int nGenotypes()
      Returns the number of distinct genotypes, which equals this.nAlleles()*(1 + this.nAlleles())/2.
      int nIds()
      Returns the number of marker identifiers.
      int pos()
      Returns the chromosome position coordinate.
      java.lang.String toString()
      Returns a string equal to the first five tab-delimited fields of a VCF record corresponding to this marker.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BasicMarker

        public BasicMarker​(int chrom,
                           int pos,
                           java.lang.String[] ids,
                           java.lang.String[] alleles)
        Constructs a new BasicMarker instance from the specified data. The end() method of the new instance will return -1. The JVM will exit with an error message if any marker identifier in the specifiedids array or if any allele identifier in the specified alleles array does not conform to the VCF specification.
        Parameters:
        chrom - a chromosome index
        pos - the marker position
        ids - a list of marker identifiers
        alleles - a list of alleles beginning with the reference allele
        Throws:
        java.lang.IllegalArgumentException - if chrom < 0 || chrom >= ChromIds.instance().size()
        java.lang.NullPointerException - if ids == null or if any element of ids is null
        java.lang.NullPointerException - if alleles == null or if any element of alleles is null
      • BasicMarker

        public BasicMarker​(int chrom,
                           int pos,
                           java.lang.String[] ids,
                           java.lang.String[] alleles,
                           int end)
        Constructs a new BasicMarker instance from the specified data. The JVM will exit with an error message if any marker identifier in the specified ids array does not conform to the VCF specification, if any allele identifier in the specified alleles array does not conform to the VCF specification, or if (end != -1 && end < pos).
        Parameters:
        chrom - a chromosome index
        pos - the marker position
        ids - a list of marker identifiers
        alleles - a list of alleles beginning with the reference allele
        end - the INFO END field, or -1 if there is no INFO END field
        Throws:
        java.lang.IllegalArgumentException - if chrom < 0 || chrom >= ChromIds.instance().size()
        java.lang.NullPointerException - if ids == null or if any element of ids is null
        java.lang.NullPointerException - if alleles == null or if any element of alleles is null
      • BasicMarker

        public BasicMarker​(java.lang.String vcfRecord)
        Constructs a new BasicMarker instance from the specified string VCF record prefix.
        Parameters:
        vcfRecord - a VCF record prefix
        Throws:
        java.lang.IllegalArgumentException - if the specified VCF record prefix has fewer than 8 tab-delimited fields, or if a format error is detected in the first 8 fields of the specified VCF record
        java.lang.NullPointerException - if vcfRecord == null
    • Method Detail

      • flipStrand

        public static Marker flipStrand​(Marker marker)
        Constructs and returns a new marker obtained from the specified marker by changing the marker's non-symbolic alleles to the alleles on the opposite chromosome strand.
        Parameters:
        marker - a marker
        Returns:
        the equivalent marker on the opposite chromosome strand
        Throws:
        java.lang.NullPointerException - if marker == null
      • flipStrand

        public static java.lang.String flipStrand​(java.lang.String allele)
        Returns the string allele obtained by changing the specified allele to the opposite chromosome strand
        Parameters:
        allele - a string allele
        Returns:
        the string allele obtained by changing the specified allele to the opposite chromosome strand
        Throws:
        java.lang.IllegalArgumentException - if any character in the specified string is not 'A', 'C', 'G', 'T', 'N', or '*'.
        java.lang.NullPointerException - if allele == null
      • chrom

        public java.lang.String chrom()
        Description copied from interface: Marker
        Returns the chromosome.
        Specified by:
        chrom in interface Marker
        Returns:
        the chromosome
      • chromIndex

        public int chromIndex()
        Description copied from interface: Marker
        Returns the chromosome index.
        Specified by:
        chromIndex in interface Marker
        Returns:
        the chromosome index
      • pos

        public int pos()
        Description copied from interface: Marker
        Returns the chromosome position coordinate.
        Specified by:
        pos in interface Marker
        Returns:
        the chromosome position coordinate
      • nIds

        public int nIds()
        Description copied from interface: Marker
        Returns the number of marker identifiers.
        Specified by:
        nIds in interface Marker
        Returns:
        the number of marker identifiers
      • id

        public java.lang.String id​(int index)
        Description copied from interface: Marker
        Returns the specified marker identifier.
        Specified by:
        id in interface Marker
        Parameters:
        index - a marker identifier index
        Returns:
        the specified marker identifier
      • id

        public java.lang.String id()
        Description copied from interface: Marker
        Returns the first marker identifier if there is at least one identifier in the VCF record ID field, and returns this.chr() + ":" + this.pos() otherwise.
        Specified by:
        id in interface Marker
        Returns:
        a marker identifier
      • nAlleles

        public int nAlleles()
        Description copied from interface: Marker
        Returns the number of alleles for the marker, including the REF allele.
        Specified by:
        nAlleles in interface Marker
        Returns:
        the number of alleles for the marker, including the REF allele
      • allele

        public java.lang.String allele​(int index)
        Description copied from interface: Marker
        Returns the specified allele. The reference allele has index 0.
        Specified by:
        allele in interface Marker
        Parameters:
        index - an allele index
        Returns:
        the specified allele
      • alleles

        public java.lang.String[] alleles()
        Description copied from interface: Marker
        Returns the alleles. The k-th element of the returned array is equal to this.allele(k).
        Specified by:
        alleles in interface Marker
        Returns:
        the alleles
      • nGenotypes

        public int nGenotypes()
        Description copied from interface: Marker
        Returns the number of distinct genotypes, which equals this.nAlleles()*(1 + this.nAlleles())/2.
        Specified by:
        nGenotypes in interface Marker
        Returns:
        the number of distinct genotypes
      • end

        public int end()
        Description copied from interface: Marker
        Returns the INFO END field, or -1 if there is no INFO END field.
        Specified by:
        end in interface Marker
        Returns:
        the INFO END field, or -1 if there is no INFO END field
      • bitsPerAllele

        public int bitsPerAllele()
        Description copied from interface: Marker
        Returns the minimum number of bits required to store a non-missing allele.
        Specified by:
        bitsPerAllele in interface Marker
        Returns:
        the minimum number of bits required to store a non-missing allele
      • toString

        public java.lang.String toString()
        Description copied from interface: Marker
        Returns a string equal to the first five tab-delimited fields of a VCF record corresponding to this marker.
        Specified by:
        toString in interface Marker
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string equal to the first five tab-delimited fields of a VCF record corresponding to this marker
      • hashCode

        public int hashCode()
        Description copied from interface: Marker

        Returns the hash code value for this object. The hash code does not depend on value of the VCF record ID field. The hash code is defined by the following calculation:

           int hash = 5;
           hash = 29 * hash + this.chromIndex();
           hash = 29 * hash + this.pos();
           for (int j=0, n=this.nAlleles(); j<n; ++j) {
               hash = 29 * hash + alleles[j].hashCode();
           }
           hash = 29 * hash + end();
         
        Specified by:
        hashCode in interface Marker
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code value for this marker
      • equals

        public boolean equals​(java.lang.Object obj)
        Description copied from interface: Marker
        Returns true if the specified object is a Marker with the same chromosome, position, allele lists, and INFO END field, and returns false otherwise. Equality does not depend on value of the VCF record ID field.
        Specified by:
        equals in interface Marker
        Overrides:
        equals in class java.lang.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, and allele lists, and INFO END field
      • compareTo

        public int compareTo​(Marker other)
        Description copied from interface: Marker
        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. Comparison is on chromosome index, position, allele identifier lists, and end value in that order. Allele identifier lists are compared for lexicographical order, and alleles are compared using the String compareTo() method.
        Specified by:
        compareTo in interface java.lang.Comparable<Marker>
        Specified by:
        compareTo in interface 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