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