Search in sources :

Example 1 with RelativeFrequencyByRaceComparator

use of org.dash.valid.race.RelativeFrequencyByRaceComparator 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 2 with RelativeFrequencyByRaceComparator

use of org.dash.valid.race.RelativeFrequencyByRaceComparator 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)2 RelativeFrequencyByRaceComparator (org.dash.valid.race.RelativeFrequencyByRaceComparator)2 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 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)1 HaplotypePairSet (org.dash.valid.gl.haplo.HaplotypePairSet)1 RelativeFrequencyByRaceSet (org.dash.valid.race.RelativeFrequencyByRaceSet)1