Search in sources :

Example 1 with DetectedDisequilibriumElement

use of org.dash.valid.report.DetectedDisequilibriumElement in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLALinkageDisequilibrium method findLinkedPairs.

private static Set<HaplotypePair> findLinkedPairs(LinkageDisequilibriumGenotypeList glString, EnumSet<Locus> loci, List<DisequilibriumElement> disequilibriumElements, DetectedLinkageFindings findings) {
    Set<HaplotypePair> linkedPairs = new HaplotypePairSet(new HaplotypePairComparator());
    Set<MultiLocusHaplotype> linkedHaplotypes = new HashSet<MultiLocusHaplotype>();
    Set<DetectedDisequilibriumElement> detectedDisequilibriumElements = new HashSet<DetectedDisequilibriumElement>();
    MultiLocusHaplotype clonedHaplotype = null;
    for (MultiLocusHaplotype possibleHaplotype : glString.getPossibleHaplotypes(loci)) {
        List<DisequilibriumElement> shortenedList = new ArrayList<DisequilibriumElement>(disequilibriumElements);
        HashMap<Locus, List<String>> hlaElementMap = new HashMap<Locus, List<String>>();
        for (Locus locus : possibleHaplotype.getLoci()) {
            if (loci.contains(locus)) {
                hlaElementMap.put(locus, possibleHaplotype.getAlleles(locus));
            }
        }
        DisequilibriumElement element = new CoreDisequilibriumElement(hlaElementMap, possibleHaplotype);
        DetectedDisequilibriumElement detectedElement = null;
        while (shortenedList.contains(element)) {
            int index = shortenedList.indexOf(element);
            clonedHaplotype = new MultiLocusHaplotype(new ConcurrentHashMap<Locus, List<String>>(possibleHaplotype.getAlleleMap()), possibleHaplotype.getHaplotypeInstanceMap(), possibleHaplotype.getDrb345Homozygous());
            detectedElement = new DetectedDisequilibriumElement(shortenedList.get(index));
            detectedElement.setHaplotype(element.getHaplotype());
            clonedHaplotype.setLinkage(detectedElement);
            linkedHaplotypes.add(clonedHaplotype);
            detectedDisequilibriumElements.add(detectedElement);
            shortenedList = shortenedList.subList(index + 1, shortenedList.size());
        }
    }
    findings.addLinkages(detectedDisequilibriumElements);
    for (Haplotype haplotype1 : linkedHaplotypes) {
        for (Haplotype haplotype2 : linkedHaplotypes) {
            int idx = 0;
            for (Locus locus : loci) {
                if ((!glString.hasHomozygous(locus) && haplotype1.getHaplotypeInstance(locus) == haplotype2.getHaplotypeInstance(locus))) {
                    // move on to next haplotype2
                    break;
                }
                if (idx == loci.size() - 1) {
                    linkedPairs.add(new HaplotypePair(haplotype1, haplotype2));
                }
                idx++;
            }
        }
    }
    return linkedPairs;
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) ArrayList(java.util.ArrayList) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) ArrayList(java.util.ArrayList) LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) List(java.util.List) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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)

Example 2 with DetectedDisequilibriumElement

use of org.dash.valid.report.DetectedDisequilibriumElement in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class DisequilibriumElementComparatorTest method testComparisonByRace.

@Test
public void testComparisonByRace() {
    List<FrequencyByRace> frequenciesByRace = new ArrayList<FrequencyByRace>();
    FrequencyByRace freq = new FrequencyByRace(new Double(.2), "1", "AAFA");
    frequenciesByRace.add(freq);
    HashMap<Locus, List<String>> hlaElementMap = new HashMap<Locus, List<String>>();
    List<String> val = new ArrayList<String>();
    val.add("HLA-B*07:01");
    hlaElementMap.put(Locus.HLA_B, val);
    val = new ArrayList<String>();
    val.add("HLA-C*01:01");
    hlaElementMap.put(Locus.HLA_C, val);
    DisequilibriumElementByRace element1 = new DisequilibriumElementByRace(hlaElementMap, frequenciesByRace);
    frequenciesByRace = new ArrayList<FrequencyByRace>();
    freq = new FrequencyByRace(new Double(.3), "2", "CAU");
    frequenciesByRace.add(freq);
    freq = new FrequencyByRace(new Double(.4), "3", "API");
    frequenciesByRace.add(freq);
    hlaElementMap = new HashMap<Locus, List<String>>();
    val = new ArrayList<String>();
    val.add("HLA-B*52:01");
    hlaElementMap.put(Locus.HLA_B, val);
    val = new ArrayList<String>();
    val.add("HLA-C*04:01");
    hlaElementMap.put(Locus.HLA_C, val);
    DisequilibriumElementByRace element2 = new DisequilibriumElementByRace(hlaElementMap, frequenciesByRace);
    DisequilibriumElementComparator comparator = new DisequilibriumElementComparator();
    assertTrue(comparator.compare(new DetectedDisequilibriumElement(element1), new DetectedDisequilibriumElement(element2)) > 0);
}
Also used : DisequilibriumElementComparator(org.dash.valid.DisequilibriumElementComparator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DisequilibriumElementByRace(org.dash.valid.race.DisequilibriumElementByRace) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) List(java.util.List) ArrayList(java.util.ArrayList) Locus(org.dash.valid.Locus) FrequencyByRace(org.dash.valid.race.FrequencyByRace) Test(org.junit.Test)

Example 3 with DetectedDisequilibriumElement

use of org.dash.valid.report.DetectedDisequilibriumElement in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLALinkageDisequilibrium method enrichHaplotype.

public static Haplotype enrichHaplotype(EnumSet<Locus> loci, List<DisequilibriumElement> disequilibriumElements, Haplotype haplotype) {
    MultiLocusHaplotype enrichedHaplotype = new MultiLocusHaplotype(new ConcurrentHashMap<Locus, List<String>>(haplotype.getAlleleMap()), new HashMap<Locus, Integer>(haplotype.getHaplotypeInstanceMap()), haplotype.getDrb345Homozygous());
    HashMap<Locus, List<String>> hlaElementMap = new HashMap<Locus, List<String>>();
    List<DisequilibriumElement> shortenedList = new ArrayList<DisequilibriumElement>(disequilibriumElements);
    for (Locus locus : enrichedHaplotype.getLoci()) {
        if (loci.contains(locus)) {
            hlaElementMap.put(locus, enrichedHaplotype.getAlleles(locus));
        } else {
            enrichedHaplotype.removeAlleles(locus);
        }
    }
    DisequilibriumElement element = new CoreDisequilibriumElement(hlaElementMap, enrichedHaplotype);
    DetectedDisequilibriumElement detectedElement = null;
    while (shortenedList.contains(element)) {
        int index = shortenedList.indexOf(element);
        detectedElement = new DetectedDisequilibriumElement(shortenedList.get(index));
        detectedElement.setHaplotype(element.getHaplotype());
        enrichedHaplotype.setLinkage(detectedElement);
        shortenedList = shortenedList.subList(index + 1, shortenedList.size());
    }
    enrichedHaplotype.setSequence(haplotype.getSequence());
    return enrichedHaplotype;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) ArrayList(java.util.ArrayList) LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) List(java.util.List) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype)

Example 4 with DetectedDisequilibriumElement

use of org.dash.valid.report.DetectedDisequilibriumElement in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class DisequilibriumElementComparatorTest method testBaseComparison.

@Test
public void testBaseComparison() {
    HashMap<Locus, List<String>> hlaElementMap = new HashMap<Locus, List<String>>();
    List<String> val = new ArrayList<String>();
    val.add("HLA-B*52:01");
    hlaElementMap.put(Locus.HLA_B, val);
    val = new ArrayList<String>();
    val.add("HLA-C*04:01");
    hlaElementMap.put(Locus.HLA_C, val);
    BaseDisequilibriumElement element1 = new BaseDisequilibriumElement(hlaElementMap, "1", "Some note");
    hlaElementMap = new HashMap<Locus, List<String>>();
    val = new ArrayList<String>();
    val.add("HLA-B*07:01");
    hlaElementMap.put(Locus.HLA_B, val);
    val = new ArrayList<String>();
    val.add("HLA-C*01:01");
    hlaElementMap.put(Locus.HLA_C, val);
    BaseDisequilibriumElement element2 = new BaseDisequilibriumElement(hlaElementMap, "2", "Another note");
    DisequilibriumElementComparator comparator = new DisequilibriumElementComparator();
    assertTrue(comparator.compare(new DetectedDisequilibriumElement(element1), new DetectedDisequilibriumElement(element2)) > 0);
}
Also used : DisequilibriumElementComparator(org.dash.valid.DisequilibriumElementComparator) HashMap(java.util.HashMap) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) ArrayList(java.util.ArrayList) BaseDisequilibriumElement(org.dash.valid.base.BaseDisequilibriumElement) List(java.util.List) ArrayList(java.util.ArrayList) Locus(org.dash.valid.Locus) Test(org.junit.Test)

Example 5 with DetectedDisequilibriumElement

use of org.dash.valid.report.DetectedDisequilibriumElement in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class LinkageElementsMapTest method test.

@Test
public void test() {
    List<FrequencyByRace> frequenciesByRace = new ArrayList<FrequencyByRace>();
    FrequencyByRace freq = new FrequencyByRace(new Double(.2), "1", "AAFA");
    frequenciesByRace.add(freq);
    HashMap<Locus, List<String>> hlaElementMap = new HashMap<Locus, List<String>>();
    List<String> val = new ArrayList<String>();
    val.add("HLA-B*07:01");
    hlaElementMap.put(Locus.HLA_B, val);
    val = new ArrayList<String>();
    val.add("HLA-C*01:01");
    hlaElementMap.put(Locus.HLA_C, val);
    DisequilibriumElementByRace element1 = new DisequilibriumElementByRace(hlaElementMap, frequenciesByRace);
    frequenciesByRace = new ArrayList<FrequencyByRace>();
    freq = new FrequencyByRace(new Double(.3), "2", "CAU");
    frequenciesByRace.add(freq);
    freq = new FrequencyByRace(new Double(.4), "3", "API");
    frequenciesByRace.add(freq);
    hlaElementMap = new HashMap<Locus, List<String>>();
    val = new ArrayList<String>();
    val.add("HLA-B*52:01");
    hlaElementMap.put(Locus.HLA_B, val);
    val = new ArrayList<String>();
    val.add("HLA-C*04:01");
    hlaElementMap.put(Locus.HLA_C, val);
    DisequilibriumElementByRace element2 = new DisequilibriumElementByRace(hlaElementMap, frequenciesByRace);
    Set<DetectedDisequilibriumElement> set = new LinkageElementsSet(new DisequilibriumElementComparator());
    set.add(new DetectedDisequilibriumElement(element1));
    set.add(new DetectedDisequilibriumElement(element2));
    int idx = 0;
    for (DetectedDisequilibriumElement obj : set) {
        if (idx == 0) {
            assertTrue(obj.getDisequilibriumElement().equals(element2));
        } else {
            assertTrue(obj.getDisequilibriumElement().equals(element1));
        }
        idx++;
    }
}
Also used : DisequilibriumElementComparator(org.dash.valid.DisequilibriumElementComparator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DisequilibriumElementByRace(org.dash.valid.race.DisequilibriumElementByRace) LinkageElementsSet(org.dash.valid.LinkageElementsSet) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) List(java.util.List) ArrayList(java.util.ArrayList) Locus(org.dash.valid.Locus) FrequencyByRace(org.dash.valid.race.FrequencyByRace) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)5 DisequilibriumElementComparator (org.dash.valid.DisequilibriumElementComparator)3 Locus (org.dash.valid.Locus)3 Test (org.junit.Test)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 LinkageDisequilibriumGenotypeList (org.dash.valid.gl.LinkageDisequilibriumGenotypeList)2 MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)2 DisequilibriumElementByRace (org.dash.valid.race.DisequilibriumElementByRace)2 FrequencyByRace (org.dash.valid.race.FrequencyByRace)2 HashSet (java.util.HashSet)1 LinkageElementsSet (org.dash.valid.LinkageElementsSet)1 BaseDisequilibriumElement (org.dash.valid.base.BaseDisequilibriumElement)1 Haplotype (org.dash.valid.gl.haplo.Haplotype)1 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)1 HaplotypePairComparator (org.dash.valid.gl.haplo.HaplotypePairComparator)1 HaplotypePairSet (org.dash.valid.gl.haplo.HaplotypePairSet)1