Search in sources :

Example 1 with SingleLocusHaplotype

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

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

Aggregations

HashMap (java.util.HashMap)2 Locus (org.dash.valid.Locus)2 MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)2 SingleLocusHaplotype (org.dash.valid.gl.haplo.SingleLocusHaplotype)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Haplotype (org.dash.valid.gl.haplo.Haplotype)1 AlleleList (org.nmdp.gl.AlleleList)1 GenotypeList (org.nmdp.gl.GenotypeList)1