# Class Genotype

java.lang.Object
htsjdk.variant.variantcontext.Genotype

All Implemented Interfaces:
  `Serializable, Comparable<Genotype>`

Direct Known Subclasses:
  `FastGenotype`

public abstract class Genotype extends Object implements Comparable<Genotype>, Serializable
This class encompasses all the basic information about a genotype. It is immutable.

See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`PHASED_ALLELE_SEPARATOR`
`static final Collection<String>`
`PRIMARY_KEYS`
A list of genotype field keys corresponding to values we manage inline in the Genotype object.
`static final long`
`serialVersionUID`
`static final String`
`UNPHASED_ALLELE_SEPARATOR`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Genotype(String sampleName, String filters)`

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(Genotype genotype)`
comparable genotypes -> compareTo on the sample names
`int`
`countAllele(Allele allele)`
Returns how many times allele appears in this genotype object?
`protected GenotypeType`
`determineType()`
Internal code to determine the type of the genotype from the alleles vector
`abstract int[]`
`getAD()`
`abstract Allele`
`getAllele(int i)`
Get the ith allele in this genotype
`abstract List<Allele>`
`getAlleles()`
`protected List<String>`
`getAlleleStrings()`
Utility that returns a list of allele strings corresponding to the alleles in this sample
`Object`
`getAnyAttribute(String key)`
A totally generic getter, that allows you to get specific keys that correspond to even inline values (GQ, for example).
`double`
`getAttributeAsDouble(String key, double defaultValue)`
Deprecated.
`int`
`getAttributeAsInt(String key, int defaultValue)`
Deprecated.
`String`
`getAttributeAsString(String key, String defaultValue)`
Deprecated.
`abstract int`
`getDP()`
`Object`
`getExtendedAttribute(String key)`
Same as #getExtendedAttribute with a null default
`Object`
`getExtendedAttribute(String key, Object defaultValue)`
Get the extended attribute value associated with key, if possible
`abstract Map<String,Object>`
`getExtendedAttributes()`
Returns the extended attributes for this object
`final String`
`getFilters()`
Returns the filter string associated with this Genotype.
`String`
`getGenotypeString()`
Return a VCF-like string representation for the alleles of this genotype.
`String`
`getGenotypeString(boolean ignoreRefState)`
Return a VCF-like string representation for the alleles of this genotype.
`abstract int`
`getGQ()`
Returns a phred-scaled quality score, or -1 if none is available
`GenotypeLikelihoods`
`getLikelihoods()`
Returns the GenotypesLikelihoods data associated with this Genotype, or null if missing
`String`
`getLikelihoodsString()`
Convenience function that returns a string representation of the PL field of this genotype, or .
`double`
`getLog10PError()`
Deprecated.
`int`
`getPhredScaledQual()`
Deprecated.
`abstract int[]`
`getPL()`
Unsafe low-level accessor the PL field itself, may be null.
`int`
`getPloidy()`
What is the ploidy of this sample?
`String`
`getSampleName()`
Returns the name associated with this sample.
`GenotypeType`
`getType()`
`boolean`
`hasAD()`
Does the AD field have a value?
`boolean`
`hasAltAllele()`
`boolean`
`hasAnyAttribute(String key)`
`boolean`
`hasDP()`
Does the DP field have a value?
`boolean`
`hasExtendedAttribute(String key)`
Is key associated with a value (even a null one) in the extended attributes? Note this will not return true for the inline attributes DP, GQ, AD, or PL
`protected static final boolean`
`hasForbiddenKey(Map<String,Object> attributes)`
Does the attribute map have a mapping involving a forbidden key (i.e., one that's managed inline by this Genotypes object?
`boolean`
`hasGQ()`
Does the GQ field have a value?
`boolean`
`hasLikelihoods()`
`boolean`
`hasLog10PError()`
Deprecated.
`boolean`
`hasPL()`
Does the PL field have a value?
`boolean`
`hasRefAllele()`
`boolean`
`isAvailable()`
`boolean`
`isCalled()`
`final boolean`
`isFiltered()`
Is this genotype filtered or not?
`protected static final boolean`
`isForbiddenKey(String key)`
`boolean`
`isHet()`
`boolean`
`isHetNonRef()`
`boolean`
`isHom()`
`boolean`
`isHomRef()`
`boolean`
`isHomVar()`
`boolean`
`isMixed()`
`boolean`
`isNoCall()`
`boolean`
`isNonInformative()`
Are all likelihoods for this sample non-informative? Returns true if all PLs are 0 => 0,0,0 => true 0,0,0,0,0,0 => true 0,10,100 => false
`abstract boolean`
`isPhased()`
Are the alleles phased w.r.t.
`boolean`
`sameGenotype(Genotype other)`
`boolean`
`sameGenotype(Genotype other, boolean ignorePhase)`
`protected static <T extends Comparable<T>, V>
String`
`sortedString(Map<T,V> c)`
a utility method for generating sorted strings from a map key set.
`String`
`toBriefString()`
`String`
`toString()`
`protected static final String`
`toStringIfExists(String name, int v)`
Returns a display name for field name with value v if this isn't -1.
`protected static final String`
`toStringIfExists(String name, int[] vs)`
Returns a display name for field name with values vs if this isn't null.
`protected static final String`
`toStringIfExists(String name, String v)`
Returns a display name for field name with String value v if this isn't null.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### serialVersionUID

public static final long serialVersionUID

See Also:
  - Constant Field Values

### PRIMARY_KEYS

public static final Collection<String> PRIMARY_KEYS
A list of genotype field keys corresponding to values we manage inline in the Genotype object. They must not appear in the extended attributes map

### PHASED_ALLELE_SEPARATOR

public static final String PHASED_ALLELE_SEPARATOR

See Also:
  - Constant Field Values

### UNPHASED_ALLELE_SEPARATOR

public static final String UNPHASED_ALLELE_SEPARATOR

See Also:
  - Constant Field Values

## Constructor Details

### Genotype

protected Genotype(String sampleName, String filters)

## Method Details

### getAlleles

public abstract List<Allele> getAlleles()

Returns:
  the alleles for this genotype. Cannot be null. May be empty

### hasRefAllele

public boolean hasRefAllele()

Returns:
  true if any allele is REF

### hasAltAllele

public boolean hasAltAllele()

Returns:
  true if any allele is ALT, (NO_CALL are ignored)

### countAllele

public int countAllele(Allele allele)
Returns how many times allele appears in this genotype object?

Parameters:
  `allele` -
Returns:
  a value >= 0 indicating how many times the allele occurred in this sample's genotype

### getAllele

public abstract Allele getAllele(int i)
Get the ith allele in this genotype

Parameters:
  `i` - the ith allele, must be < the ploidy, starting with 0
Returns:
  the allele at position i, which cannot be null

### isPhased

public abstract boolean isPhased()
Are the alleles phased w.r.t. the global phasing system?

Returns:
  true if yes

### getPloidy

public int getPloidy()
What is the ploidy of this sample?

Returns:
  the ploidy of this genotype. 0 if the site is no-called.

### getDP

public abstract int getDP()

Returns:
  the sequencing depth of this sample, or -1 if this value is missing

### getAD

public abstract int[] getAD()

Returns:
  the count of reads, one for each allele in the surrounding Variant context, matching the corresponding allele, or null if this value is missing. MUST NOT BE MODIFIED!

### getSampleName

public String getSampleName()
Returns the name associated with this sample.

Returns:
  a non-null String

### getGQ

public abstract int getGQ()
Returns a phred-scaled quality score, or -1 if none is available

Returns:

### hasPL

public boolean hasPL()
Does the PL field have a value?

Returns:
  true if there's a PL field value

### hasAD

public boolean hasAD()
Does the AD field have a value?

Returns:
  true if there's a AD field value

### hasGQ

public boolean hasGQ()
Does the GQ field have a value?

Returns:
  true if there's a GQ field value

### hasDP

public boolean hasDP()
Does the DP field have a value?

Returns:
  true if there's a DP field value

### getType

public GenotypeType getType()

Returns:
  the high-level type of this sample's genotype

### determineType

protected GenotypeType determineType()
Internal code to determine the type of the genotype from the alleles vector

Returns:
  the type

### isHom

public boolean isHom()

Returns:
  true if all observed alleles are the same (regardless of whether they are ref or alt); if any alleles are no-calls, this method will return false.

### isHomRef

public boolean isHomRef()

Returns:
  true if all observed alleles are ref; if any alleles are no-calls, this method will return false.

### isHomVar

public boolean isHomVar()

Returns:
  true if all observed alleles are alt; if any alleles are no-calls, this method will return false.

### isHet

public boolean isHet()

Returns:
  true if we're het (observed alleles differ); if the ploidy is less than 2 or if any alleles are no-calls, this method will return false.

### isHetNonRef

public boolean isHetNonRef()

Returns:
  true if we're het (observed alleles differ) and neither allele is reference; if the ploidy is less than 2 or if any alleles are no-calls, this method will return false.

### isNoCall

public boolean isNoCall()

Returns:
  true if this genotype is not actually a genotype but a "no call" (e.g. './.' in VCF); if any alleles are not no-calls (even if some are), this method will return false.

### isCalled

public boolean isCalled()

Returns:
  true if this genotype is comprised of any alleles that are not no-calls (even if some are).

### isMixed

public boolean isMixed()

Returns:
  true if this genotype is comprised of both calls and no-calls.

### isAvailable

public boolean isAvailable()

Returns:
  true if the type of this genotype is set.

### hasLikelihoods

public boolean hasLikelihoods()

Returns:
  Returns true if this Genotype has PL field values

### getLikelihoodsString

public String getLikelihoodsString()
Convenience function that returns a string representation of the PL field of this genotype, or . if none is available.

Returns:
  a non-null String representation for the PL of this sample

### getLikelihoods

public GenotypeLikelihoods getLikelihoods()
Returns the GenotypesLikelihoods data associated with this Genotype, or null if missing

Returns:
  null or a GenotypesLikelihood object for this sample's PL field

### isNonInformative

public boolean isNonInformative()
Are all likelihoods for this sample non-informative? Returns true if all PLs are 0 => 0,0,0 => true 0,0,0,0,0,0 => true 0,10,100 => false

Returns:
  true if all samples PLs are equal and == 0

### getPL

public abstract int[] getPL()
Unsafe low-level accessor the PL field itself, may be null.

Returns:
  a pointer to the underlying PL data. MUST NOT BE MODIFIED!

### getGenotypeString

public String getGenotypeString()
Return a VCF-like string representation for the alleles of this genotype. Does not append the reference * marker on the alleles.

Returns:
  a string representing the genotypes, or null if the type is unavailable.

### getGenotypeString

public String getGenotypeString(boolean ignoreRefState)
Return a VCF-like string representation for the alleles of this genotype. If ignoreRefState is true, will not append the reference * marker on the alleles.

Returns:
  a string representing the genotypes, or null if the type is unavailable.

### getAlleleStrings

protected List<String> getAlleleStrings()
Utility that returns a list of allele strings corresponding to the alleles in this sample

Returns:

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### toBriefString

public String toBriefString()

### compareTo

public int compareTo(Genotype genotype)
comparable genotypes -> compareTo on the sample names

Specified by:
  `compareTo` in interface `Comparable<Genotype>`
Parameters:
  `genotype` -
Returns:

### sameGenotype

public boolean sameGenotype(Genotype other)

### sameGenotype

public boolean sameGenotype(Genotype other, boolean ignorePhase)

### getExtendedAttributes

public abstract Map<String,Object> getExtendedAttributes()
Returns the extended attributes for this object

Returns:
  is never null, but is often isEmpty()

### hasExtendedAttribute

public boolean hasExtendedAttribute(String key)
Is key associated with a value (even a null one) in the extended attributes? Note this will not return true for the inline attributes DP, GQ, AD, or PL

Parameters:
  `key` - a non-null string key to check for an association
Returns:
  true if key has a value in the extendedAttributes

### getExtendedAttribute

public Object getExtendedAttribute(String key, Object defaultValue)
Get the extended attribute value associated with key, if possible

Parameters:
  `key` - a non-null string key to fetch a value for
  `defaultValue` - the value to return if key isn't in the extended attributes
Returns:
  a value (potentially) null associated with key, or defaultValue if no association exists

### getExtendedAttribute

public Object getExtendedAttribute(String key)
Same as #getExtendedAttribute with a null default

Parameters:
  `key` -
Returns:

### getFilters

public final String getFilters()
Returns the filter string associated with this Genotype.

Returns:
  If this result == null, then the genotype is considered PASSing filters If the result != null, then the genotype has failed filtering for the reason(s) specified in result. To be reference compliant multiple filter field string values can be encoded with a ; separator.

### isFiltered

public final boolean isFiltered()
Is this genotype filtered or not?

Returns:
  returns false if getFilters() == null

### hasLog10PError

@Deprecated public boolean hasLog10PError()
Deprecated.

### getLog10PError

@Deprecated public double getLog10PError()
Deprecated.

### getPhredScaledQual

@Deprecated public int getPhredScaledQual()
Deprecated.

### getAttributeAsString

@Deprecated public String getAttributeAsString(String key, String defaultValue)
Deprecated.

### getAttributeAsInt

@Deprecated public int getAttributeAsInt(String key, int defaultValue)
Deprecated.

### getAttributeAsDouble

@Deprecated public double getAttributeAsDouble(String key, double defaultValue)
Deprecated.

### getAnyAttribute

public Object getAnyAttribute(String key)
A totally generic getter, that allows you to get specific keys that correspond to even inline values (GQ, for example). Can be very expensive. Additionally, all `int[]` are converted inline into `List<Integer>` for convenience.

Parameters:
  `key` -
Returns:

### hasAnyAttribute

public boolean hasAnyAttribute(String key)

### sortedString

protected static <T extends Comparable<T>, V> String sortedString(Map<T,V> c)
a utility method for generating sorted strings from a map key set.

Type Parameters:
  `T` - the key type
  `V` - the value type
Parameters:
  `c` - the map
Returns:
  a sting, enclosed in {}, with comma seperated key value pairs in order of the keys

### toStringIfExists

protected static final String toStringIfExists(String name, int v)
Returns a display name for field name with value v if this isn't -1. Otherwise returns ""

Parameters:
  `name` - of the field ("AD")
  `v` - the value of the field, or -1 if missing
Returns:
  a non-null string for display if the field is not missing

### toStringIfExists

protected static final String toStringIfExists(String name, String v)
Returns a display name for field name with String value v if this isn't null. Otherwise returns ""

Parameters:
  `name` - of the field ("FT")
  `v` - the value of the field, or null if missing
Returns:
  a non-null string for display if the field is not missing

### toStringIfExists

protected static final String toStringIfExists(String name, int[] vs)
Returns a display name for field name with values vs if this isn't null. Otherwise returns ""

Parameters:
  `name` - of the field ("AD")
  `vs` - the value of the field, or null if missing
Returns:
  a non-null string for display if the field is not missing

### hasForbiddenKey

protected static final boolean hasForbiddenKey(Map<String,Object> attributes)
Does the attribute map have a mapping involving a forbidden key (i.e., one that's managed inline by this Genotypes object?

Parameters:
  `attributes` - the extended attributes key
Returns:

### isForbiddenKey

protected static final boolean isForbiddenKey(String key)