Merged bug fix from Stable into Unstable
This commit is contained in:
commit
a733723439
|
|
@ -744,62 +744,67 @@ public class PhaseByTransmission extends RodWalker<HashMap<Byte,Integer>, HashMa
|
||||||
|
|
||||||
String mvfLine;
|
String mvfLine;
|
||||||
|
|
||||||
if (tracker != null) {
|
if (tracker == null)
|
||||||
VariantContext vc = tracker.getFirstValue(variantCollection.variants, context.getLocation());
|
return metricsCounters;
|
||||||
VariantContextBuilder builder = new VariantContextBuilder(vc);
|
|
||||||
|
|
||||||
GenotypesContext genotypesContext = GenotypesContext.copy(vc.getGenotypes());
|
final VariantContext vc = tracker.getFirstValue(variantCollection.variants, context.getLocation());
|
||||||
for (Sample sample : trios) {
|
if (vc == null)
|
||||||
Genotype mother = vc.getGenotype(sample.getMaternalID());
|
return metricsCounters;
|
||||||
Genotype father = vc.getGenotype(sample.getPaternalID());
|
|
||||||
Genotype child = vc.getGenotype(sample.getID());
|
|
||||||
|
|
||||||
//Keep only trios and parent/child pairs
|
final VariantContextBuilder builder = new VariantContextBuilder(vc);
|
||||||
if(mother == null && father == null || child == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ArrayList<Genotype> trioGenotypes = new ArrayList<Genotype>(3);
|
final GenotypesContext genotypesContext = GenotypesContext.copy(vc.getGenotypes());
|
||||||
final int mvCount = phaseTrioGenotypes(vc.getReference(), vc.getAltAlleleWithHighestAlleleCount(), mother, father, child,trioGenotypes);
|
for (Sample sample : trios) {
|
||||||
|
Genotype mother = vc.getGenotype(sample.getMaternalID());
|
||||||
|
Genotype father = vc.getGenotype(sample.getPaternalID());
|
||||||
|
Genotype child = vc.getGenotype(sample.getID());
|
||||||
|
|
||||||
Genotype phasedMother = trioGenotypes.get(0);
|
//Keep only trios and parent/child pairs
|
||||||
Genotype phasedFather = trioGenotypes.get(1);
|
if(mother == null && father == null || child == null)
|
||||||
Genotype phasedChild = trioGenotypes.get(2);
|
continue;
|
||||||
|
|
||||||
//Fill the genotype map with the new genotypes and increment metrics counters
|
ArrayList<Genotype> trioGenotypes = new ArrayList<Genotype>(3);
|
||||||
genotypesContext.replace(phasedChild);
|
final int mvCount = phaseTrioGenotypes(vc.getReference(), vc.getAltAlleleWithHighestAlleleCount(), mother, father, child,trioGenotypes);
|
||||||
if(mother != null){
|
|
||||||
genotypesContext.replace(phasedMother);
|
Genotype phasedMother = trioGenotypes.get(0);
|
||||||
if(father != null){
|
Genotype phasedFather = trioGenotypes.get(1);
|
||||||
genotypesContext.replace(phasedFather);
|
Genotype phasedChild = trioGenotypes.get(2);
|
||||||
updateTrioMetricsCounters(phasedMother,phasedFather,phasedChild,mvCount,metricsCounters);
|
|
||||||
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t%s:%s:%s:%s\t%s:%s:%s:%s\t%s:%s:%s:%s",vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),phasedMother.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getAttribute(VCFConstants.DEPTH_KEY),phasedMother.getAttribute("AD"),phasedMother.getLikelihoods().toString(),phasedFather.getGenotypeString(),phasedFather.getAttribute(VCFConstants.DEPTH_KEY),phasedFather.getAttribute("AD"),phasedFather.getLikelihoods().toString(),phasedChild.getGenotypeString(),phasedChild.getAttribute(VCFConstants.DEPTH_KEY),phasedChild.getAttribute("AD"),phasedChild.getLikelihoods().toString());
|
//Fill the genotype map with the new genotypes and increment metrics counters
|
||||||
if(!(phasedMother.getType()==mother.getType() && phasedFather.getType()==father.getType() && phasedChild.getType()==child.getType()))
|
genotypesContext.replace(phasedChild);
|
||||||
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
if(mother != null){
|
||||||
}
|
genotypesContext.replace(phasedMother);
|
||||||
else{
|
if(father != null){
|
||||||
updatePairMetricsCounters(phasedMother,phasedChild,mvCount,metricsCounters);
|
genotypesContext.replace(phasedFather);
|
||||||
if(!(phasedMother.getType()==mother.getType() && phasedChild.getType()==child.getType()))
|
updateTrioMetricsCounters(phasedMother,phasedFather,phasedChild,mvCount,metricsCounters);
|
||||||
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t%s:%s:%s:%s\t%s:%s:%s:%s\t%s:%s:%s:%s",vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),phasedMother.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getAttribute(VCFConstants.DEPTH_KEY),phasedMother.getAttribute("AD"),phasedMother.getLikelihoods().toString(),phasedFather.getGenotypeString(),phasedFather.getAttribute(VCFConstants.DEPTH_KEY),phasedFather.getAttribute("AD"),phasedFather.getLikelihoods().toString(),phasedChild.getGenotypeString(),phasedChild.getAttribute(VCFConstants.DEPTH_KEY),phasedChild.getAttribute("AD"),phasedChild.getLikelihoods().toString());
|
||||||
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t%s:%s:%s:%s\t.:.:.:.\t%s:%s:%s:%s",vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),phasedMother.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getAttribute(VCFConstants.DEPTH_KEY),phasedMother.getAttribute("AD"),phasedMother.getLikelihoods().toString(),phasedChild.getGenotypeString(),phasedChild.getAttribute(VCFConstants.DEPTH_KEY),phasedChild.getAttribute("AD"),phasedChild.getLikelihoods().toString());
|
if(!(phasedMother.getType()==mother.getType() && phasedFather.getType()==father.getType() && phasedChild.getType()==child.getType()))
|
||||||
}
|
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
genotypesContext.replace(phasedFather);
|
updatePairMetricsCounters(phasedMother,phasedChild,mvCount,metricsCounters);
|
||||||
updatePairMetricsCounters(phasedFather,phasedChild,mvCount,metricsCounters);
|
if(!(phasedMother.getType()==mother.getType() && phasedChild.getType()==child.getType()))
|
||||||
if(!(phasedFather.getType()==father.getType() && phasedChild.getType()==child.getType()))
|
|
||||||
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
||||||
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t.:.:.:.\t%s:%s:%s:%s\t%s:%s:%s:%s",vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),phasedFather.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedFather.getGenotypeString(),phasedFather.getAttribute(VCFConstants.DEPTH_KEY),phasedFather.getAttribute("AD"),phasedFather.getLikelihoods().toString(),phasedChild.getGenotypeString(),phasedChild.getAttribute(VCFConstants.DEPTH_KEY),phasedChild.getAttribute("AD"),phasedChild.getLikelihoods().toString());
|
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t%s:%s:%s:%s\t.:.:.:.\t%s:%s:%s:%s",vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),phasedMother.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedMother.getGenotypeString(),phasedMother.getAttribute(VCFConstants.DEPTH_KEY),phasedMother.getAttribute("AD"),phasedMother.getLikelihoods().toString(),phasedChild.getGenotypeString(),phasedChild.getAttribute(VCFConstants.DEPTH_KEY),phasedChild.getAttribute("AD"),phasedChild.getLikelihoods().toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//Report violation if set so
|
else{
|
||||||
//TODO: ADAPT FOR PAIRS TOO!!
|
genotypesContext.replace(phasedFather);
|
||||||
if(mvCount>0 && mvFile != null)
|
updatePairMetricsCounters(phasedFather,phasedChild,mvCount,metricsCounters);
|
||||||
mvFile.println(mvfLine);
|
if(!(phasedFather.getType()==father.getType() && phasedChild.getType()==child.getType()))
|
||||||
|
metricsCounters.put(NUM_GENOTYPES_MODIFIED,metricsCounters.get(NUM_GENOTYPES_MODIFIED)+1);
|
||||||
|
mvfLine = String.format("%s\t%d\t%s\t%s\t%s\t%s\t.:.:.:.\t%s:%s:%s:%s\t%s:%s:%s:%s",vc.getChr(),vc.getStart(),vc.getFilters(),vc.getAttribute(VCFConstants.ALLELE_COUNT_KEY),sample.toString(),phasedFather.getAttribute(TRANSMISSION_PROBABILITY_TAG_NAME),phasedFather.getGenotypeString(),phasedFather.getAttribute(VCFConstants.DEPTH_KEY),phasedFather.getAttribute("AD"),phasedFather.getLikelihoods().toString(),phasedChild.getGenotypeString(),phasedChild.getAttribute(VCFConstants.DEPTH_KEY),phasedChild.getAttribute("AD"),phasedChild.getLikelihoods().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.genotypes(genotypesContext);
|
//Report violation if set so
|
||||||
vcfWriter.add(builder.make());
|
//TODO: ADAPT FOR PAIRS TOO!!
|
||||||
|
if(mvCount>0 && mvFile != null)
|
||||||
|
mvFile.println(mvfLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
builder.genotypes(genotypesContext);
|
||||||
|
vcfWriter.add(builder.make());
|
||||||
|
|
||||||
return metricsCounters;
|
return metricsCounters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue