Indentation
This commit is contained in:
parent
62cff266d4
commit
81b163ff4d
|
|
@ -129,220 +129,220 @@ public class PhaseByTransmission extends RodWalker<HashMap<Byte,Integer>, HashMa
|
||||||
private EnumMap<FamilyMember,Genotype> trioPhasedGenotypes = new EnumMap<FamilyMember, Genotype>(FamilyMember.class);
|
private EnumMap<FamilyMember,Genotype> trioPhasedGenotypes = new EnumMap<FamilyMember, Genotype>(FamilyMember.class);
|
||||||
|
|
||||||
private ArrayList<Allele> getAlleles(Genotype.Type genotype){
|
private ArrayList<Allele> getAlleles(Genotype.Type genotype){
|
||||||
ArrayList<Allele> alleles = new ArrayList<Allele>(2);
|
ArrayList<Allele> alleles = new ArrayList<Allele>(2);
|
||||||
if(genotype == Genotype.Type.HOM_REF){
|
if(genotype == Genotype.Type.HOM_REF){
|
||||||
alleles.add(REF);
|
alleles.add(REF);
|
||||||
alleles.add(REF);
|
alleles.add(REF);
|
||||||
}
|
}
|
||||||
else if(genotype == Genotype.Type.HET){
|
else if(genotype == Genotype.Type.HET){
|
||||||
alleles.add(REF);
|
alleles.add(REF);
|
||||||
alleles.add(VAR);
|
alleles.add(VAR);
|
||||||
}
|
}
|
||||||
else if(genotype == Genotype.Type.HOM_VAR){
|
else if(genotype == Genotype.Type.HOM_VAR){
|
||||||
alleles.add(VAR);
|
alleles.add(VAR);
|
||||||
alleles.add(VAR);
|
alleles.add(VAR);
|
||||||
}
|
}
|
||||||
else if(genotype == Genotype.Type.NO_CALL){
|
else if(genotype == Genotype.Type.NO_CALL){
|
||||||
alleles.add(NO_CALL);
|
alleles.add(NO_CALL);
|
||||||
alleles.add(NO_CALL);
|
alleles.add(NO_CALL);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return alleles;
|
return alleles;
|
||||||
}
|
|
||||||
|
|
||||||
//Create a new Genotype based on information from a single individual
|
|
||||||
//Homozygous genotypes will be set as phased, heterozygous won't be
|
|
||||||
private void phaseSingleIndividualAlleles(Genotype.Type genotype, FamilyMember familyMember){
|
|
||||||
if(genotype == Genotype.Type.HOM_REF || genotype == Genotype.Type.HOM_VAR){
|
|
||||||
trioPhasedGenotypes.put(familyMember, new Genotype(DUMMY_NAME, getAlleles(genotype), Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
trioPhasedGenotypes.put(familyMember, new Genotype(DUMMY_NAME,getAlleles(genotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Find the phase for a parent/child pair
|
|
||||||
private void phasePairAlleles(Genotype.Type parentGenotype, Genotype.Type childGenotype, FamilyMember parent){
|
|
||||||
|
|
||||||
//Special case for Het/Het as it is ambiguous
|
|
||||||
if(parentGenotype == Genotype.Type.HET && childGenotype == Genotype.Type.HET){
|
|
||||||
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME, getAlleles(parentGenotype), Genotype.NO_NEG_LOG_10PERROR, null, null, false));
|
|
||||||
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,getAlleles(childGenotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Allele> parentAlleles = getAlleles(parentGenotype);
|
//Create a new Genotype based on information from a single individual
|
||||||
ArrayList<Allele> childAlleles = getAlleles(childGenotype);
|
//Homozygous genotypes will be set as phased, heterozygous won't be
|
||||||
ArrayList<Allele> parentPhasedAlleles = new ArrayList<Allele>(2);
|
private void phaseSingleIndividualAlleles(Genotype.Type genotype, FamilyMember familyMember){
|
||||||
ArrayList<Allele> childPhasedAlleles = new ArrayList<Allele>(2);
|
if(genotype == Genotype.Type.HOM_REF || genotype == Genotype.Type.HOM_VAR){
|
||||||
|
trioPhasedGenotypes.put(familyMember, new Genotype(DUMMY_NAME, getAlleles(genotype), Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
||||||
//If there is a possible phasing between the mother and child => phase
|
}
|
||||||
int childTransmittedAlleleIndex = childAlleles.indexOf(parentAlleles.get(0));
|
else
|
||||||
if(childTransmittedAlleleIndex > -1){
|
trioPhasedGenotypes.put(familyMember, new Genotype(DUMMY_NAME,getAlleles(genotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME, parentAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
|
||||||
childPhasedAlleles.add(childAlleles.remove(childTransmittedAlleleIndex));
|
|
||||||
childPhasedAlleles.add(childAlleles.get(0));
|
|
||||||
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME, childPhasedAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
|
||||||
}
|
}
|
||||||
else if((childTransmittedAlleleIndex = childAlleles.indexOf(parentAlleles.get(1))) > -1){
|
|
||||||
parentPhasedAlleles.add(parentAlleles.get(1));
|
|
||||||
parentPhasedAlleles.add(parentAlleles.get(0));
|
|
||||||
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME, parentPhasedAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
|
||||||
childPhasedAlleles.add(childAlleles.remove(childTransmittedAlleleIndex));
|
|
||||||
childPhasedAlleles.add(childAlleles.get(0));
|
|
||||||
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME, childPhasedAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
|
||||||
}
|
|
||||||
//This is a Mendelian Violation => Do not phase
|
|
||||||
else{
|
|
||||||
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME,getAlleles(parentGenotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
|
||||||
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,getAlleles(childGenotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Phases a family by transmission
|
//Find the phase for a parent/child pair
|
||||||
private void phaseFamilyAlleles(Genotype.Type mother, Genotype.Type father, Genotype.Type child){
|
private void phasePairAlleles(Genotype.Type parentGenotype, Genotype.Type childGenotype, FamilyMember parent){
|
||||||
|
|
||||||
Set<ArrayList<Allele>> possiblePhasedChildGenotypes = new HashSet<ArrayList<Allele>>();
|
//Special case for Het/Het as it is ambiguous
|
||||||
ArrayList<Allele> motherAlleles = getAlleles(mother);
|
if(parentGenotype == Genotype.Type.HET && childGenotype == Genotype.Type.HET){
|
||||||
ArrayList<Allele> fatherAlleles = getAlleles(father);
|
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME, getAlleles(parentGenotype), Genotype.NO_NEG_LOG_10PERROR, null, null, false));
|
||||||
ArrayList<Allele> childAlleles = getAlleles(child);
|
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,getAlleles(childGenotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
|
}
|
||||||
|
|
||||||
//Build all possible child genotypes for the given parent's genotypes
|
ArrayList<Allele> parentAlleles = getAlleles(parentGenotype);
|
||||||
for (Allele momAllele : motherAlleles) {
|
ArrayList<Allele> childAlleles = getAlleles(childGenotype);
|
||||||
for (Allele fatherAllele : fatherAlleles) {
|
ArrayList<Allele> parentPhasedAlleles = new ArrayList<Allele>(2);
|
||||||
ArrayList<Allele> possiblePhasedChildAlleles = new ArrayList<Allele>(2);
|
ArrayList<Allele> childPhasedAlleles = new ArrayList<Allele>(2);
|
||||||
possiblePhasedChildAlleles.add(momAllele);
|
|
||||||
possiblePhasedChildAlleles.add(fatherAllele);
|
//If there is a possible phasing between the mother and child => phase
|
||||||
possiblePhasedChildGenotypes.add(possiblePhasedChildAlleles);
|
int childTransmittedAlleleIndex = childAlleles.indexOf(parentAlleles.get(0));
|
||||||
|
if(childTransmittedAlleleIndex > -1){
|
||||||
|
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME, parentAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
||||||
|
childPhasedAlleles.add(childAlleles.remove(childTransmittedAlleleIndex));
|
||||||
|
childPhasedAlleles.add(childAlleles.get(0));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME, childPhasedAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
||||||
|
}
|
||||||
|
else if((childTransmittedAlleleIndex = childAlleles.indexOf(parentAlleles.get(1))) > -1){
|
||||||
|
parentPhasedAlleles.add(parentAlleles.get(1));
|
||||||
|
parentPhasedAlleles.add(parentAlleles.get(0));
|
||||||
|
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME, parentPhasedAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
||||||
|
childPhasedAlleles.add(childAlleles.remove(childTransmittedAlleleIndex));
|
||||||
|
childPhasedAlleles.add(childAlleles.get(0));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME, childPhasedAlleles, Genotype.NO_NEG_LOG_10PERROR, null, null, true));
|
||||||
|
}
|
||||||
|
//This is a Mendelian Violation => Do not phase
|
||||||
|
else{
|
||||||
|
trioPhasedGenotypes.put(parent, new Genotype(DUMMY_NAME,getAlleles(parentGenotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,getAlleles(childGenotype),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ArrayList<Allele> childPhasedAllelesAlleles : possiblePhasedChildGenotypes) {
|
//Phases a family by transmission
|
||||||
int firstAlleleIndex = childPhasedAllelesAlleles.indexOf(childAlleles.get(0));
|
private void phaseFamilyAlleles(Genotype.Type mother, Genotype.Type father, Genotype.Type child){
|
||||||
int secondAlleleIndex = childPhasedAllelesAlleles.lastIndexOf(childAlleles.get(1));
|
|
||||||
//If a possible combination has been found, create the genotypes
|
|
||||||
if (firstAlleleIndex != secondAlleleIndex && firstAlleleIndex > -1 && secondAlleleIndex > -1) {
|
|
||||||
//Create mother's genotype
|
|
||||||
ArrayList<Allele> motherPhasedAlleles = new ArrayList<Allele>(2);
|
|
||||||
motherPhasedAlleles.add(childPhasedAllelesAlleles.get(0));
|
|
||||||
if(motherAlleles.get(0) != motherPhasedAlleles.get(0))
|
|
||||||
motherPhasedAlleles.add(motherAlleles.get(0));
|
|
||||||
else
|
|
||||||
motherPhasedAlleles.add(motherAlleles.get(1));
|
|
||||||
trioPhasedGenotypes.put(FamilyMember.MOTHER, new Genotype(DUMMY_NAME,motherPhasedAlleles,Genotype.NO_NEG_LOG_10PERROR,null,null,true));
|
|
||||||
|
|
||||||
//Create father's genotype
|
Set<ArrayList<Allele>> possiblePhasedChildGenotypes = new HashSet<ArrayList<Allele>>();
|
||||||
ArrayList<Allele> fatherPhasedAlleles = new ArrayList<Allele>(2);
|
ArrayList<Allele> motherAlleles = getAlleles(mother);
|
||||||
fatherPhasedAlleles.add(childPhasedAllelesAlleles.get(1));
|
ArrayList<Allele> fatherAlleles = getAlleles(father);
|
||||||
if(fatherAlleles.get(0) != fatherPhasedAlleles.get(0))
|
ArrayList<Allele> childAlleles = getAlleles(child);
|
||||||
fatherPhasedAlleles.add(fatherAlleles.get(0));
|
|
||||||
else
|
|
||||||
fatherPhasedAlleles.add(fatherAlleles.get(1));
|
|
||||||
trioPhasedGenotypes.put(FamilyMember.FATHER, new Genotype(DUMMY_NAME,fatherPhasedAlleles,Genotype.NO_NEG_LOG_10PERROR,null,null,true));
|
|
||||||
|
|
||||||
//Create child's genotype
|
//Build all possible child genotypes for the given parent's genotypes
|
||||||
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,childPhasedAllelesAlleles,Genotype.NO_NEG_LOG_10PERROR,null,null,true));
|
for (Allele momAllele : motherAlleles) {
|
||||||
|
for (Allele fatherAllele : fatherAlleles) {
|
||||||
//Once a phased combination is found; exit
|
ArrayList<Allele> possiblePhasedChildAlleles = new ArrayList<Allele>(2);
|
||||||
return;
|
possiblePhasedChildAlleles.add(momAllele);
|
||||||
|
possiblePhasedChildAlleles.add(fatherAllele);
|
||||||
|
possiblePhasedChildGenotypes.add(possiblePhasedChildAlleles);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ArrayList<Allele> childPhasedAllelesAlleles : possiblePhasedChildGenotypes) {
|
||||||
|
int firstAlleleIndex = childPhasedAllelesAlleles.indexOf(childAlleles.get(0));
|
||||||
|
int secondAlleleIndex = childPhasedAllelesAlleles.lastIndexOf(childAlleles.get(1));
|
||||||
|
//If a possible combination has been found, create the genotypes
|
||||||
|
if (firstAlleleIndex != secondAlleleIndex && firstAlleleIndex > -1 && secondAlleleIndex > -1) {
|
||||||
|
//Create mother's genotype
|
||||||
|
ArrayList<Allele> motherPhasedAlleles = new ArrayList<Allele>(2);
|
||||||
|
motherPhasedAlleles.add(childPhasedAllelesAlleles.get(0));
|
||||||
|
if(motherAlleles.get(0) != motherPhasedAlleles.get(0))
|
||||||
|
motherPhasedAlleles.add(motherAlleles.get(0));
|
||||||
|
else
|
||||||
|
motherPhasedAlleles.add(motherAlleles.get(1));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.MOTHER, new Genotype(DUMMY_NAME,motherPhasedAlleles,Genotype.NO_NEG_LOG_10PERROR,null,null,true));
|
||||||
|
|
||||||
|
//Create father's genotype
|
||||||
|
ArrayList<Allele> fatherPhasedAlleles = new ArrayList<Allele>(2);
|
||||||
|
fatherPhasedAlleles.add(childPhasedAllelesAlleles.get(1));
|
||||||
|
if(fatherAlleles.get(0) != fatherPhasedAlleles.get(0))
|
||||||
|
fatherPhasedAlleles.add(fatherAlleles.get(0));
|
||||||
|
else
|
||||||
|
fatherPhasedAlleles.add(fatherAlleles.get(1));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.FATHER, new Genotype(DUMMY_NAME,fatherPhasedAlleles,Genotype.NO_NEG_LOG_10PERROR,null,null,true));
|
||||||
|
|
||||||
|
//Create child's genotype
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,childPhasedAllelesAlleles,Genotype.NO_NEG_LOG_10PERROR,null,null,true));
|
||||||
|
|
||||||
|
//Once a phased combination is found; exit
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//If this is reached then no phasing could be found
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.MOTHER, new Genotype(DUMMY_NAME,getAlleles(mother),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.FATHER, new Genotype(DUMMY_NAME,getAlleles(father),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
|
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,getAlleles(child),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
||||||
}
|
}
|
||||||
|
|
||||||
//If this is reached then no phasing could be found
|
/* Constructor: Creates a conceptual trio genotype combination from the given genotypes.
|
||||||
trioPhasedGenotypes.put(FamilyMember.MOTHER, new Genotype(DUMMY_NAME,getAlleles(mother),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
If one or more genotypes are set as NO_CALL or UNAVAILABLE, it will phase them like a pair
|
||||||
trioPhasedGenotypes.put(FamilyMember.FATHER, new Genotype(DUMMY_NAME,getAlleles(father),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
or single individual.
|
||||||
trioPhasedGenotypes.put(FamilyMember.CHILD, new Genotype(DUMMY_NAME,getAlleles(child),Genotype.NO_NEG_LOG_10PERROR,null,null,false));
|
*/
|
||||||
}
|
public TrioPhase(Genotype.Type mother, Genotype.Type father, Genotype.Type child){
|
||||||
|
|
||||||
/* Constructor: Creates a conceptual trio genotype combination from the given genotypes.
|
//Take care of cases where one or more family members are no call
|
||||||
If one or more genotypes are set as NO_CALL or UNAVAILABLE, it will phase them like a pair
|
if(child == Genotype.Type.NO_CALL || child == Genotype.Type.UNAVAILABLE){
|
||||||
or single individual.
|
phaseSingleIndividualAlleles(mother, FamilyMember.MOTHER);
|
||||||
*/
|
|
||||||
public TrioPhase(Genotype.Type mother, Genotype.Type father, Genotype.Type child){
|
|
||||||
|
|
||||||
//Take care of cases where one or more family members are no call
|
|
||||||
if(child == Genotype.Type.NO_CALL || child == Genotype.Type.UNAVAILABLE){
|
|
||||||
phaseSingleIndividualAlleles(mother, FamilyMember.MOTHER);
|
|
||||||
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
|
||||||
phaseSingleIndividualAlleles(child, FamilyMember.CHILD);
|
|
||||||
}
|
|
||||||
else if(mother == Genotype.Type.NO_CALL || mother == Genotype.Type.UNAVAILABLE){
|
|
||||||
phaseSingleIndividualAlleles(mother, FamilyMember.MOTHER);
|
|
||||||
if(father == Genotype.Type.NO_CALL || father == Genotype.Type.UNAVAILABLE){
|
|
||||||
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
||||||
phaseSingleIndividualAlleles(child, FamilyMember.CHILD);
|
phaseSingleIndividualAlleles(child, FamilyMember.CHILD);
|
||||||
}
|
}
|
||||||
else
|
else if(mother == Genotype.Type.NO_CALL || mother == Genotype.Type.UNAVAILABLE){
|
||||||
phasePairAlleles(father, child, FamilyMember.FATHER);
|
phaseSingleIndividualAlleles(mother, FamilyMember.MOTHER);
|
||||||
|
if(father == Genotype.Type.NO_CALL || father == Genotype.Type.UNAVAILABLE){
|
||||||
|
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
||||||
|
phaseSingleIndividualAlleles(child, FamilyMember.CHILD);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
phasePairAlleles(father, child, FamilyMember.FATHER);
|
||||||
|
}
|
||||||
|
else if(father == Genotype.Type.NO_CALL || father == Genotype.Type.UNAVAILABLE){
|
||||||
|
phasePairAlleles(mother, child, FamilyMember.MOTHER);
|
||||||
|
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
||||||
|
}
|
||||||
|
//Special case for Het/Het/Het as it is ambiguous
|
||||||
|
else if(mother == Genotype.Type.HET && father == Genotype.Type.HET && child == Genotype.Type.HET){
|
||||||
|
phaseSingleIndividualAlleles(mother, FamilyMember.MOTHER);
|
||||||
|
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
||||||
|
phaseSingleIndividualAlleles(child, FamilyMember.CHILD);
|
||||||
|
}
|
||||||
|
//All family members have genotypes and at least one of them is not Het
|
||||||
|
else{
|
||||||
|
phaseFamilyAlleles(mother, father, child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(father == Genotype.Type.NO_CALL || father == Genotype.Type.UNAVAILABLE){
|
|
||||||
phasePairAlleles(mother, child, FamilyMember.MOTHER);
|
/**
|
||||||
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
* Applies the trio genotype combination to the given trio.
|
||||||
|
* @param ref: Reference allele
|
||||||
|
* @param alt: Alternate allele
|
||||||
|
* @param motherGenotype: Genotype of the mother to phase using this trio genotype combination
|
||||||
|
* @param fatherGenotype: Genotype of the father to phase using this trio genotype combination
|
||||||
|
* @param childGenotype: Genotype of the child to phase using this trio genotype combination
|
||||||
|
* @param transmissionProb: Probability for this trio genotype combination to be correct (pass NO_TRANSMISSION_PROB if unavailable)
|
||||||
|
* @param phasedGenotypes: An ArrayList<Genotype> to which the newly phased genotypes are added in the following order: Mother, Father, Child
|
||||||
|
*/
|
||||||
|
public void getPhasedGenotypes(Allele ref, Allele alt, Genotype motherGenotype, Genotype fatherGenotype, Genotype childGenotype, double transmissionProb,ArrayList<Genotype> phasedGenotypes){
|
||||||
|
phasedGenotypes.add(getPhasedGenotype(ref,alt,motherGenotype,transmissionProb,this.trioPhasedGenotypes.get(FamilyMember.MOTHER)));
|
||||||
|
phasedGenotypes.add(getPhasedGenotype(ref,alt,fatherGenotype,transmissionProb,this.trioPhasedGenotypes.get(FamilyMember.FATHER)));
|
||||||
|
phasedGenotypes.add(getPhasedGenotype(ref,alt,childGenotype,transmissionProb,this.trioPhasedGenotypes.get(FamilyMember.CHILD)));
|
||||||
}
|
}
|
||||||
//Special case for Het/Het/Het as it is ambiguous
|
|
||||||
else if(mother == Genotype.Type.HET && father == Genotype.Type.HET && child == Genotype.Type.HET){
|
|
||||||
phaseSingleIndividualAlleles(mother, FamilyMember.MOTHER);
|
|
||||||
phaseSingleIndividualAlleles(father, FamilyMember.FATHER);
|
|
||||||
phaseSingleIndividualAlleles(child, FamilyMember.CHILD);
|
|
||||||
}
|
|
||||||
//All family members have genotypes and at least one of them is not Het
|
|
||||||
else{
|
|
||||||
phaseFamilyAlleles(mother, father, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
private Genotype getPhasedGenotype(Allele refAllele, Allele altAllele, Genotype genotype, double transmissionProb, Genotype phasedGenotype){
|
||||||
* Applies the trio genotype combination to the given trio.
|
|
||||||
* @param ref: Reference allele
|
|
||||||
* @param alt: Alternate allele
|
|
||||||
* @param motherGenotype: Genotype of the mother to phase using this trio genotype combination
|
|
||||||
* @param fatherGenotype: Genotype of the father to phase using this trio genotype combination
|
|
||||||
* @param childGenotype: Genotype of the child to phase using this trio genotype combination
|
|
||||||
* @param transmissionProb: Probability for this trio genotype combination to be correct (pass NO_TRANSMISSION_PROB if unavailable)
|
|
||||||
* @param phasedGenotypes: An ArrayList<Genotype> to which the newly phased genotypes are added in the following order: Mother, Father, Child
|
|
||||||
*/
|
|
||||||
public void getPhasedGenotypes(Allele ref, Allele alt, Genotype motherGenotype, Genotype fatherGenotype, Genotype childGenotype, double transmissionProb,ArrayList<Genotype> phasedGenotypes){
|
|
||||||
phasedGenotypes.add(getPhasedGenotype(ref,alt,motherGenotype,transmissionProb,this.trioPhasedGenotypes.get(FamilyMember.MOTHER)));
|
|
||||||
phasedGenotypes.add(getPhasedGenotype(ref,alt,fatherGenotype,transmissionProb,this.trioPhasedGenotypes.get(FamilyMember.FATHER)));
|
|
||||||
phasedGenotypes.add(getPhasedGenotype(ref,alt,childGenotype,transmissionProb,this.trioPhasedGenotypes.get(FamilyMember.CHILD)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Genotype getPhasedGenotype(Allele refAllele, Allele altAllele, Genotype genotype, double transmissionProb, Genotype phasedGenotype){
|
//Handle null, missing and unavailable genotypes
|
||||||
|
//Note that only cases where a null/missing/unavailable genotype was passed in the first place can lead to a null/missing/unavailable
|
||||||
|
//genotype so it is safe to return the original genotype in this case.
|
||||||
|
if(genotype == null || !phasedGenotype.isAvailable() || phasedGenotype.isNoCall())
|
||||||
|
return genotype;
|
||||||
|
|
||||||
//Handle null, missing and unavailable genotypes
|
//Add the transmission probability
|
||||||
//Note that only cases where a null/missing/unavailable genotype was passed in the first place can lead to a null/missing/unavailable
|
Map<String, Object> genotypeAttributes = new HashMap<String, Object>();
|
||||||
//genotype so it is safe to return the original genotype in this case.
|
genotypeAttributes.putAll(genotype.getAttributes());
|
||||||
if(genotype == null || !phasedGenotype.isAvailable() || phasedGenotype.isNoCall())
|
if(transmissionProb>NO_TRANSMISSION_PROB)
|
||||||
return genotype;
|
genotypeAttributes.put(TRANSMISSION_PROBABILITY_TAG_NAME, MathUtils.probabilityToPhredScale(1-(transmissionProb)));
|
||||||
|
|
||||||
//Add the transmission probability
|
ArrayList<Allele> phasedAlleles = new ArrayList<Allele>(2);
|
||||||
Map<String, Object> genotypeAttributes = new HashMap<String, Object>();
|
for(Allele allele : phasedGenotype.getAlleles()){
|
||||||
genotypeAttributes.putAll(genotype.getAttributes());
|
if(allele.isReference())
|
||||||
if(transmissionProb>NO_TRANSMISSION_PROB)
|
phasedAlleles.add(refAllele);
|
||||||
genotypeAttributes.put(TRANSMISSION_PROBABILITY_TAG_NAME, MathUtils.probabilityToPhredScale(1-(transmissionProb)));
|
else if(allele.isNonReference())
|
||||||
|
phasedAlleles.add(altAllele);
|
||||||
|
//At this point there should not be any other alleles left
|
||||||
|
else
|
||||||
|
throw new UserException(String.format("BUG: Unexpected allele: %s. Please report.",allele.toString()));
|
||||||
|
|
||||||
ArrayList<Allele> phasedAlleles = new ArrayList<Allele>(2);
|
}
|
||||||
for(Allele allele : phasedGenotype.getAlleles()){
|
|
||||||
if(allele.isReference())
|
//Compute the new Log10Error if the genotype is different from the original genotype
|
||||||
phasedAlleles.add(refAllele);
|
double negLog10Error;
|
||||||
else if(allele.isNonReference())
|
if(genotype.getType() == phasedGenotype.getType())
|
||||||
phasedAlleles.add(altAllele);
|
negLog10Error = genotype.getNegLog10PError();
|
||||||
//At this point there should not be any other alleles left
|
|
||||||
else
|
else
|
||||||
throw new UserException(String.format("BUG: Unexpected allele: %s. Please report.",allele.toString()));
|
negLog10Error = genotype.getLikelihoods().getNegLog10GQ(phasedGenotype.getType());
|
||||||
|
|
||||||
|
return new Genotype(genotype.getSampleName(), phasedAlleles, negLog10Error, null, genotypeAttributes, phasedGenotype.isPhased());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Compute the new Log10Error if the genotype is different from the original genotype
|
|
||||||
double negLog10Error;
|
|
||||||
if(genotype.getType() == phasedGenotype.getType())
|
|
||||||
negLog10Error = genotype.getNegLog10PError();
|
|
||||||
else
|
|
||||||
negLog10Error = genotype.getLikelihoods().getNegLog10GQ(phasedGenotype.getType());
|
|
||||||
|
|
||||||
return new Genotype(genotype.getSampleName(), phasedAlleles, negLog10Error, null, genotypeAttributes, phasedGenotype.isPhased());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue