clean up, add final

This commit is contained in:
Ron Levine 2015-01-04 23:01:24 -05:00
parent 85dc703461
commit c6840124fe
2 changed files with 35 additions and 30 deletions

View File

@ -68,7 +68,7 @@ import java.util.*;
class PhasingUtils { class PhasingUtils {
/** /**
* Merge variants into an MNP * Merge variants into a multi-nucleotide polymorphism (MNP)
* *
* @param genomeLocParser parse the genome locations * @param genomeLocParser parse the genome locations
* @param vc1 variant context 1 * @param vc1 variant context 1
@ -160,7 +160,7 @@ class PhasingUtils {
} }
/** /**
* Merge variants into an MNP * Merge variants into a multi-nucleotide polymorphism (MNP)
* *
* @param vc1 variant context 1 * @param vc1 variant context 1
* @param vc2 variant context 2 * @param vc2 variant context 2
@ -245,23 +245,23 @@ class PhasingUtils {
} }
/** /**
* Merge two variant context names together with an underscore betwwen them * Merge variant context names
* *
* @param name1 variant context 1 name * @param name1 variant context 1 name
* @param name2 variant context 2 name * @param name2 variant context 2 name
* @return combined variant names * @return merged variant names (name1_name2)
*/ */
static String mergeVariantContextNames(String name1, String name2) { static String mergeVariantContextNames(String name1, String name2) {
return name1 + "_" + name2; return name1 + "_" + name2;
} }
/** /**
* Get preset attributes and whether they are in vc1 or vc2 * Get preset attributes and that are in vc1 or vc2
* TODO: Will always return an empty map because MERGE_OR_ATTRIBS is empty * TODO: Will always return an empty map because MERGE_OR_ATTRIBS is empty
* *
* @param vc1 variant context 1 * @param vc1 variant context 1
* @param vc2 variant context 2 * @param vc2 variant context 2
* @return whether the preset attributes are in vc1 or vc2 * @return merged attributes in vc1 or vc2
*/ */
static Map<String, Object> mergeVariantContextAttributes(VariantContext vc1, VariantContext vc2) { static Map<String, Object> mergeVariantContextAttributes(VariantContext vc1, VariantContext vc2) {
// Map of attribute name to value // Map of attribute name to value
@ -289,7 +289,7 @@ class PhasingUtils {
} }
/** /**
* Check if variants can be merged into the MNP * Check if variants can be merged into the multi-nucleotide polymorphism (MNP)
* *
* @param genomeLocParser parse the genome locations * @param genomeLocParser parse the genome locations
* @param vc1 variant context 1 * @param vc1 variant context 1
@ -340,7 +340,7 @@ class PhasingUtils {
} }
/** /**
* Check if can merge variants * Check if can merge genotypes from the same sample
* *
* @param vc1 variant context 1 * @param vc1 variant context 1
* @param vc2 variant context 2 * @param vc2 variant context 2
@ -423,7 +423,7 @@ class PhasingUtils {
} }
/** /**
* Check that Alleles at vc1 and at vc2 always segregate together in all samples (including reference) * Check that alleles at vc1 and at vc2 always segregate together in all samples (including reference)
* *
* @param vc1 variant context 1 * @param vc1 variant context 1
* @param vc2 variant context 2 * @param vc2 variant context 2
@ -464,7 +464,7 @@ class PhasingUtils {
} }
/** /**
* Class for rule for merging variants * Class for variants merging rules
*/ */
abstract static class AlleleMergeRule { abstract static class AlleleMergeRule {
// vc1, vc2 are ONLY passed to allelesShouldBeMerged() if mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2) AND allSamplesAreMergeable(vc1, vc2): // vc1, vc2 are ONLY passed to allelesShouldBeMerged() if mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2) AND allSamplesAreMergeable(vc1, vc2):
@ -537,11 +537,16 @@ class PhasingUtils {
} }
/** /**
* Class for merging alleles data * Class for merging alleles
*/ */
static class MergedAllelesData { static class MergedAllelesData {
/// merged alleles
private Map<AlleleOneAndTwo, Allele> mergedAlleles; private Map<AlleleOneAndTwo, Allele> mergedAlleles;
/// bases between the alleles
private byte[] intermediateBases; private byte[] intermediateBases;
/// number of bases between the alleles
private int intermediateLength; private int intermediateLength;
/** /**
@ -573,7 +578,7 @@ class PhasingUtils {
/** /**
* Ensure that the alleles are merged. * Ensure that the alleles are merged.
* Put the bases from all1 before and all2 after the intermediate bases * all1 is before all2, if there is a gap between them, join with the intermediate bases
* *
* @param all1 allele 1 * @param all1 allele 1
* @param all2 allele 2 * @param all2 allele 2

View File

@ -135,9 +135,9 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test @Test
public void TestMergeIntoMNPvalidationCheckLocBefore() { public void TestMergeIntoMNPvalidationCheckLocBefore() {
final VariantContext vc1 = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList1).make(); final VariantContext vc1before = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList1).make();
final VariantContext vc2 = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start).stop(start).alleles(alleleList2).make(); final VariantContext vc2after = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start).stop(start).alleles(alleleList2).make();
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2)); Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1before, vc2after));
} }
@Test @Test
@ -200,8 +200,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test @Test
public void TestDoubleAllelesSegregatePerfectlyAmongSamples(){ public void TestDoubleAllelesSegregatePerfectlyAmongSamples(){
Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make(); final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make();
VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make();
Assert.assertTrue(PhasingUtils.doubleAllelesSegregatePerfectlyAmongSamples(vc1, vc)); Assert.assertTrue(PhasingUtils.doubleAllelesSegregatePerfectlyAmongSamples(vc1, vc));
} }
@ -213,11 +213,11 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test @Test
public void TestMergeIntoMNP(){ public void TestMergeIntoMNP(){
AlwaysTrueMergeRule alleleMergeRule = new AlwaysTrueMergeRule(); final AlwaysTrueMergeRule alleleMergeRule = new AlwaysTrueMergeRule();
VariantContext vc = PhasingUtils.mergeIntoMNP(genomeLocParser, vc1, vc2, referenceFile, alleleMergeRule); final VariantContext vc = PhasingUtils.mergeIntoMNP(genomeLocParser, vc1, vc2, referenceFile, alleleMergeRule);
List<Allele> alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false)); final List<Allele> alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false));
Map<String,Object> attributes = new HashMap<String,Object>(){{ final Map<String,Object> attributes = new HashMap<String,Object>(){{
put("AC", new ArrayList<Integer>(Arrays.asList(1, 1))); put("AC", new ArrayList<Integer>(Arrays.asList(1, 1)));
put("AF", new ArrayList<Double>(Arrays.asList(0.5, 0.5))); put("AF", new ArrayList<Double>(Arrays.asList(0.5, 0.5)));
put("AN", 2); put("AN", 2);
@ -225,8 +225,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
final Map<String, Object> extendedAttributes = new HashMap<String, Object>(){{ final Map<String, Object> extendedAttributes = new HashMap<String, Object>(){{
put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"}); put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"});
}}; }};
List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG")); final List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make(); final Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make();
final VariantContext vcExpected = new VariantContextBuilder().chr(contig).id("id1;id2").source("TC_GA").start(start).stop(start+1).alleles(alleleList).genotypes(genotype).attributes(attributes).make(); final VariantContext vcExpected = new VariantContextBuilder().chr(contig).id("id1;id2").source("TC_GA").start(start).stop(start+1).alleles(alleleList).genotypes(genotype).attributes(attributes).make();
Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample"))); Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample")));
Assert.assertTrue(vcExpected.hasSameAllelesAs(vc)); Assert.assertTrue(vcExpected.hasSameAllelesAs(vc));
@ -243,10 +243,10 @@ public class PhasingUtilsUnitTest extends BaseTest {
@Test @Test
public void TestReallyMergeIntoMNP( ){ public void TestReallyMergeIntoMNP( ){
VariantContext vc = PhasingUtils.reallyMergeIntoMNP(vc1, vc2, referenceFile); final VariantContext vc = PhasingUtils.reallyMergeIntoMNP(vc1, vc2, referenceFile);
List<Allele> alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false)); final List<Allele> alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false));
Map<String,Object> attributes = new HashMap<String,Object>(){{ final Map<String,Object> attributes = new HashMap<String,Object>(){{
put("AC", new ArrayList<Integer>(Arrays.asList(1, 1))); put("AC", new ArrayList<Integer>(Arrays.asList(1, 1)));
put("AF", new ArrayList<Double>(Arrays.asList(0.5, 0.5))); put("AF", new ArrayList<Double>(Arrays.asList(0.5, 0.5)));
put("AN", 2); put("AN", 2);
@ -254,8 +254,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
final Map<String, Object> extendedAttributes = new HashMap<String, Object>(){{ final Map<String, Object> extendedAttributes = new HashMap<String, Object>(){{
put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"}); put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"});
}}; }};
List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG")); final List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make(); final Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make();
final VariantContext vcExpected = new VariantContextBuilder().chr(contig).id("id1;id2").source("TC_GA").start(start).stop(start+1).alleles(alleleList).genotypes(genotype).attributes(attributes).make(); final VariantContext vcExpected = new VariantContextBuilder().chr(contig).id("id1;id2").source("TC_GA").start(start).stop(start+1).alleles(alleleList).genotypes(genotype).attributes(attributes).make();
Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample"))); Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample")));
Assert.assertTrue(vcExpected.hasSameAllelesAs(vc)); Assert.assertTrue(vcExpected.hasSameAllelesAs(vc));
@ -280,8 +280,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
public void TestEnsureMergedAllele(){ public void TestEnsureMergedAllele(){
byte[] intermediateBases = new byte[]{'A','T'}; byte[] intermediateBases = new byte[]{'A','T'};
final PhasingUtils.MergedAllelesData mergeData = new PhasingUtils.MergedAllelesData(intermediateBases, vc1, vc2); final PhasingUtils.MergedAllelesData mergeData = new PhasingUtils.MergedAllelesData(intermediateBases, vc1, vc2);
Allele allele = mergeData.ensureMergedAllele(Allele.create("T", true), Allele.create("C", true)); final Allele allele = mergeData.ensureMergedAllele(Allele.create("T", true), Allele.create("C", true));
Allele expectedAllele = Allele.create(new byte[]{'T', 'A', 'T', 'C'}, false); final Allele expectedAllele = Allele.create(new byte[]{'T', 'A', 'T', 'C'}, false);
Assert.assertEquals(allele, expectedAllele); Assert.assertEquals(allele, expectedAllele);
} }