utility methods for genotype counts

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2912 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-03-02 20:23:41 +00:00
parent 7578678f99
commit 6ceae22793
1 changed files with 59 additions and 2 deletions

View File

@ -175,6 +175,9 @@ public class VariantContext {
/** A mapping from sampleName -> genotype objects for all genotypes associated with this context */ /** A mapping from sampleName -> genotype objects for all genotypes associated with this context */
protected Map<String, Genotype> genotypes = null; protected Map<String, Genotype> genotypes = null;
/** Counts for each of the possible Genotype types in this context */
protected int[] genotypeCounts = null;
protected final static Map<String, Genotype> NO_GENOTYPES = Collections.unmodifiableMap(new HashMap<String, Genotype>()); protected final static Map<String, Genotype> NO_GENOTYPES = Collections.unmodifiableMap(new HashMap<String, Genotype>());
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
@ -199,6 +202,7 @@ public class VariantContext {
if ( genotypes == null ) { genotypes = NO_GENOTYPES; } if ( genotypes == null ) { genotypes = NO_GENOTYPES; }
this.genotypes = Collections.unmodifiableMap(genotypes); this.genotypes = Collections.unmodifiableMap(genotypes);
calculateGenotypeCounts();
validate(); validate();
} }
@ -695,7 +699,7 @@ public class VariantContext {
* Genotype-specific functions -- are the genotypes monomorphic w.r.t. to the alleles segregating at this * Genotype-specific functions -- are the genotypes monomorphic w.r.t. to the alleles segregating at this
* site? That is, is the number of alternate alleles among all fo the genotype == 0? * site? That is, is the number of alternate alleles among all fo the genotype == 0?
* *
* @return * @return true if it's monomorphic
*/ */
public boolean isMonomorphic() { public boolean isMonomorphic() {
return ! isVariant() || getChromosomeCount(getReference()) == getChromosomeCount(); return ! isVariant() || getChromosomeCount(getReference()) == getChromosomeCount();
@ -705,12 +709,65 @@ public class VariantContext {
* Genotype-specific functions -- are the genotypes polymorphic w.r.t. to the alleles segregating at this * Genotype-specific functions -- are the genotypes polymorphic w.r.t. to the alleles segregating at this
* site? That is, is the number of alternate alleles among all fo the genotype > 0? * site? That is, is the number of alternate alleles among all fo the genotype > 0?
* *
* @return * @return true if it's polymorphic
*/ */
public boolean isPolymorphic() { public boolean isPolymorphic() {
return ! isMonomorphic(); return ! isMonomorphic();
} }
private void calculateGenotypeCounts() {
genotypeCounts = new int[Genotype.Type.values().length];
for ( Genotype g : getGenotypes().values() ) {
if ( g.isNoCall() )
genotypeCounts[Genotype.Type.NO_CALL.ordinal()]++;
else if ( g.isHomRef() )
genotypeCounts[Genotype.Type.HOM_REF.ordinal()]++;
else if ( g.isHet() )
genotypeCounts[Genotype.Type.HET.ordinal()]++;
else if ( g.isHomVar() )
genotypeCounts[Genotype.Type.HOM_VAR.ordinal()]++;
else
throw new StingException("Genotype of unknown type: " + g);
}
}
/**
* Genotype-specific functions -- how many no-calls are there in the genotypes?
*
* @return number of no calls
*/
public int getNoCallCount() {
return genotypeCounts[Genotype.Type.NO_CALL.ordinal()];
}
/**
* Genotype-specific functions -- how many hom ref calls are there in the genotypes?
*
* @return number of hom ref calls
*/
public int getHomRefCount() {
return genotypeCounts[Genotype.Type.HOM_REF.ordinal()];
}
/**
* Genotype-specific functions -- how many het calls are there in the genotypes?
*
* @return number of het calls
*/
public int getHetCount() {
return genotypeCounts[Genotype.Type.HET.ordinal()];
}
/**
* Genotype-specific functions -- how many hom var calls are there in the genotypes?
*
* @return number of hom var calls
*/
public int getHomVarCount() {
return genotypeCounts[Genotype.Type.HOM_VAR.ordinal()];
}
// --------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------
// //
// validation // validation