Search in sources :

Example 1 with MultiLocusHaplotype

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

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

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

the class GLStringUtilities method buildHaplotypes.

public static List<Haplotype> buildHaplotypes(LinkageDisequilibriumGenotypeList linkedGlString) {
    String glString = linkedGlString.getGLString();
    List<Haplotype> knownHaplotypes = new CopyOnWriteArrayList<Haplotype>();
    HashMap<String, Locus> locusMap = new HashMap<String, Locus>();
    Locus locus = null;
    if (StringUtils.countMatches(glString, GLStringConstants.GENE_PHASE_DELIMITER) > 1 && StringUtils.countMatches(glString, GLStringConstants.GENE_COPY_DELIMITER) == 1) {
        List<String> genes = GLStringUtilities.parse(glString, GLStringConstants.GENE_DELIMITER);
        for (String gene : genes) {
            List<String> genotypeAmbiguities = GLStringUtilities.parse(gene, GLStringConstants.GENOTYPE_AMBIGUITY_DELIMITER);
            for (String genotypeAmbiguity : genotypeAmbiguities) {
                List<String> geneCopies = GLStringUtilities.parse(genotypeAmbiguity, GLStringConstants.GENE_COPY_DELIMITER);
                int i = 0;
                for (String geneCopy : geneCopies) {
                    HashMap<Locus, SingleLocusHaplotype> singleLocusHaplotypes = new HashMap<Locus, SingleLocusHaplotype>();
                    List<String> genePhases = GLStringUtilities.parse(geneCopy, GLStringConstants.GENE_PHASE_DELIMITER);
                    for (String genePhase : genePhases) {
                        String[] splitString = genePhase.split(GLStringUtilities.ESCAPED_ASTERISK);
                        String locusVal = splitString[0];
                        List<String> alleleAmbiguities = GLStringUtilities.parse(genePhase, GLStringConstants.ALLELE_AMBIGUITY_DELIMITER);
                        if (locusMap.containsKey(locusVal)) {
                            locus = locusMap.get(locusVal);
                        } else {
                            locus = Locus.normalizeLocus(Locus.lookup(locusVal));
                            locusMap.put(locusVal, locus);
                        }
                        SingleLocusHaplotype haplotype = new SingleLocusHaplotype(locus, alleleAmbiguities, i);
                        singleLocusHaplotypes.put(locus, haplotype);
                    }
                    MultiLocusHaplotype multiLocusHaplotype = new MultiLocusHaplotype(singleLocusHaplotypes, linkedGlString.hasHomozygous(Locus.HLA_DRB345));
                    multiLocusHaplotype.setSequence(i + 1);
                    knownHaplotypes.add(multiLocusHaplotype);
                    i++;
                }
            }
        }
    }
    return knownHaplotypes;
}
Also used : HashMap(java.util.HashMap) SingleLocusHaplotype(org.dash.valid.gl.haplo.SingleLocusHaplotype) Locus(org.dash.valid.Locus) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype) Haplotype(org.dash.valid.gl.haplo.Haplotype) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype) SingleLocusHaplotype(org.dash.valid.gl.haplo.SingleLocusHaplotype) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 4 with MultiLocusHaplotype

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

the class LinkageDisequilibriumGenotypeList method constructPossibleHaplotypes.

@SuppressWarnings("unchecked")
public Set<MultiLocusHaplotype> constructPossibleHaplotypes(Set<Locus> loci) {
    HashMap<Locus, SingleLocusHaplotype> singleLocusHaplotypes = new HashMap<Locus, SingleLocusHaplotype>();
    Set<MultiLocusHaplotype> possibleHaplotypes = new HashSet<MultiLocusHaplotype>();
    Locus[] locusArray = loci.toArray(new Locus[loci.size()]);
    List<?>[] allelesByLocus = (List<?>[]) getAlleles(locusArray);
    List<List<Object>> haplotypeCombinations = cartesianProduct(allelesByLocus);
    String[] alleleParts;
    Locus locus;
    HashMap<String, Locus> locusMap = new HashMap<String, Locus>();
    for (List<Object> haplotypeCombo : haplotypeCombinations) {
        boolean drb345Homozygous = false;
        for (Object haplotypePart : haplotypeCombo) {
            List<String> alleles = (List<String>) haplotypePart;
            alleleParts = alleles.iterator().next().split(GLStringUtilities.ESCAPED_ASTERISK);
            if (locusMap.containsKey(alleleParts[0])) {
                locus = locusMap.get(alleleParts[0]);
            } else {
                locus = Locus.normalizeLocus(Locus.lookup(alleleParts[0]));
                locusMap.put(alleleParts[0], locus);
            }
            if (Locus.HLA_DRB345.equals(locus) && hasHomozygous(locus)) {
                drb345Homozygous = true;
            }
            singleLocusHaplotypes.put(locus, new SingleLocusHaplotype(locus, (List<String>) haplotypePart, getHaplotypeIndex(locus, (List<String>) haplotypePart)));
        }
        possibleHaplotypes.add(new MultiLocusHaplotype(singleLocusHaplotypes, drb345Homozygous));
    }
    return possibleHaplotypes;
}
Also used : HashMap(java.util.HashMap) SingleLocusHaplotype(org.dash.valid.gl.haplo.SingleLocusHaplotype) AlleleList(org.nmdp.gl.AlleleList) ArrayList(java.util.ArrayList) List(java.util.List) GenotypeList(org.nmdp.gl.GenotypeList) Locus(org.dash.valid.Locus) MultiLocusHaplotype(org.dash.valid.gl.haplo.MultiLocusHaplotype) HashSet(java.util.HashSet)

Example 5 with MultiLocusHaplotype

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

MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Locus (org.dash.valid.Locus)3 LinkageDisequilibriumGenotypeList (org.dash.valid.gl.LinkageDisequilibriumGenotypeList)3 Haplotype (org.dash.valid.gl.haplo.Haplotype)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)2 HaplotypePairComparator (org.dash.valid.gl.haplo.HaplotypePairComparator)2 HaplotypePairSet (org.dash.valid.gl.haplo.HaplotypePairSet)2 SingleLocusHaplotype (org.dash.valid.gl.haplo.SingleLocusHaplotype)2 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Test (org.junit.Test)1 AlleleList (org.nmdp.gl.AlleleList)1 GenotypeList (org.nmdp.gl.GenotypeList)1