Killing the final versions of old new VariantContext interface

This commit is contained in:
Mark DePristo 2011-11-18 21:32:43 -05:00
parent 6cf315e17b
commit f685fff79b
7 changed files with 46 additions and 79 deletions

View File

@ -122,7 +122,7 @@ public class BeagleOutputToVCFWalker extends RodWalker<Integer, Integer> {
protected static String line = null;
private final double MIN_PROB_ERROR = 0.000001;
private final double MAX_GENOTYPE_QUALITY = 6.0;
private final double MAX_GENOTYPE_QUALITY = -6.0;
public void initialize() {
@ -292,7 +292,7 @@ public class BeagleOutputToVCFWalker extends RodWalker<Integer, Integer> {
if (probWrongGenotype < MIN_PROB_ERROR)
genotypeQuality = MAX_GENOTYPE_QUALITY;
else
genotypeQuality = -log10(probWrongGenotype);
genotypeQuality = log10(probWrongGenotype);
HashMap<String,Object> originalAttributes = new HashMap<String,Object>(g.getAttributes());

View File

@ -225,44 +225,6 @@ public class VariantContext implements Feature { // to enable tribble intergrati
//
// ---------------------------------------------------------------------------------------------------------
/**
* the complete constructor. Makes a complete VariantContext from its arguments
* This is the only constructor that is able to create indels! DO NOT USE THE OTHER ONES.
*
* @param source source
* @param contig the contig
* @param start the start base (one based)
* @param stop the stop reference base (one based)
* @param alleles alleles
* @param genotypes genotypes map
* @param log10PError qual
* @param filters filters: use null for unfiltered and empty set for passes filters
* @param attributes attributes
* @param referenceBaseForIndel padded reference base
*
* @deprecated replaced by {@link VariantContextBuilder}
*/
@Deprecated
protected VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles, GenotypesContext genotypes, double log10PError, Set<String> filters, Map<String, Object> attributes, Byte referenceBaseForIndel) {
this(source, ID, contig, start, stop, alleles, genotypes, log10PError, filters, attributes, referenceBaseForIndel, false, ALL_VALIDATION);
}
/**
* Create a new variant context without genotypes and no Perror, no filters, and no attributes
*
* @param source source
* @param contig the contig
* @param start the start base (one based)
* @param stop the stop reference base (one based)
* @param alleles alleles
*
* @deprecated replaced by {@link VariantContextBuilder}
*/
@Deprecated
public VariantContext(String source, String ID, String contig, long start, long stop, Collection<Allele> alleles) {
this(source, ID, contig, start, stop, alleles, NO_GENOTYPES, CommonInfo.NO_LOG10_PERROR, null, null, null, false, ALL_VALIDATION);
}
/**
* Copy constructor
*

View File

@ -375,8 +375,7 @@ public class VariantContextUtils {
genotypeAttributes, g.isPhased()));
}
return new VariantContext(vc.getSource(), vc.getID(), vc.getChr(), vc.getStart(), vc.getEnd(),
vc.getAlleles(), genotypes, vc.getLog10PError(), vc.getFilters(), attributes, vc.getReferenceBaseForIndel());
return new VariantContextBuilder(vc).genotypes(genotypes).attributes(attributes).make();
}
public enum GenotypeMergeType {

View File

@ -66,9 +66,9 @@ public class RefMetaDataTrackerUnitTest {
C = Allele.create("C");
G = Allele.create("G");
T = Allele.create("T");
AC_SNP = new VariantContext("x", VCFConstants.EMPTY_ID_FIELD, "chr1", START_POS, START_POS, Arrays.asList(A, C));
AG_SNP = new VariantContext("x", VCFConstants.EMPTY_ID_FIELD, "chr1", START_POS, START_POS, Arrays.asList(A, G));
AT_SNP = new VariantContext("x", VCFConstants.EMPTY_ID_FIELD, "chr1", START_POS, START_POS, Arrays.asList(A, T));
AC_SNP = new VariantContextBuilder("x", "chr1", START_POS, START_POS, Arrays.asList(A, C).make());
AG_SNP = new VariantContextBuilder("x", "chr1", START_POS, START_POS, Arrays.asList(A, G).make());
AT_SNP = new VariantContextBuilder("x", "chr1", START_POS, START_POS, Arrays.asList(A, T).make());
span10_10 = makeSpan(10, 10);
span1_20 = makeSpan(1, 20);
span10_20 = makeSpan(10, 20);

View File

@ -12,6 +12,7 @@ import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.Assert;
import java.lang.reflect.Array;
import java.util.*;
@ -39,6 +40,8 @@ public class VariantContextUnitTest extends BaseTest {
int mixedLocStart = 20;
int mixedLocStop = 23;
VariantContextBuilder basicBuilder, snpBuilder, insBuilder;
@BeforeSuite
public void before() {
del = Allele.create("-");
@ -52,6 +55,10 @@ public class VariantContextUnitTest extends BaseTest {
ATC = Allele.create("ATC");
ATCref = Allele.create("ATC", true);
basicBuilder = new VariantContextBuilder("test", snpLoc,snpLocStart, snpLocStop, Arrays.asList(Aref, T)).referenceBaseForIndel((byte)'A');
snpBuilder = new VariantContextBuilder("test", snpLoc,snpLocStart, snpLocStop, Arrays.asList(Aref, T)).referenceBaseForIndel((byte)'A');
insBuilder = new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Arrays.asList(delRef, ATC)).referenceBaseForIndel((byte)'A');
}
@Test
@ -68,68 +75,68 @@ public class VariantContextUnitTest extends BaseTest {
// test REF
List<Allele> alleles = Arrays.asList(Tref);
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
VariantContext vc = snpBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.NO_VARIATION);
// test SNPs
alleles = Arrays.asList(Tref, A);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
vc = snpBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.SNP);
alleles = Arrays.asList(Tref, A, C);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
vc = snpBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.SNP);
// test MNPs
alleles = Arrays.asList(ACref, TA);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles);
vc = snpBuilder.alleles(alleles).stop(snpLocStop+1).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.MNP);
alleles = Arrays.asList(ATCref, CAT, Allele.create("GGG"));
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles);
vc = basicBuilder.alleles(alleles).stop(snpLocStop+2).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.MNP);
// test INDELs
alleles = Arrays.asList(Aref, ATC);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
alleles = Arrays.asList(ATCref, A);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+2).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
alleles = Arrays.asList(Tref, TA, TC);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
alleles = Arrays.asList(ATCref, A, AC);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+2).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
alleles = Arrays.asList(ATCref, A, Allele.create("ATCTC"));
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+2, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+2).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.INDEL);
// test MIXED
alleles = Arrays.asList(TAref, T, TC);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+1).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
alleles = Arrays.asList(TAref, T, AC);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+1).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
alleles = Arrays.asList(ACref, ATC, AT);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop+1, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+1).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
alleles = Arrays.asList(Aref, T, symbolic);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.MIXED);
// test SYMBOLIC
alleles = Arrays.asList(Tref, symbolic);
vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
vc = basicBuilder.alleles(alleles).stop(snpLocStop+2).make();
Assert.assertEquals(vc.getType(), VariantContext.Type.SYMBOLIC);
}
@ -137,8 +144,8 @@ public class VariantContextUnitTest extends BaseTest {
public void testMultipleSNPAlleleOrdering() {
final List<Allele> allelesNaturalOrder = Arrays.asList(Aref, C, T);
final List<Allele> allelesUnnaturalOrder = Arrays.asList(Aref, T, C);
VariantContext naturalVC = new VariantContext("natural", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, allelesNaturalOrder);
VariantContext unnaturalVC = new VariantContext("unnatural", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, allelesUnnaturalOrder);
VariantContext naturalVC = snpBuilder.alleles(allelesNaturalOrder).make();
VariantContext unnaturalVC = snpBuilder.alleles(allelesUnnaturalOrder).make();
Assert.assertEquals(new ArrayList<Allele>(naturalVC.getAlleles()), allelesNaturalOrder);
Assert.assertEquals(new ArrayList<Allele>(unnaturalVC.getAlleles()), allelesUnnaturalOrder);
}
@ -147,7 +154,7 @@ public class VariantContextUnitTest extends BaseTest {
public void testCreatingSNPVariantContext() {
List<Allele> alleles = Arrays.asList(Aref, T);
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
VariantContext vc = snpBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getChr(), snpLoc);
Assert.assertEquals(vc.getStart(), snpLocStart);
@ -174,7 +181,7 @@ public class VariantContextUnitTest extends BaseTest {
@Test
public void testCreatingRefVariantContext() {
List<Allele> alleles = Arrays.asList(Aref);
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc,snpLocStart, snpLocStop, alleles);
VariantContext vc = snpBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getChr(), snpLoc);
Assert.assertEquals(vc.getStart(), snpLocStart);
@ -200,7 +207,7 @@ public class VariantContextUnitTest extends BaseTest {
@Test
public void testCreatingDeletionVariantContext() {
List<Allele> alleles = Arrays.asList(ATCref, del);
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, delLoc, delLocStart, delLocStop, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
VariantContext vc = new VariantContextBuilder("test", delLoc, delLocStart, delLocStop, alleles).referenceBaseForIndel((byte)'A').make();
Assert.assertEquals(vc.getChr(), delLoc);
Assert.assertEquals(vc.getStart(), delLocStart);
@ -227,7 +234,7 @@ public class VariantContextUnitTest extends BaseTest {
@Test
public void testCreatingInsertionVariantContext() {
List<Allele> alleles = Arrays.asList(delRef, ATC);
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
VariantContext vc = insBuilder.alleles(alleles).make();
Assert.assertEquals(vc.getChr(), insLoc);
Assert.assertEquals(vc.getStart(), insLocStart);
@ -275,48 +282,48 @@ public class VariantContextUnitTest extends BaseTest {
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadConstructorArgs1() {
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(delRef, ATCref));
new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Arrays.asList(delRef, ATCref)).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadConstructorArgs2() {
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(delRef, del));
new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Arrays.asList(delRef, del)).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadConstructorArgs3() {
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(del));
new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Arrays.asList(del)).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadConstructorArgs4() {
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Collections.<Allele>emptyList());
new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Collections.<Allele>emptyList()).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadConstructorArgsDuplicateAlleles1() {
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(Aref, T, T));
new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Arrays.asList(Aref, T, T)).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadConstructorArgsDuplicateAlleles2() {
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, insLoc, insLocStart, insLocStop, Arrays.asList(Aref, A));
new VariantContextBuilder("test", insLoc, insLocStart, insLocStop, Arrays.asList(Aref, A)).make();
}
@Test (expectedExceptions = IllegalStateException.class)
public void testBadLoc1() {
List<Allele> alleles = Arrays.asList(Aref, T, del);
new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, delLoc, delLocStart, delLocStop, alleles);
new VariantContextBuilder("test", delLoc, delLocStart, delLocStop, alleles).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadID1() {
new VariantContext("test", null, delLoc, delLocStart, delLocStop, Arrays.asList(Aref, T));
new VariantContextBuilder("test", delLoc, delLocStart, delLocStop, Arrays.asList(Aref, T)).id(null).make();
}
@Test (expectedExceptions = IllegalArgumentException.class)
public void testBadID2() {
new VariantContext("test", "", delLoc, delLocStart, delLocStop, Arrays.asList(Aref, T));
new VariantContextBuilder("test", delLoc, delLocStart, delLocStop, Arrays.asList(Aref, T)).id("");
}
@Test
@ -550,7 +557,7 @@ public class VariantContextUnitTest extends BaseTest {
@Test(dataProvider = "getAlleles")
public void testMergeAlleles(GetAllelesTest cfg) {
final List<Allele> altAlleles = cfg.alleles.subList(1, cfg.alleles.size());
final VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc, snpLocStart, snpLocStop, cfg.alleles, null, CommonInfo.NO_LOG10_PERROR, null, null, (byte)'A');
final VariantContext vc = snpBuilder.alleles(cfg.alleles).make();
Assert.assertEquals(vc.getAlleles(), cfg.alleles, "VC alleles not the same as input alleles");
Assert.assertEquals(vc.getNAlleles(), cfg.alleles.size(), "VC getNAlleles not the same as input alleles size");

View File

@ -99,8 +99,7 @@ public class VariantContextUtilsUnitTest extends BaseTest {
private VariantContext makeVC(String source, List<Allele> alleles, Collection<Genotype> genotypes, Set<String> filters) {
int start = 10;
int stop = start; // alleles.contains(ATC) ? start + 3 : start;
return new VariantContext(source, VCFConstants.EMPTY_ID_FIELD, "1", start, stop, alleles,
GenotypesContext.copy(genotypes), 1.0, filters, null, Cref.getBases()[0]);
return new VariantContextBuilder(source, "1", start, stop, alleles).genotypes(genotypes).filters(filters).referenceBaseForIndel(Cref.getBases()[0]).make();
}
// --------------------------------------------------------------------------------

View File

@ -144,7 +144,7 @@ public class VariantJEXLContextUnitTest extends BaseTest {
private JEXLMap getVarContext() {
List<Allele> alleles = Arrays.asList(Aref, T);
VariantContext vc = new VariantContext("test", VCFConstants.EMPTY_ID_FIELD, snpLoc.getContig(), snpLoc.getStart(), snpLoc.getStop(), alleles);
VariantContext vc = new VariantContextBuilder("test", snpLoc.getContig(), snpLoc.getStart(), snpLoc.getStop(), alleles).make();
return new JEXLMap(Arrays.asList(exp),vc);
}