Search in sources :

Example 1 with RelativeFrequencyByRace

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;
}
Also used : HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) RelativeFrequencyByRace(org.dash.valid.race.RelativeFrequencyByRace) SampleData(io.swagger.model.SampleData) FindingData(io.swagger.model.FindingData) HaplotypePairData(io.swagger.model.HaplotypePairData) BigDecimal(java.math.BigDecimal)

Example 2 with RelativeFrequencyByRace

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);
    }
}
Also used : HaplotypePairSet(org.dash.valid.gl.haplo.HaplotypePairSet) Set(java.util.Set) RelativeFrequencyByRaceSet(org.dash.valid.race.RelativeFrequencyByRaceSet) HashSet(java.util.HashSet) LinkageElementsSet(org.dash.valid.LinkageElementsSet) EnumSet(java.util.EnumSet) HaplotypePair(org.dash.valid.gl.haplo.HaplotypePair) HashMap(java.util.HashMap) RelativeFrequencyByRace(org.dash.valid.race.RelativeFrequencyByRace) EnumSet(java.util.EnumSet) RelativeFrequencyByRaceComparator(org.dash.valid.race.RelativeFrequencyByRaceComparator) RelativeFrequencyByRaceSet(org.dash.valid.race.RelativeFrequencyByRaceSet) ArrayList(java.util.ArrayList) LinkageDisequilibriumGenotypeList(org.dash.valid.gl.LinkageDisequilibriumGenotypeList) List(java.util.List) Locus(org.dash.valid.Locus) HashSet(java.util.HashSet)

Example 3 with RelativeFrequencyByRace

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;
}
Also used : RelativeFrequencyByRace(org.dash.valid.race.RelativeFrequencyByRace) RelativeFrequencyByRaceComparator(org.dash.valid.race.RelativeFrequencyByRaceComparator)

Aggregations

RelativeFrequencyByRace (org.dash.valid.race.RelativeFrequencyByRace)3 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)2 RelativeFrequencyByRaceComparator (org.dash.valid.race.RelativeFrequencyByRaceComparator)2 FindingData (io.swagger.model.FindingData)1 HaplotypePairData (io.swagger.model.HaplotypePairData)1 SampleData (io.swagger.model.SampleData)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 LinkageElementsSet (org.dash.valid.LinkageElementsSet)1 Locus (org.dash.valid.Locus)1 LinkageDisequilibriumGenotypeList (org.dash.valid.gl.LinkageDisequilibriumGenotypeList)1 HaplotypePairSet (org.dash.valid.gl.haplo.HaplotypePairSet)1 RelativeFrequencyByRaceSet (org.dash.valid.race.RelativeFrequencyByRaceSet)1