V5 improvements to VariantContext. Now fully supports genotypes. Filtering enabled. Significant tests throughout system. Support for rebuilding variant contexts from subsets of genotypes. Some code cleanup around repository
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2721 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
9876645a5d
commit
956b570c8e
|
|
@ -13,6 +13,11 @@ public class Genotype extends AttributedObject {
|
|||
private List<Allele> alleles = new ArrayList<Allele>();
|
||||
private String sampleName = null;
|
||||
|
||||
// todo -- do genotypes need to have locations? Or is it sufficient to have an
|
||||
// todo -- associated VC with a location? One nasty implication is that people will have to
|
||||
// todo -- pass around both a Variant Context and genotypes. Although users can always just package up
|
||||
// the associated genotypes into the VC itself.
|
||||
|
||||
public Genotype(VariantContext vc, List<String> alleles, String sampleName, double negLog10PError) {
|
||||
this(resolveAlleles(vc, alleles), sampleName, negLog10PError);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class TestVariantContextWalker extends RodWalker<Integer, Integer> {
|
|||
for (ReferenceOrderedDatum d : dbsnpList) {
|
||||
rodDbSNP dbsnpRecord = (rodDbSNP)d;
|
||||
if ( dbsnpRecord.getLocation().getStart() == context.getLocation().getStart() ) {
|
||||
VariantContext vc = VariantContextAdaptors.dbsnp2VariantContext(dbsnpRecord);
|
||||
VariantContext vc = VariantContextAdaptors.dbsnpToVariantContext(dbsnpRecord);
|
||||
if ( vc != null ) {
|
||||
n++;
|
||||
System.out.printf("%s%n", vc);
|
||||
|
|
@ -40,7 +40,7 @@ public class TestVariantContextWalker extends RodWalker<Integer, Integer> {
|
|||
int n = 0;
|
||||
for (ReferenceOrderedDatum d : vcfList) {
|
||||
RodVCF vcfRecord = (RodVCF)d;
|
||||
VariantContext vc = VariantContextAdaptors.vcf2VariantContext(vcfRecord);
|
||||
VariantContext vc = VariantContextAdaptors.vcfToVariantContext(vcfRecord);
|
||||
if ( vc != null ) {
|
||||
n++;
|
||||
System.out.printf("%s%n", vc);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.broadinstitute.sting.oneoffprojects.variantcontext;
|
|||
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
import org.broadinstitute.sting.utils.BaseUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -22,7 +23,8 @@ public class VariantContext extends AttributedObject {
|
|||
|
||||
Type type = Type.UNDETERMINED;
|
||||
|
||||
// todo -- add FILTER
|
||||
Set<Object> filters = new HashSet<Object>();
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
|
|
@ -31,20 +33,17 @@ public class VariantContext extends AttributedObject {
|
|||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
public VariantContext(GenomeLoc loc) {
|
||||
if ( loc == null ) { throw new StingException("GenomeLoc cannot be null"); }
|
||||
super();
|
||||
|
||||
if ( loc == null ) { throw new StingException("GenomeLoc cannot be null"); }
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
protected VariantContext(VariantContext parent, Set<Genotype> genotypes, HashMap<Object, Object> attributes) {
|
||||
this(parent.getLocation(), parent.getAlleles(), genotypes, attributes);
|
||||
public VariantContext(GenomeLoc loc, Collection<Allele> alleles) {
|
||||
this(loc, alleles, (Map<Object, Object>)null);
|
||||
}
|
||||
|
||||
// todo -- add more convenience methods
|
||||
public VariantContext(GenomeLoc loc, Set<Allele> alleles) { this(loc, alleles, null); }
|
||||
public VariantContext(GenomeLoc loc, List<Allele> alleles ) { this(loc, alleles, null); }
|
||||
|
||||
public VariantContext(GenomeLoc loc, List<Allele> alleles, Map<Object, Object> attributes) {
|
||||
public VariantContext(GenomeLoc loc, Collection<Allele> alleles, Map<Object, Object> attributes) {
|
||||
this(loc);
|
||||
|
||||
HashSet<Allele> alleleSet = new HashSet<Allele>();
|
||||
|
|
@ -59,30 +58,114 @@ public class VariantContext extends AttributedObject {
|
|||
validate();
|
||||
}
|
||||
|
||||
public VariantContext(GenomeLoc loc, Set<Allele> alleles, Map<Object, Object> attributes) {
|
||||
this(loc);
|
||||
setAlleles(alleles);
|
||||
setAttributes(attributes);
|
||||
validate();
|
||||
}
|
||||
|
||||
public VariantContext(GenomeLoc loc, Set<Allele> alleles, Set<Genotype> genotypes, Map<Object, Object> attributes) {
|
||||
public VariantContext(GenomeLoc loc, Collection<Allele> alleles, Collection<Genotype> genotypes) {
|
||||
this(loc);
|
||||
setAlleles(alleles);
|
||||
setGenotypes(genotypes);
|
||||
setAttributes(attributes);
|
||||
validate();
|
||||
}
|
||||
|
||||
|
||||
public VariantContext(GenomeLoc loc, Set<Allele> alleles, Map<String, Genotype> genotypes, Map<Object, Object> attributes) {
|
||||
public VariantContext(GenomeLoc loc, Collection<Allele> alleles,
|
||||
Collection<Genotype> genotypes, Map<Object, Object> attributes,
|
||||
double negLog10PError, Collection<Object> filters) {
|
||||
this(loc);
|
||||
setAlleles(alleles);
|
||||
setGenotypes(genotypes);
|
||||
setAttributes(attributes);
|
||||
setNegLog10PError(negLog10PError);
|
||||
setFilters(filters);
|
||||
validate();
|
||||
}
|
||||
|
||||
public VariantContext(GenomeLoc loc, Collection<Allele> alleles,
|
||||
Map<String, Genotype> genotypes, Map<Object, Object> attributes,
|
||||
double negLog10PError, Collection<Object> filters) {
|
||||
this(loc);
|
||||
setAlleles(alleles);
|
||||
setGenotypes(genotypes);
|
||||
setAttributes(attributes);
|
||||
setNegLog10PError(negLog10PError);
|
||||
setFilters(filters);
|
||||
validate();
|
||||
}
|
||||
|
||||
// todo -- add clone method
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Selectors
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
public VariantContext subContextFromGenotypes(Genotype genotype) {
|
||||
return subContextFromGenotypes(Arrays.asList(genotype));
|
||||
}
|
||||
|
||||
public VariantContext subContextFromGenotypes(Collection<Genotype> genotypes) {
|
||||
// todo -- we should check for uniqueness of genotypes
|
||||
return subContextFromGenotypes(new HashSet<Genotype>(genotypes), getAttributes());
|
||||
}
|
||||
|
||||
public VariantContext subContextFromGenotypes(Collection<Genotype> genotypes, Map<Object, Object> attributes) {
|
||||
return new VariantContext(getLocation(), allelesOfGenotypes(genotypes), genotypes, attributes, getNegLog10PError(), getFilters());
|
||||
}
|
||||
|
||||
/** helper routnine for subcontext */
|
||||
private Set<Allele> allelesOfGenotypes(Collection<Genotype> genotypes) {
|
||||
Set<Allele> alleles = new HashSet<Allele>();
|
||||
|
||||
boolean addedref = false;
|
||||
for ( Genotype g : genotypes ) {
|
||||
for ( Allele a : g.getAlleles() ) {
|
||||
addedref = addedref || a.isReference();
|
||||
if ( a.isCalled() )
|
||||
alleles.add(a);
|
||||
}
|
||||
}
|
||||
if ( ! addedref ) alleles.add(getReference());
|
||||
|
||||
return alleles;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Filter
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
public Set<Object> getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public boolean isFiltered() {
|
||||
return filters.size() > 0;
|
||||
}
|
||||
|
||||
public boolean isNotFiltered() {
|
||||
return ! isFiltered();
|
||||
}
|
||||
|
||||
public void addFilter(Object filter) {
|
||||
if ( filter == null ) throw new IllegalArgumentException("BUG: Attempting to add null filter " + this);
|
||||
if ( getFilters().contains(filter) ) throw new IllegalArgumentException("BUG: Attempting to add duplicate filter " + filter + " at " + this);
|
||||
filters.add(filter);
|
||||
}
|
||||
|
||||
public void addFilters(Collection<? extends Object> filters) {
|
||||
if ( filters == null ) throw new IllegalArgumentException("BUG: Attempting to add null filters at" + this);
|
||||
for ( Object f : filters )
|
||||
addFilter(f);
|
||||
}
|
||||
|
||||
public void clearFilters() {
|
||||
filters.clear();
|
||||
}
|
||||
|
||||
public void setFilters(Collection<? extends Object> filters) {
|
||||
clearFilters();
|
||||
addFilters(filters);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// type operations
|
||||
|
|
@ -142,7 +225,6 @@ public class VariantContext extends AttributedObject {
|
|||
* Assigned to variations that are multi-base variations of a single, common length
|
||||
* GGA/AGT
|
||||
*/
|
||||
|
||||
public enum Type {
|
||||
NO_VARIATION,
|
||||
SNP,
|
||||
|
|
@ -172,6 +254,14 @@ public class VariantContext extends AttributedObject {
|
|||
*/
|
||||
public boolean isSNP() { return getType() == Type.SNP; }
|
||||
|
||||
public BaseUtils.BaseSubstitutionType getSNPSubstitutionType() {
|
||||
if ( ! isSNP() || ! isBiallelic() ) throw new IllegalStateException("Requested SNP substitution type for bialleic non-SNP " + this);
|
||||
return BaseUtils.SNPSubstitutionType(getReference().getBases()[0], getAlternateAllele(0).getBases()[0]);
|
||||
}
|
||||
|
||||
public boolean isTransition() { return getSNPSubstitutionType() == BaseUtils.BaseSubstitutionType.TRANSITION; }
|
||||
public boolean isTransversion() { return getSNPSubstitutionType() == BaseUtils.BaseSubstitutionType.TRANSVERSION; }
|
||||
|
||||
/**
|
||||
* convenience method for variants
|
||||
*
|
||||
|
|
@ -207,6 +297,7 @@ public class VariantContext extends AttributedObject {
|
|||
*/
|
||||
public boolean isMixed() { return getType() == Type.MIXED; }
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Generic accessors
|
||||
|
|
@ -276,26 +367,6 @@ public class VariantContext extends AttributedObject {
|
|||
return false;
|
||||
}
|
||||
|
||||
// public int getMaxAlleleLength() {
|
||||
// int max = 0;
|
||||
//
|
||||
// for ( Allele a : getAlleles() ) {
|
||||
// max = a.length() > max ? a.length() : max;
|
||||
// }
|
||||
//
|
||||
// return max;
|
||||
// }
|
||||
//
|
||||
// public int getMinAlleleLength() {
|
||||
// int min = Integer.MAX_VALUE;
|
||||
//
|
||||
// for ( Allele a : getAlleles() ) {
|
||||
// min = a.length() < min ? a.length() : min;
|
||||
// }
|
||||
//
|
||||
// return min;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets the alleles. This method should return all of the alleles present at the location,
|
||||
* including the reference allele. There are no constraints imposed on the ordering of alleles
|
||||
|
|
@ -334,7 +405,7 @@ public class VariantContext extends AttributedObject {
|
|||
}
|
||||
|
||||
|
||||
public void setAlleles(Set<Allele> alleles) {
|
||||
public void setAlleles(Collection<Allele> alleles) {
|
||||
this.alleles.clear();
|
||||
for ( Allele a : alleles )
|
||||
addAllele(a);
|
||||
|
|
@ -368,11 +439,28 @@ public class VariantContext extends AttributedObject {
|
|||
*/
|
||||
public boolean hasGenotypes() { return genotypes.size() > 0; }
|
||||
|
||||
public boolean hasSingleSample() { return genotypes.size() == 1; }
|
||||
|
||||
/**
|
||||
* @return set of all Genotypes associated with this context
|
||||
*/
|
||||
public Map<String, Genotype> getGenotypes() { return genotypes; }
|
||||
|
||||
public Map<String, Genotype> getGenotypes(String sampleName) {
|
||||
return getGenotypes(Arrays.asList(sampleName));
|
||||
}
|
||||
|
||||
public Map<String, Genotype> getGenotypes(Collection<String> sampleNames) {
|
||||
HashMap<String, Genotype> map = new HashMap<String, Genotype>();
|
||||
|
||||
for ( String name : sampleNames ) {
|
||||
if ( map.containsKey(name) ) throw new IllegalArgumentException("Duplicate names detected in requested samples " + sampleNames);
|
||||
map.put(name, getGenotype(name));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the set of all sample names in this context
|
||||
*/
|
||||
|
|
@ -553,12 +641,11 @@ public class VariantContext extends AttributedObject {
|
|||
if ( ! alreadySeenRef )
|
||||
throw new IllegalArgumentException("No reference allele found in VariantContext");
|
||||
|
||||
if ( getType() == Type.INDEL ) {
|
||||
// if ( getType() == Type.INDEL ) {
|
||||
// if ( getReference().length() != (getLocation().size()-1) ) {
|
||||
if ( (getReference().isNull() && getLocation().size() != 1 ) ||
|
||||
(getReference().isNonNull() && getReference().length() != getLocation().size()) ) {
|
||||
throw new IllegalStateException("BUG: GenomeLoc " + getLocation() + " has a size == " + getLocation().size() + " but the variation reference allele has length " + getReference().length() + " this = " + this);
|
||||
}
|
||||
if ( (getReference().isNull() && getLocation().size() != 1 ) ||
|
||||
(getReference().isNonNull() && getReference().length() != getLocation().size()) ) {
|
||||
throw new IllegalStateException("BUG: GenomeLoc " + getLocation() + " has a size == " + getLocation().size() + " but the variation reference allele has length " + getReference().length() + " this = " + this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.*;
|
|||
|
||||
|
||||
public class VariantContextAdaptors {
|
||||
public static VariantContext dbsnp2VariantContext(rodDbSNP dbsnp) {
|
||||
public static VariantContext dbsnpToVariantContext(rodDbSNP dbsnp) {
|
||||
if ( dbsnp.isSNP() || dbsnp.isIndel() || dbsnp.varType.contains("mixed") ) {
|
||||
VariantContext vc = new VariantContext(dbsnp.getLocation());
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ public class VariantContextAdaptors {
|
|||
return null; // can't handle anything else
|
||||
}
|
||||
|
||||
public static VariantContext vcf2VariantContext(RodVCF vcf) {
|
||||
public static VariantContext vcfToVariantContext(RodVCF vcf) {
|
||||
if ( vcf.isSNP() || vcf.isIndel() ) {
|
||||
VariantContext vc = new VariantContext(vcf.getLocation());
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ public class VariantContextAdaptors {
|
|||
vc.setNegLog10PError(vcf.getNegLog10PError());
|
||||
vc.setAttributes(vcf.getInfoValues());
|
||||
vc.putAttribute("ID", vcf.getID());
|
||||
vc.putAttribute("FILTER", vcf.getFilterString());
|
||||
if ( vcf.isFiltered() ) vc.setFilters(Arrays.asList(vcf.getFilteringCodes()));
|
||||
|
||||
// add all of the alt alleles
|
||||
for ( String alt : vcf.getAlternateAlleleList() ) {
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ public class VariantContextUtils {
|
|||
* throws an exception if there is a collision such that the same sample exists in both contexts
|
||||
* @return a context representing the merge of this context and the other provided context
|
||||
*/
|
||||
public VariantContext merge(VariantContext left, VariantContext other) {
|
||||
return merge(left, other, false);
|
||||
}
|
||||
// public VariantContext merge(VariantContext left, VariantContext other) {
|
||||
// return merge(left, other, false);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param other another variant context
|
||||
|
|
@ -25,30 +25,30 @@ public class VariantContextUtils {
|
|||
*
|
||||
* @return a context representing the merge of this context and the other provided context
|
||||
*/
|
||||
public VariantContext merge(VariantContext left, VariantContext other, boolean uniquifySamples) {
|
||||
// todo -- make functional
|
||||
|
||||
if ( !left.getLocation().equals(other.getLocation()) )
|
||||
throw new IllegalArgumentException("The locations must be identical for two contexts to be merged");
|
||||
|
||||
Set<String> samples = left.getSampleNames();
|
||||
Set<Genotype> Gs = new HashSet<Genotype>(left.getGenotypes().values());
|
||||
|
||||
for ( Genotype g : other.getGenotypes().values() ) {
|
||||
if ( samples.contains(g.getSampleName()) ) {
|
||||
if ( uniquifySamples )
|
||||
g.setSampleName(g.getSampleName() + UNIQUIFIED_SUFFIX);
|
||||
else
|
||||
throw new IllegalStateException("The same sample name exists in both contexts when attempting to merge");
|
||||
}
|
||||
Gs.add(g);
|
||||
}
|
||||
|
||||
HashMap<Object, Object> attrs = new HashMap<Object, Object>(left.getAttributes());
|
||||
attrs.putAll(other.getAttributes());
|
||||
|
||||
return new VariantContext(left, Gs, attrs);
|
||||
}
|
||||
// public VariantContext merge(VariantContext left, VariantContext other, boolean uniquifySamples) {
|
||||
// // todo -- make functional
|
||||
//
|
||||
// if ( !left.getLocation().equals(other.getLocation()) )
|
||||
// throw new IllegalArgumentException("The locations must be identical for two contexts to be merged");
|
||||
//
|
||||
// Set<String> samples = left.getSampleNames();
|
||||
// Set<Genotype> Gs = new HashSet<Genotype>(left.getGenotypes().values());
|
||||
//
|
||||
// for ( Genotype g : other.getGenotypes().values() ) {
|
||||
// if ( samples.contains(g.getSampleName()) ) {
|
||||
// if ( uniquifySamples )
|
||||
// g.setSampleName(g.getSampleName() + UNIQUIFIED_SUFFIX);
|
||||
// else
|
||||
// throw new IllegalStateException("The same sample name exists in both contexts when attempting to merge");
|
||||
// }
|
||||
// Gs.add(g);
|
||||
// }
|
||||
//
|
||||
// HashMap<Object, Object> attrs = new HashMap<Object, Object>(left.getAttributes());
|
||||
// attrs.putAll(other.getAttributes());
|
||||
//
|
||||
// return new VariantContext(left, Gs, attrs);
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ public class SubstitutionEvaluation implements VariantEvaluation {
|
|||
for (char abase : BaseUtils.BASES) {
|
||||
String altAllele = String.format("%c", abase);
|
||||
|
||||
if (BaseUtils.isTransition(rbase, abase)) {
|
||||
if (BaseUtils.isTransition((byte)rbase, (byte)abase)) {
|
||||
transitions += substitutions.get(refAllele, altAllele);
|
||||
} else if (BaseUtils.isTransversion(rbase, abase)) {
|
||||
} else if (BaseUtils.isTransversion((byte)rbase, (byte)abase)) {
|
||||
transversions += substitutions.get(refAllele, altAllele);
|
||||
} else {
|
||||
unknown += substitutions.get(refAllele, altAllele);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class TransitionTranversionAnalysis extends BasicVariantAnalysis implemen
|
|||
public String update(Variation eval, RefMetaDataTracker tracker, char ref, AlignmentContext context) {
|
||||
if (eval != null && eval.isSNP()) {
|
||||
char altBase = eval.getAlternativeBaseForSNP();
|
||||
BaseUtils.BaseSubstitutionType subType = BaseUtils.SNPSubstitutionType(ref, altBase);
|
||||
BaseUtils.BaseSubstitutionType subType = BaseUtils.SNPSubstitutionType((byte)ref, (byte)altBase);
|
||||
if (subType == BaseUtils.BaseSubstitutionType.TRANSITION)
|
||||
nTransitions++;
|
||||
else
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public class AnnotationDataManager {
|
|||
final boolean isTrueVariant = false; //BUGBUG: Check truth input file to see if this variant is in the truth set
|
||||
|
||||
// Decide if the variant is a transition or transversion
|
||||
if( BaseUtils.isTransition( variant.getReferenceForSNP(), variant.getAlternativeBaseForSNP()) ) {
|
||||
if( BaseUtils.isTransition( (byte)variant.getReferenceForSNP(), (byte)variant.getAlternativeBaseForSNP()) ) {
|
||||
datum.incrementTi( isNovelVariant, isTrueVariant );
|
||||
} else {
|
||||
datum.incrementTv( isNovelVariant, isTrueVariant );
|
||||
|
|
|
|||
|
|
@ -24,20 +24,20 @@ public class BaseUtils {
|
|||
* @param base2
|
||||
* @return
|
||||
*/
|
||||
public static BaseSubstitutionType SNPSubstitutionType( char base1, char base2 ) {
|
||||
public static BaseSubstitutionType SNPSubstitutionType( byte base1, byte base2 ) {
|
||||
BaseSubstitutionType t = isTransition(base1, base2) ? BaseSubstitutionType.TRANSITION : BaseSubstitutionType.TRANSVERSION;
|
||||
//System.out.printf("SNPSubstitutionType( char %c, char %c ) => %s%n", base1, base2, t);
|
||||
return t;
|
||||
}
|
||||
|
||||
public static boolean isTransition( char base1, char base2 ) {
|
||||
public static boolean isTransition( byte base1, byte base2 ) {
|
||||
int b1 = simpleBaseToBaseIndex(base1);
|
||||
int b2 = simpleBaseToBaseIndex(base2);
|
||||
return b1 == 0 && b2 == 2 || b1 == 2 && b2 == 0 ||
|
||||
b1 == 1 && b2 == 3 || b1 == 3 && b2 == 1;
|
||||
}
|
||||
|
||||
public static boolean isTransversion( char base1, char base2 ) {
|
||||
public static boolean isTransversion( byte base1, byte base2 ) {
|
||||
return ! isTransition(base1, base2);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import org.junit.BeforeClass;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.File;
|
||||
|
||||
|
|
@ -37,7 +39,7 @@ public class VariantContextTest extends BaseTest {
|
|||
Allele del, delRef, ATC, ATCref;
|
||||
|
||||
// A [ref] / T at 10
|
||||
GenomeLoc snpLoc = GenomeLocParser.createGenomeLoc("chr1", 10, 11);
|
||||
GenomeLoc snpLoc = GenomeLocParser.createGenomeLoc("chr1", 10, 10);
|
||||
|
||||
// - / ATC [ref] from 20-23
|
||||
GenomeLoc delLoc = GenomeLocParser.createGenomeLoc("chr1", 20, 22);
|
||||
|
|
@ -80,6 +82,9 @@ public class VariantContextTest extends BaseTest {
|
|||
Assert.assertTrue(vc.isBiallelic());
|
||||
Assert.assertEquals(vc.getNAlleles(), 2);
|
||||
|
||||
Assert.assertTrue(vc.isTransversion());
|
||||
Assert.assertFalse(vc.isTransition());
|
||||
|
||||
Assert.assertEquals(vc.getReference(), Aref);
|
||||
Assert.assertEquals(vc.getAlleles().size(), 2);
|
||||
Assert.assertEquals(vc.getAlternateAlleles().size(), 1);
|
||||
|
|
@ -203,6 +208,19 @@ public class VariantContextTest extends BaseTest {
|
|||
new VariantContext(insLoc, Arrays.asList(Aref, A));
|
||||
}
|
||||
|
||||
@Test (expected = IllegalStateException.class)
|
||||
public void testBadLoc1() {
|
||||
logger.warn("testBadLoc1");
|
||||
List<Allele> alleles = Arrays.asList(Aref, T, del);
|
||||
VariantContext vc = new VariantContext(delLoc, alleles);
|
||||
}
|
||||
|
||||
|
||||
@Test (expected = IllegalStateException.class)
|
||||
public void testBadTiTvRequest() {
|
||||
logger.warn("testBadConstructorArgsDuplicateAlleles2");
|
||||
new VariantContext(insLoc, Arrays.asList(Aref, ATC)).isTransition();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccessingSimpleSNPGenotypes() {
|
||||
|
|
@ -249,7 +267,7 @@ public class VariantContextTest extends BaseTest {
|
|||
logger.warn("testAccessingCompleteGenotypes");
|
||||
|
||||
List<Allele> alleles = Arrays.asList(Aref, T, del);
|
||||
VariantContext vc = new VariantContext(delLoc, alleles);
|
||||
VariantContext vc = new VariantContext(snpLoc, alleles);
|
||||
logger.warn("vc = " + vc);
|
||||
|
||||
Genotype g1 = new Genotype(Arrays.asList(Aref, Aref), "AA", 10);
|
||||
|
|
@ -266,6 +284,8 @@ public class VariantContextTest extends BaseTest {
|
|||
Assert.assertTrue(vc.isPolymorphic());
|
||||
Assert.assertEquals(vc.getGenotypes().size(), 6);
|
||||
|
||||
Assert.assertEquals(3, vc.getGenotypes(Arrays.asList("AA", "Td", "dd")).size());
|
||||
|
||||
Assert.assertEquals(10, vc.getChromosomeCount());
|
||||
Assert.assertEquals(3, vc.getChromosomeCount(Aref));
|
||||
Assert.assertEquals(4, vc.getChromosomeCount(T));
|
||||
|
|
@ -302,6 +322,99 @@ public class VariantContextTest extends BaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilters() {
|
||||
logger.warn("testFilters");
|
||||
|
||||
List<Allele> alleles = Arrays.asList(Aref, T, del);
|
||||
Genotype g1 = new Genotype(Arrays.asList(Aref, Aref), "AA", 10);
|
||||
Genotype g2 = new Genotype(Arrays.asList(Aref, T), "AT", 10);
|
||||
VariantContext vc = new VariantContext(snpLoc, alleles, Arrays.asList(g1,g2));
|
||||
logger.warn("vc = " + vc);
|
||||
|
||||
Assert.assertTrue(vc.isNotFiltered());
|
||||
Assert.assertFalse(vc.isFiltered());
|
||||
Assert.assertEquals(0, vc.getFilters().size());
|
||||
|
||||
vc.addFilter("BAD_SNP_BAD!");
|
||||
|
||||
Assert.assertFalse(vc.isNotFiltered());
|
||||
Assert.assertTrue(vc.isFiltered());
|
||||
Assert.assertEquals(1, vc.getFilters().size());
|
||||
|
||||
vc.addFilters(Arrays.asList("REALLY_BAD_SNP", "CHRIST_THIS_IS_TERRIBLE"));
|
||||
|
||||
Assert.assertFalse(vc.isNotFiltered());
|
||||
Assert.assertTrue(vc.isFiltered());
|
||||
Assert.assertEquals(3, vc.getFilters().size());
|
||||
|
||||
vc.clearFilters();
|
||||
|
||||
Assert.assertTrue(vc.isNotFiltered());
|
||||
Assert.assertFalse(vc.isFiltered());
|
||||
Assert.assertEquals(0, vc.getFilters().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCromGenotypes() {
|
||||
logger.warn("testVCromGenotypes");
|
||||
|
||||
List<Allele> alleles = Arrays.asList(Aref, T, del);
|
||||
Genotype g1 = new Genotype(Arrays.asList(Aref, Aref), "AA", 10);
|
||||
Genotype g2 = new Genotype(Arrays.asList(Aref, T), "AT", 10);
|
||||
Genotype g3 = new Genotype(Arrays.asList(T, T), "TT", 10);
|
||||
Genotype g4 = new Genotype(Arrays.asList(Allele.NO_CALL, Allele.NO_CALL), "..", 10);
|
||||
Genotype g5 = new Genotype(Arrays.asList(del, del), "--", 10);
|
||||
VariantContext vc = new VariantContext(snpLoc, alleles, Arrays.asList(g1,g2,g3,g4,g5));
|
||||
logger.warn("vc = " + vc);
|
||||
|
||||
VariantContext vc12 = vc.subContextFromGenotypes(Arrays.asList(g1,g2));
|
||||
VariantContext vc1 = vc.subContextFromGenotypes(Arrays.asList(g1));
|
||||
VariantContext vc23 = vc.subContextFromGenotypes(Arrays.asList(g2, g3));
|
||||
VariantContext vc4 = vc.subContextFromGenotypes(Arrays.asList(g4));
|
||||
VariantContext vc14 = vc.subContextFromGenotypes(Arrays.asList(g1, g4));
|
||||
VariantContext vc5 = vc.subContextFromGenotypes(Arrays.asList(g5));
|
||||
|
||||
Assert.assertTrue(vc12.isPolymorphic());
|
||||
Assert.assertTrue(vc23.isPolymorphic());
|
||||
Assert.assertTrue(vc1.isMonomorphic());
|
||||
Assert.assertTrue(vc4.isMonomorphic());
|
||||
Assert.assertTrue(vc14.isMonomorphic());
|
||||
Assert.assertTrue(vc5.isPolymorphic());
|
||||
|
||||
Assert.assertTrue(vc12.isSNP());
|
||||
Assert.assertTrue(vc12.isVariant());
|
||||
Assert.assertTrue(vc12.isBiallelic());
|
||||
|
||||
Assert.assertFalse(vc1.isSNP());
|
||||
Assert.assertFalse(vc1.isVariant());
|
||||
Assert.assertFalse(vc1.isBiallelic());
|
||||
|
||||
Assert.assertTrue(vc23.isSNP());
|
||||
Assert.assertTrue(vc23.isVariant());
|
||||
Assert.assertTrue(vc23.isBiallelic());
|
||||
|
||||
Assert.assertFalse(vc4.isSNP());
|
||||
Assert.assertFalse(vc4.isVariant());
|
||||
Assert.assertFalse(vc4.isBiallelic());
|
||||
|
||||
Assert.assertFalse(vc14.isSNP());
|
||||
Assert.assertFalse(vc14.isVariant());
|
||||
Assert.assertFalse(vc14.isBiallelic());
|
||||
|
||||
Assert.assertTrue(vc5.isIndel());
|
||||
Assert.assertTrue(vc5.isDeletion());
|
||||
Assert.assertTrue(vc5.isVariant());
|
||||
Assert.assertTrue(vc5.isBiallelic());
|
||||
|
||||
Assert.assertEquals(3, vc12.getChromosomeCount(Aref));
|
||||
Assert.assertEquals(1, vc23.getChromosomeCount(Aref));
|
||||
Assert.assertEquals(2, vc1.getChromosomeCount(Aref));
|
||||
Assert.assertEquals(0, vc4.getChromosomeCount(Aref));
|
||||
Assert.assertEquals(2, vc14.getChromosomeCount(Aref));
|
||||
Assert.assertEquals(0, vc5.getChromosomeCount(Aref));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testManipulatingAlleles() {
|
||||
|
|
|
|||
|
|
@ -27,27 +27,27 @@ public class BaseUtilsTest extends BaseTest {
|
|||
public void testTransitionTransversion() {
|
||||
logger.warn("Executing testTransitionTransversion");
|
||||
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 'G' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'C', 'A' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'C', 'T' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'C', 'G' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'T', 'A' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'T', 'C' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'T', 'G' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'G', 'A' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'G', 'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'G', 'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'G' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'C', (byte)'A' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'C', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'C', (byte)'G' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'T', (byte)'A' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'T', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'T', (byte)'G' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'G', (byte)'A' ) == BaseUtils.BaseSubstitutionType.TRANSITION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'G', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'G', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'a', 'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'a', 'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 't' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'A', 'c' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'a', 't' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( 'a', 'c' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'T' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'C' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'t' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'A', (byte)'c' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'t' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
Assert.assertTrue( BaseUtils.SNPSubstitutionType( (byte)'a', (byte)'c' ) == BaseUtils.BaseSubstitutionType.TRANSVERSION );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue