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;
}
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;
}
Aggregations