Search in sources :

Example 1 with Locus

use of org.dash.valid.Locus in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class LinkageDisequilibriumGenotypeList method parseGLString.

private void parseGLString() {
    HashMap<String, Locus> locusMap = new HashMap<String, Locus>();
    Locus locus = null;
    List<String> genes = GLStringUtilities.parse(glString, GLStringConstants.GENE_DELIMITER);
    for (String gene : genes) {
        String[] splitString = gene.split(GLStringUtilities.ESCAPED_ASTERISK);
        String locusVal = splitString[0];
        List<String> genotypeAmbiguities = GLStringUtilities.parse(gene, GLStringConstants.GENOTYPE_AMBIGUITY_DELIMITER);
        for (String genotypeAmbiguity : genotypeAmbiguities) {
            List<String> geneCopies = GLStringUtilities.parse(genotypeAmbiguity, GLStringConstants.GENE_COPY_DELIMITER);
            for (String geneCopy : geneCopies) {
                List<String> genePhases = GLStringUtilities.parse(geneCopy, GLStringConstants.GENE_PHASE_DELIMITER);
                for (String genePhase : genePhases) {
                    List<String> alleleAmbiguities = GLStringUtilities.parse(genePhase, GLStringConstants.ALLELE_AMBIGUITY_DELIMITER);
                    if (locusMap.containsKey(locusVal)) {
                        locus = locusMap.get(locusVal);
                    } else {
                        locus = Locus.normalizeLocus(Locus.lookup(locusVal));
                        locusMap.put(locusVal, locus);
                    }
                    setAlleles(locus, alleleAmbiguities);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Locus(org.dash.valid.Locus)

Example 2 with Locus

use of org.dash.valid.Locus 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 Locus

use of org.dash.valid.Locus in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class DetectedDisequilibriumElement method toString.

public String toString() {
    StringBuffer sb = new StringBuffer();
    Set<Locus> loci = new LocusSet(new LocusComparator());
    loci.addAll(getDisequilibriumElement().getLoci());
    for (Locus locus : loci) {
        // sb.append(locus.getShortName() + " Locus: " + getDisequilibriumElement().getHlaElement(locus) + GLStringConstants.NEWLINE);
        if (getDisequilibriumElement().getHlaElement(locus).size() == 1) {
            sb.append(getDisequilibriumElement().getHlaElement(locus).get(0));
        } else {
            sb.append(getDisequilibriumElement().getHlaElement(locus));
        }
        sb.append(GLStringConstants.GENE_PHASE_DELIMITER);
    }
    return sb.substring(0, sb.length() - 1) + GLStringConstants.NEWLINE + ((CoreDisequilibriumElement) getDisequilibriumElement()).getFrequencyInfo();
}
Also used : LocusSet(org.dash.valid.LocusSet) LocusComparator(org.dash.valid.LocusComparator) Locus(org.dash.valid.Locus)

Example 4 with Locus

use of org.dash.valid.Locus 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);
}
Also used : DisequilibriumElementComparator(org.dash.valid.DisequilibriumElementComparator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DisequilibriumElementByRace(org.dash.valid.race.DisequilibriumElementByRace) DetectedDisequilibriumElement(org.dash.valid.report.DetectedDisequilibriumElement) List(java.util.List) ArrayList(java.util.ArrayList) Locus(org.dash.valid.Locus) FrequencyByRace(org.dash.valid.race.FrequencyByRace) Test(org.junit.Test)

Example 5 with Locus

use of org.dash.valid.Locus in project ImmunogeneticDataTools by nmdp-bioinformatics.

the class HLAFrequenciesLoader method loadIndividualLocusFrequencies.

private void loadIndividualLocusFrequencies(File allelesFile) throws IOException {
    String row;
    String[] parts;
    HashMap<String, Locus> locusMap = new HashMap<String, Locus>();
    Locus locus;
    List<String> singleLocusFrequencies;
    InputStream inStream = new FileInputStream(allelesFile);
    InputStreamReader isr = new InputStreamReader(inStream);
    BufferedReader reader = new BufferedReader(isr);
    while ((row = reader.readLine()) != null) {
        parts = row.split(GLStringUtilities.ESCAPED_ASTERISK);
        if (locusMap.containsKey(parts[0])) {
            locus = locusMap.get(parts[0]);
        } else {
            locus = Locus.lookup(parts[0]);
            locusMap.put(parts[0], locus);
        }
        if (individualLocusFrequencies.containsKey(locus)) {
            singleLocusFrequencies = individualLocusFrequencies.get(locus);
        } else {
            singleLocusFrequencies = new ArrayList<String>();
        }
        singleLocusFrequencies.add(row);
        individualLocusFrequencies.put(locus, singleLocusFrequencies);
    }
    reader.close();
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Locus(org.dash.valid.Locus) FileInputStream(java.io.FileInputStream)

Aggregations

Locus (org.dash.valid.Locus)18 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 List (java.util.List)8 HashSet (java.util.HashSet)5 DisequilibriumElement (org.dash.valid.DisequilibriumElement)4 BaseDisequilibriumElement (org.dash.valid.base.BaseDisequilibriumElement)4 MultiLocusHaplotype (org.dash.valid.gl.haplo.MultiLocusHaplotype)4 DisequilibriumElementByRace (org.dash.valid.race.DisequilibriumElementByRace)4 FrequencyByRace (org.dash.valid.race.FrequencyByRace)4 Test (org.junit.Test)4 BufferedReader (java.io.BufferedReader)3 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 DisequilibriumElementComparator (org.dash.valid.DisequilibriumElementComparator)3 HaplotypePair (org.dash.valid.gl.haplo.HaplotypePair)3 SingleLocusHaplotype (org.dash.valid.gl.haplo.SingleLocusHaplotype)3 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)3 AlleleList (org.nmdp.gl.AlleleList)3 GenotypeList (org.nmdp.gl.GenotypeList)3