Package vcf

Class BasicMarker

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

public class BasicMarker extends 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, String[] ids, String[] alleles)
    Constructs a new BasicMarker instance from the specified data.
    BasicMarker(int chrom, int pos, String[] ids, String[] alleles, int end)
    Constructs a new BasicMarker instance from the specified data.
    BasicMarker(String vcfRecord)
    Constructs a new BasicMarker instance from the specified string VCF record prefix.
  • Method Summary

    Modifier and Type
    Method
    Description
    allele(int index)
    Returns the specified allele.
    Returns the alleles.
    int
    Returns the minimum number of bits required to store a non-missing allele.
    Returns the chromosome.
    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.
    int
    end()
    Returns the INFO END field, or -1 if there is no INFO END field.
    boolean
    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 String
    Returns the string allele obtained by changing the specified allele to the opposite chromosome strand
    static 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
    Returns the hash code value for this object.
    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.
    id(int index)
    Returns the specified marker identifier.
    int
    Returns the number of alleles for the marker, including the REF allele.
    int
    Returns the number of distinct genotypes, which equals this.nAlleles()*(1 + this.nAlleles())/2.
    int
    Returns the number of marker identifiers.
    int
    pos()
    Returns the chromosome position coordinate.
    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 Details

    • BasicMarker

      public BasicMarker(int chrom, int pos, String[] ids, 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:
      IllegalArgumentException - if chrom < 0 || chrom >= ChromIds.instance().size()
      NullPointerException - if ids == null or if any element of ids is null
      NullPointerException - if alleles == null or if any element of alleles is null
    • BasicMarker

      public BasicMarker(int chrom, int pos, String[] ids, 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:
      IllegalArgumentException - if chrom < 0 || chrom >= ChromIds.instance().size()
      NullPointerException - if ids == null or if any element of ids is null
      NullPointerException - if alleles == null or if any element of alleles is null
    • BasicMarker

      public BasicMarker(String vcfRecord)
      Constructs a new BasicMarker instance from the specified string VCF record prefix.
      Parameters:
      vcfRecord - a VCF record prefix
      Throws:
      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
      NullPointerException - if vcfRecord == null
  • Method Details

    • 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:
      NullPointerException - if marker == null
    • flipStrand

      public static String flipStrand(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:
      IllegalArgumentException - if any character in the specified string is not 'A', 'C', 'G', 'T', 'N', or '*'.
      NullPointerException - if allele == null
    • chrom

      public 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 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 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 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 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 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 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 Object
      Returns:
      the hash code value for this marker
    • equals

      public boolean equals(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 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 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