Search in sources :

Example 16 with Locus

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));
    }
}
Also used : LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) Locus(org.dash.valid.Locus) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype) HaplotypePairComparator(org.dash.valid.gl.haplo.HaplotypePairComparator) Haplotype(org.dash.valid.gl.haplo.Haplotype) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with Locus

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();
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) Locus(org.dash.valid.Locus)

Example 18 with Locus

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);
}
Also used : LocusSet(org.dash.valid.LocusSet) LocusComparator(org.dash.valid.LocusComparator) Locus(org.dash.valid.Locus)

Aggregations

Locus (org.dash.valid.Locus)18 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 List (java.util.List)8 HashSet (java.util.HashSet)5 DisequilibriumElement (org.dash.valid.DisequilibriumElement)4 BaseDisequilibriumElement (org.dash.valid.base.BaseDisequilibriumElement)4 MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)4 DisequilibriumElementByRace (org.dash.valid.race.DisequilibriumElementByRace)4 FrequencyByRace (org.dash.valid.race.FrequencyByRace)4 Test (org.junit.Test)4 BufferedReader (java.io.BufferedReader)3 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 DisequilibriumElementComparator (org.dash.valid.DisequilibriumElementComparator)3 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)3 SingleLocusHaplotype (org.dash.valid.gl.haplo.SingleLocusHaplotype)3 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)3 AlleleList (org.nmdp.gl.AlleleList)3 GenotypeList (org.nmdp.gl.GenotypeList)3