use of org.dash.valid.Locus in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class LinkageDisequilibriumGenotypeListTest method testHaplotypePairs.
@Test
public void testHaplotypePairs() throws IOException {
LinkageDisequilibriumGenotypeList genotypeList = new LinkageDisequilibriumGenotypeList("HaplotypePairs", TEST_BC_PAIRS);
Set<Locus> loci = new HashSet<Locus>();
loci.add(Locus.HLA_B);
loci.add(Locus.HLA_C);
Set<MultiLocusHaplotype> possibleHaplotypes = genotypeList.constructPossibleHaplotypes(loci);
Set<HaplotypePair> linkedPairs = new HaplotypePairSet(new HaplotypePairComparator());
for (Haplotype haplotype1 : possibleHaplotypes) {
for (Haplotype haplotype2 : possibleHaplotypes) {
if ((!genotypeList.hasHomozygous(Locus.HLA_B) && haplotype1.getAlleles(Locus.HLA_B).containsAll(haplotype2.getAlleles(Locus.HLA_B))) || (!genotypeList.hasHomozygous(Locus.HLA_C) && haplotype1.getAlleles(Locus.HLA_C).containsAll(haplotype2.getAlleles(Locus.HLA_C)))) {
continue;
}
HaplotypePair haplotypePair = new HaplotypePair(haplotype1, haplotype2);
linkedPairs.add(haplotypePair);
}
}
for (HaplotypePair pair : linkedPairs) {
Haplotype haplotype1 = pair.getHaplotypes().get(0);
assertTrue(haplotype1 instanceof MultiLocusHaplotype);
Haplotype haplotype2 = pair.getHaplotypes().get(1);
assertTrue(haplotype2 instanceof MultiLocusHaplotype);
assertTrue((haplotype1.getAlleles(Locus.HLA_B).contains(B0704) && haplotype2.getAlleles(Locus.HLA_B).contains(B4403)) || (haplotype1.getAlleles(Locus.HLA_B).contains(B4403) && haplotype2.getAlleles(Locus.HLA_B).contains(B0704)));
assertTrue((haplotype1.getAlleles(Locus.HLA_C).contains(C0702) && haplotype2.getAlleles(Locus.HLA_C).contains(C1203)) || (haplotype1.getAlleles(Locus.HLA_C).contains(C1203) && haplotype2.getAlleles(Locus.HLA_C).contains(C0702)));
assertFalse(haplotype1.getAlleles(Locus.HLA_B).contains(B0704) && haplotype2.getAlleles(Locus.HLA_B).contains(B0704));
assertFalse(haplotype1.getAlleles(Locus.HLA_B).contains(B4403) && haplotype2.getAlleles(Locus.HLA_B).contains(B4403));
assertFalse(haplotype1.getAlleles(Locus.HLA_C).contains(C0702) && haplotype2.getAlleles(Locus.HLA_C).contains(C0702));
assertFalse(haplotype1.getAlleles(Locus.HLA_C).contains(C1203) && haplotype2.getAlleles(Locus.HLA_C).contains(C1203));
}
}
use of org.dash.valid.Locus in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class HaplotypePairWriter method formatDetectedLinkages.
public static String formatDetectedLinkages(DetectedLinkageFindings findings) {
StringBuffer sb = new StringBuffer("Id: " + findings.getGLId() + GLStringConstants.NEWLINE + "GL String: " + findings.getGLString());
sb.append(GLStringConstants.NEWLINE + GLStringConstants.NEWLINE + "HLA DB Version: " + findings.getHladb() + GLStringConstants.NEWLINE);
sb.append(GLStringConstants.NEWLINE + "Frequencies: " + findings.getFrequencies() + GLStringConstants.NEWLINE);
for (EnumSet<Locus> findingSought : findings.getFindingsSought()) {
if (findings.hasLinkedPairs(findingSought) && findings.getFirstPair(findingSought) != null) {
sb.append(GLStringConstants.NEWLINE + "First " + findingSought + " Haplotype pair:" + GLStringConstants.NEWLINE + findings.getFirstPair(findingSought));
} else {
sb.append(GLStringConstants.NEWLINE + "WARNING - No " + findingSought + " haplotype pairs detected." + GLStringConstants.NEWLINE);
}
}
for (HaplotypePair pair : findings.getLinkedPairs()) {
if (findings.getFirstPairs().contains(pair)) {
continue;
} else {
sb.append(GLStringConstants.NEWLINE + "Possible " + pair.getLoci() + " Haplotype Pair:" + GLStringConstants.NEWLINE);
}
sb.append(pair);
}
sb.append(GLStringConstants.NEWLINE + "***************************************" + GLStringConstants.NEWLINE);
return sb.toString();
}
use of org.dash.valid.Locus in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class MultiLocusHaplotype method getHaplotypeString.
@Override
public String getHaplotypeString() {
StringBuffer sb = new StringBuffer();
Set<Locus> keySet = getAlleleMap().keySet();
Set<Locus> loci = new LocusSet(new LocusComparator());
loci.addAll(keySet);
if (this.linkage != null) {
for (Locus locus : loci) {
// TODO: Make less clumsy to get rid of brackets?
if (linkage.getDisequilibriumElement().getHlaElement(locus).size() == 1) {
sb.append(linkage.getDisequilibriumElement().getHlaElement(locus).get(0));
} else {
sb.append(linkage.getDisequilibriumElement().getHlaElement(locus));
}
sb.append(GLStringConstants.GENE_PHASE_DELIMITER);
}
} else {
for (Locus locus : loci) {
sb.append(getAlleles(locus));
sb.append(GLStringConstants.GENE_DELIMITER);
}
}
return sb.substring(0, sb.length() - 1);
}
Aggregations