use of org.dash.valid.race.RelativeFrequencyByRaceSet 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);
}
}
Aggregations