use of org.dash.valid.race.RelativeFrequencyByRace in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class GenotypesApiController method populateSwaggerObject.
public SampleData populateSwaggerObject(Sample sample) {
SampleData sampleData;
sampleData = new SampleData();
sampleData.setId(sample.getId());
sampleData.setGlString(sample.getGlString());
sampleData.setProcessedGlString(sample.getProcessedGlString());
for (HaplotypePair pair : sample.getFindings().getLinkedPairs()) {
HaplotypePairData pairData = new HaplotypePairData();
pairData.setHaplotype1(pair.getHaplotypes().get(0).getHaplotypeString());
pairData.setHaplotype2(pair.getHaplotypes().get(1).getHaplotypeString());
for (RelativeFrequencyByRace freqByRace : pair.getFrequencies()) {
FindingData finding = new FindingData();
finding.setRace(freqByRace.getRace());
finding.setFrequency(new BigDecimal(freqByRace.getFrequency()));
finding.setRelativeFrequency(new BigDecimal(freqByRace.getRelativeFrequency()));
finding.setHaplotype1Frequency(new BigDecimal(freqByRace.getHap1Frequency()));
finding.setHaplotype2Frequency(new BigDecimal(freqByRace.getHap2Frequency()));
pairData.addFindingItem(finding);
}
sampleData.addHaplotypePairItem(pairData);
}
return sampleData;
}
use of org.dash.valid.race.RelativeFrequencyByRace 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);
}
}
use of org.dash.valid.race.RelativeFrequencyByRace in project ImmunogeneticDataTools by nmdp-bioinformatics.
the class HaplotypePairComparator method compare.
@Override
public int compare(HaplotypePair element1, HaplotypePair element2) {
int ret = 0;
if (element1.equals(element2)) {
return 0;
} else if (element1.getPrimaryFrequency() != null && element2.getPrimaryFrequency() == null) {
return -1;
} else if (element1.getPrimaryFrequency() == null && element2.getPrimaryFrequency() != null) {
return 1;
} else if (element1.getPrimaryFrequency() != null && element1.getPrimaryFrequency() instanceof RelativeFrequencyByRace && element2.getPrimaryFrequency() != null) {
ret = new RelativeFrequencyByRaceComparator().compare((RelativeFrequencyByRace) element1.getPrimaryFrequency(), (RelativeFrequencyByRace) element2.getPrimaryFrequency());
}
if (ret != 0) {
return ret;
}
// else sort alphabetically
ret = element1.toString().compareTo(element2.toString());
return ret;
}
Aggregations