Search in sources :

Example 1 with HaplotypePair

use of org.dash.valid.gl.haplo.HaplotypePair in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLALinkageDisequilibrium method hasLinkageDisequilibrium.

public static Sample hasLinkageDisequilibrium(LinkageDisequilibriumGenotypeList glString, List<Haplotype> knownHaplotypes) {
    Set<HaplotypePair> linkedPairs = new HaplotypePairSet(new HaplotypePairComparator());
    Set<String> notCommon = GLStringUtilities.checkCommonWellDocumented(glString.getGLString());
    Sample sample = new Sample(glString);
    DetectedLinkageFindings findings = new DetectedLinkageFindings(System.getProperty(Frequencies.FREQUENCIES_PROPERTY));
    Set<Linkages> linkages = LinkagesLoader.getInstance().getLinkages();
    if (linkages == null) {
        sample.setFindings(findings);
        return sample;
    }
    for (Linkages linkage : linkages) {
        EnumSet<Locus> loci = linkage.getLoci();
        findings.addFindingSought(loci);
        List<DisequilibriumElement> disequilibriumElements = HLAFrequenciesLoader.getInstance().getDisequilibriumElements(loci);
        List<Haplotype> enrichedHaplotypes = new ArrayList<Haplotype>();
        for (Haplotype haplotype : knownHaplotypes) {
            Haplotype enrichedHaplotype = enrichHaplotype(loci, disequilibriumElements, haplotype);
            if (enrichedHaplotype.getLinkage() != null) {
                findings.addLinkage(enrichedHaplotype.getLinkage());
                enrichedHaplotypes.add(enrichedHaplotype);
            }
        }
        if (enrichedHaplotypes.size() == 2) {
            linkedPairs.add(new HaplotypePair(enrichedHaplotypes.get(0), enrichedHaplotypes.get(1)));
        }
    }
    LOGGER.info(linkedPairs.size() + " linkedPairs");
    findings.setGenotypeList(glString);
    findings.setLinkedPairs(linkedPairs);
    findings.setNonCWDAlleles(notCommon);
    findings.setHladb(System.getProperty(GLStringConstants.HLADB_PROPERTY));
    sample.setFindings(findings);
    return sample;
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) ArrayList(java.util.ArrayList) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings) HaplotypePairComparator(org.dash.valid.gl.haplo.HaplotypePairComparator) Haplotype(org.dash.valid.gl.haplo.Haplotype) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype)

Example 2 with HaplotypePair

use of org.dash.valid.gl.haplo.HaplotypePair in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLALinkageDisequilibrium method hasLinkageDisequilibrium.

public static Sample hasLinkageDisequilibrium(LinkageDisequilibriumGenotypeList glString) {
    Sample sample = new Sample(glString);
    Set<HaplotypePair> linkedPairs = new HaplotypePairSet(new HaplotypePairComparator());
    Set<String> notCommon = GLStringUtilities.checkCommonWellDocumented(glString.getGLString());
    DetectedLinkageFindings findings = new DetectedLinkageFindings(System.getProperty(Frequencies.FREQUENCIES_PROPERTY));
    Set<Linkages> linkages = LinkagesLoader.getInstance().getLinkages();
    if (linkages == null) {
        sample.setFindings(findings);
        return sample;
    }
    for (Linkages linkage : linkages) {
        EnumSet<Locus> loci = linkage.getLoci();
        findings.addFindingSought(loci);
        List<DisequilibriumElement> disequilibriumElements = HLAFrequenciesLoader.getInstance().getDisequilibriumElements(loci);
        linkedPairs.addAll(findLinkedPairs(glString, loci, disequilibriumElements, findings));
    }
    LOGGER.info(linkedPairs.size() + " linkedPairs");
    findings.setGenotypeList(glString);
    findings.setLinkedPairs(linkedPairs);
    findings.setNonCWDAlleles(notCommon);
    findings.setHladb(System.getProperty(GLStringConstants.HLADB_PROPERTY));
    sample.setFindings(findings);
    return sample;
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) DetectedLinkageFindings(org.dash.valid.report.DetectedLinkageFindings) HaplotypePairComparator(org.dash.valid.gl.haplo.HaplotypePairComparator)

Example 3 with HaplotypePair

use of org.dash.valid.gl.haplo.HaplotypePair 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 4 with HaplotypePair

use of org.dash.valid.gl.haplo.HaplotypePair in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class DetectedLinkageFindings method setLinkedPairs.

public void setLinkedPairs(Set<HaplotypePair> linkedPairs) {
    EnumSet<Locus> loci = null;
    if (linkedPairs.iterator().hasNext() && linkedPairs.iterator().next().isByRace()) {
        HashMap<Set<Locus>, HashMap<String, Double>> raceTotalFreqsMap = new HashMap<Set<Locus>, HashMap<String, Double>>();
        Set<HaplotypePair> noRaceOverlapPairs = new HashSet<HaplotypePair>();
        RelativeFrequencyByRace relativeRaceFreq;
        String race;
        Double totalFreq;
        for (HaplotypePair pair : linkedPairs) {
            loci = Locus.lookup(pair.getLoci());
            if (pair.getPrimaryFrequency() == null) {
                noRaceOverlapPairs.add(pair);
                continue;
            }
            for (Object freqByRace : pair.getFrequencies()) {
                relativeRaceFreq = (RelativeFrequencyByRace) freqByRace;
                race = relativeRaceFreq.getRace();
                raceTotalFreqsMap = calculateTotalFrequency(loci, raceTotalFreqsMap, relativeRaceFreq, race);
            }
        }
        linkedPairs.removeAll(noRaceOverlapPairs);
        HashMap<String, List<Float>> minimumDifferenceMap;
        for (HaplotypePair pair : linkedPairs) {
            loci = Locus.lookup(pair.getLoci());
            setLinkedPairs(loci, true);
            minimumDifferenceMap = minimumDifferenceMapOfMaps.get(loci) != null ? minimumDifferenceMapOfMaps.get(loci) : new HashMap<String, List<Float>>();
            Set<RelativeFrequencyByRace> freqsByRace = new RelativeFrequencyByRaceSet(new RelativeFrequencyByRaceComparator());
            for (Object freqByRace : pair.getFrequencies()) {
                relativeRaceFreq = (RelativeFrequencyByRace) freqByRace;
                totalFreq = raceTotalFreqsMap.get(loci).get(relativeRaceFreq.getRace());
                relativeRaceFreq.setRelativeFrequency(new Float((relativeRaceFreq.getFrequency() * 100) / totalFreq));
                freqsByRace.add(relativeRaceFreq);
                List<Float> relativeFrequencies;
                if (minimumDifferenceMap.containsKey(relativeRaceFreq.getRace())) {
                    relativeFrequencies = minimumDifferenceMap.get(relativeRaceFreq.getRace());
                } else {
                    relativeFrequencies = new ArrayList<Float>();
                }
                relativeFrequencies.add(relativeRaceFreq.getRelativeFrequency());
                minimumDifferenceMap.put(relativeRaceFreq.getRace(), relativeFrequencies);
            }
            minimumDifferenceMapOfMaps.put(loci, minimumDifferenceMap);
            this.linkedPairs.add(pair);
        }
    } else {
        for (HaplotypePair pair : linkedPairs) {
            loci = Locus.lookup(pair.getLoci());
            setLinkedPairs(loci, true);
        }
        this.linkedPairs = linkedPairs;
    }
    Set<EnumSet<Locus>> lociSet = this.linkedPairsMap.keySet();
    for (EnumSet<Locus> lociInSet : lociSet) {
        getFirstPair(lociInSet);
    }
}
Also used : HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) Set(java.util.Set) RelativeFrequencyByRaceSet(org.dash.valid.race.RelativeFrequencyByRaceSet) HashSet(java.util.HashSet) LinkageElementsSet(org.dash.valid.LinkageElementsSet) EnumSet(java.util.EnumSet) HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HashMap(java.util.HashMap) RelativeFrequencyByRace(org.dash.valid.race.RelativeFrequencyByRace) EnumSet(java.util.EnumSet) RelativeFrequencyByRaceComparator(org.dash.valid.race.RelativeFrequencyByRaceComparator) RelativeFrequencyByRaceSet(org.dash.valid.race.RelativeFrequencyByRaceSet) ArrayList(java.util.ArrayList) LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) List(java.util.List) Locus(org.dash.valid.Locus) HashSet(java.util.HashSet)

Example 5 with HaplotypePair

use of org.dash.valid.gl.haplo.HaplotypePair 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)

Aggregations

HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)6 HaplotypePairSet (org.dash.valid.gl.haplo.HaplotypePairSet)5 HaplotypePairComparator (org.dash.valid.gl.haplo.HaplotypePairComparator)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Locus (org.dash.valid.Locus)3 LinkageDisequilibriumGenotypeList (org.dash.valid.gl.LinkageDisequilibriumGenotypeList)3 Haplotype (org.dash.valid.gl.haplo.Haplotype)3 MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)3 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)3 HashMap (java.util.HashMap)2 List (java.util.List)2 DetectedLinkageFindings (org.dash.valid.report.DetectedLinkageFindings)2 EnumSet (java.util.EnumSet)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LinkageElementsSet (org.dash.valid.LinkageElementsSet)1 RelativeFrequencyByRace (org.dash.valid.race.RelativeFrequencyByRace)1 RelativeFrequencyByRaceComparator (org.dash.valid.race.RelativeFrequencyByRaceComparator)1 RelativeFrequencyByRaceSet (org.dash.valid.race.RelativeFrequencyByRaceSet)1