clean up, add final
This commit is contained in:
parent
85dc703461
commit
c6840124fe
|
|
@ -68,7 +68,7 @@ import java.util.*;
|
|||
class PhasingUtils {
|
||||
|
||||
/**
|
||||
* Merge variants into an MNP
|
||||
* Merge variants into a multi-nucleotide polymorphism (MNP)
|
||||
*
|
||||
* @param genomeLocParser parse the genome locations
|
||||
* @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 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 name2 variant context 2 name
|
||||
* @return combined variant names
|
||||
* @return merged variant names (name1_name2)
|
||||
*/
|
||||
static String mergeVariantContextNames(String name1, String 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
|
||||
*
|
||||
* @param vc1 variant context 1
|
||||
* @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) {
|
||||
// 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 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 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 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 {
|
||||
// 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 {
|
||||
/// merged alleles
|
||||
private Map<AlleleOneAndTwo, Allele> mergedAlleles;
|
||||
|
||||
/// bases between the alleles
|
||||
private byte[] intermediateBases;
|
||||
|
||||
/// number of bases between the alleles
|
||||
private int intermediateLength;
|
||||
|
||||
/**
|
||||
|
|
@ -573,7 +578,7 @@ class PhasingUtils {
|
|||
|
||||
/**
|
||||
* 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 all2 allele 2
|
||||
|
|
|
|||
|
|
@ -135,9 +135,9 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
|
||||
@Test
|
||||
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 vc2 = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start).stop(start).alleles(alleleList2).make();
|
||||
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1, vc2));
|
||||
final VariantContext vc1before = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start+1).stop(start+1).alleles(alleleList1).make();
|
||||
final VariantContext vc2after = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start).stop(start).alleles(alleleList2).make();
|
||||
Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc1before, vc2after));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -200,8 +200,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
|
||||
@Test
|
||||
public void TestDoubleAllelesSegregatePerfectlyAmongSamples(){
|
||||
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 Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).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));
|
||||
}
|
||||
|
||||
|
|
@ -213,11 +213,11 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
|
||||
@Test
|
||||
public void TestMergeIntoMNP(){
|
||||
AlwaysTrueMergeRule alleleMergeRule = new AlwaysTrueMergeRule();
|
||||
VariantContext vc = PhasingUtils.mergeIntoMNP(genomeLocParser, vc1, vc2, referenceFile, alleleMergeRule);
|
||||
final AlwaysTrueMergeRule alleleMergeRule = new AlwaysTrueMergeRule();
|
||||
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));
|
||||
Map<String,Object> attributes = new HashMap<String,Object>(){{
|
||||
final List<Allele> alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false));
|
||||
final Map<String,Object> attributes = new HashMap<String,Object>(){{
|
||||
put("AC", new ArrayList<Integer>(Arrays.asList(1, 1)));
|
||||
put("AF", new ArrayList<Double>(Arrays.asList(0.5, 0.5)));
|
||||
put("AN", 2);
|
||||
|
|
@ -225,8 +225,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
final Map<String, Object> extendedAttributes = new HashMap<String, Object>(){{
|
||||
put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"});
|
||||
}};
|
||||
List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
|
||||
Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make();
|
||||
final List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
|
||||
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();
|
||||
Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample")));
|
||||
Assert.assertTrue(vcExpected.hasSameAllelesAs(vc));
|
||||
|
|
@ -243,10 +243,10 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
|
||||
@Test
|
||||
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));
|
||||
Map<String,Object> attributes = new HashMap<String,Object>(){{
|
||||
final List<Allele> alleleList = Arrays.asList(Allele.create("TG", true), Allele.create("TA", false), Allele.create("CG", false));
|
||||
final Map<String,Object> attributes = new HashMap<String,Object>(){{
|
||||
put("AC", new ArrayList<Integer>(Arrays.asList(1, 1)));
|
||||
put("AF", new ArrayList<Double>(Arrays.asList(0.5, 0.5)));
|
||||
put("AN", 2);
|
||||
|
|
@ -254,8 +254,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
final Map<String, Object> extendedAttributes = new HashMap<String, Object>(){{
|
||||
put("PQ", 100.0); put("HP", new String[]{"10-1", "10-2"});
|
||||
}};
|
||||
List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
|
||||
Genotype genotype = new GenotypeBuilder().name("sample").attributes(extendedAttributes).alleles(alleleListMeged).make();
|
||||
final List<Allele> alleleListMeged = Arrays.asList(Allele.create("TA"), Allele.create("CG"));
|
||||
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();
|
||||
Assert.assertTrue(genotype.sameGenotype(vcExpected.getGenotypes().get("sample")));
|
||||
Assert.assertTrue(vcExpected.hasSameAllelesAs(vc));
|
||||
|
|
@ -280,8 +280,8 @@ public class PhasingUtilsUnitTest extends BaseTest {
|
|||
public void TestEnsureMergedAllele(){
|
||||
byte[] intermediateBases = new byte[]{'A','T'};
|
||||
final PhasingUtils.MergedAllelesData mergeData = new PhasingUtils.MergedAllelesData(intermediateBases, vc1, vc2);
|
||||
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 allele = mergeData.ensureMergedAllele(Allele.create("T", true), Allele.create("C", true));
|
||||
final Allele expectedAllele = Allele.create(new byte[]{'T', 'A', 'T', 'C'}, false);
|
||||
Assert.assertEquals(allele, expectedAllele);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue