Search in sources :

Example 1 with FrequencyByRace

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

the class HLAFrequenciesLoader method loadFrequencyAndRank.

/**
 * @param row
 * @param frequenciesByRace
 * @param cell
 * @param idx
 */
private static List<FrequencyByRace> loadFrequencyAndRank(Row row, Cell cell, List<FrequencyByRace> frequenciesByRace, List<String> raceHeaders) {
    Double freq = cell.getNumericCellValue();
    if (freq != 0) {
        FrequencyByRace frequencyByRace = new FrequencyByRace(freq, ((Double) row.getCell(cell.getColumnIndex() + 1).getNumericCellValue()).toString(), raceHeaders.get(cell.getColumnIndex()));
        frequenciesByRace.add(frequencyByRace);
    }
    Collections.sort(frequenciesByRace, new FrequencyByRaceComparator());
    return frequenciesByRace;
}
Also used : FrequencyByRaceComparator(org.dash.valid.race.FrequencyByRaceComparator) FrequencyByRace(org.dash.valid.race.FrequencyByRace)

Example 2 with FrequencyByRace

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

the class HLAFrequenciesLoader method readDiseqilibriumElementsByRace.

/**
 * @param row
 */
private static DisequilibriumElement readDiseqilibriumElementsByRace(Row row, List<String> raceHeaders, Locus[] locusPositions) {
    // For each row, iterate through each columns
    Iterator<Cell> cellIterator = row.cellIterator();
    List<FrequencyByRace> frequenciesByRace = new ArrayList<FrequencyByRace>();
    DisequilibriumElementByRace disElement = new DisequilibriumElementByRace();
    int columnIndex;
    String cellValue = null;
    while (cellIterator.hasNext()) {
        Cell cell = cellIterator.next();
        columnIndex = cell.getColumnIndex();
        if (columnIndex < locusPositions.length) {
            cellValue = cell.getStringCellValue();
            if (!cellValue.contains(GLStringConstants.ASTERISK)) {
                cellValue = locusPositions[columnIndex].getShortName() + GLStringConstants.ASTERISK + cellValue.substring(0, 2) + GLStringUtilities.COLON + cellValue.substring(2);
            }
            List<String> val = new ArrayList<String>();
            val.add(GLStringConstants.HLA_DASH + cellValue);
            disElement.setHlaElement(locusPositions[columnIndex], val);
        } else {
            if ((locusPositions.length % 2 == 0 && columnIndex % 2 == 0) || (locusPositions.length % 2 != 0 && columnIndex % 2 != 0)) {
                disElement.setFrequenciesByRace(loadFrequencyAndRank(row, cell, frequenciesByRace, raceHeaders));
            }
        }
    }
    return disElement;
}
Also used : ArrayList(java.util.ArrayList) Cell(org.apache.poi.ss.usermodel.Cell) FrequencyByRace(org.dash.valid.race.FrequencyByRace) DisequilibriumElementByRace(org.dash.valid.race.DisequilibriumElementByRace)

Example 3 with FrequencyByRace

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

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

the class HLAFrequenciesLoader method loadStandardReferenceData.

public static List<DisequilibriumElement> loadStandardReferenceData(BufferedReader reader) throws IOException {
    String row;
    String[] columns;
    HashMap<String, List<FrequencyByRace>> frequencyMap = new HashMap<String, List<FrequencyByRace>>();
    while ((row = reader.readLine()) != null) {
        columns = row.split(GLStringConstants.COMMA);
        String race = columns[0];
        String haplotype = columns[1];
        Double frequency = new Double(columns[2]);
        String rank = columns[3];
        List<FrequencyByRace> freqList = frequencyMap.get(haplotype);
        if (freqList == null) {
            freqList = new ArrayList<FrequencyByRace>();
        }
        FrequencyByRace freqByRace = new FrequencyByRace(frequency, rank, race);
        freqList.add(freqByRace);
        frequencyMap.put(haplotype, freqList);
    }
    List<DisequilibriumElement> disequilibriumElements = new ArrayList<DisequilibriumElement>();
    DisequilibriumElementByRace disElement;
    HashMap<String, Locus> locusMap = new HashMap<String, Locus>();
    Locus locus = null;
    for (String haplotype : frequencyMap.keySet()) {
        String[] locusHaplotypes = haplotype.split(GLStringConstants.GENE_PHASE_DELIMITER);
        HashMap<Locus, List<String>> hlaElementMap = new HashMap<Locus, List<String>>();
        for (String locusHaplotype : locusHaplotypes) {
            String[] parts = locusHaplotype.split(GLStringUtilities.ESCAPED_ASTERISK);
            List<String> val = new ArrayList<String>();
            val.add(locusHaplotype);
            if (locusMap.containsKey(parts[0])) {
                locus = locusMap.get(parts[0]);
            } else {
                locus = Locus.normalizeLocus(Locus.lookup(parts[0]));
                locusMap.put(parts[0], locus);
            }
            hlaElementMap.put(locus, val);
        }
        disElement = new DisequilibriumElementByRace(hlaElementMap, frequencyMap.get(haplotype));
        disequilibriumElements.add(disElement);
    }
    reader.close();
    return disequilibriumElements;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DisequilibriumElementByRace(org.dash.valid.race.DisequilibriumElementByRace) BaseDisequilibriumElement(org.dash.valid.base.BaseDisequilibriumElement) DisequilibriumElement(org.dash.valid.DisequilibriumElement) ArrayList(java.util.ArrayList) List(java.util.List) Locus(org.dash.valid.Locus) FrequencyByRace(org.dash.valid.race.FrequencyByRace)

Example 5 with FrequencyByRace

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

the class NormalizeFrequencyFile method call.

@Override
public Integer call() throws Exception {
    PrintWriter writer = new PrintWriter(outputFile);
    if (SINGLE.equals(frequencies)) {
        List<String> singleLocusFrequencies = HLAFrequenciesLoader.loadIndividualLocusFrequency(new FileInputStream(inputFile));
        for (String allele : singleLocusFrequencies) {
            writer.write(allele + GLStringConstants.NEWLINE);
        }
    } else {
        HashSet<String> linkageNames = new HashSet<String>();
        linkageNames.add(frequencies);
        Set<Linkages> linkagesSet = Linkages.lookup(linkageNames);
        LinkagesLoader.getInstance(linkagesSet);
        List<DisequilibriumElement> disequilibriumElements = HLAFrequenciesLoader.loadNMDPLinkageReferenceData(new FileInputStream(inputFile), LOCUS_POSITION_MAP.get(Linkages.lookup(frequencies).getLoci()));
        for (DisequilibriumElement element : disequilibriumElements) {
            StringBuffer sb = new StringBuffer();
            int locusCounter = 0;
            for (Locus locus : Locus.lookup(element.getLoci())) {
                if (locusCounter > 0) {
                    sb.append(GLStringConstants.GENE_PHASE_DELIMITER);
                }
                sb.append(element.getHlaElement(locus).get(0));
                locusCounter++;
            }
            List<FrequencyByRace> frequencies = ((DisequilibriumElementByRace) element).getFrequenciesByRace();
            for (FrequencyByRace frequency : frequencies) {
                writer.write(frequency.getRace() + GLStringConstants.COMMA + sb + GLStringConstants.COMMA + frequency.getFrequency() + GLStringConstants.COMMA + frequency.getRank() + GLStringConstants.NEWLINE);
            }
        }
    }
    writer.close();
    return 0;
}
Also used : Linkages(org.dash.valid.Linkages) FileInputStream(java.io.FileInputStream) DisequilibriumElementByRace(org.dash.valid.race.DisequilibriumElementByRace) DisequilibriumElement(org.dash.valid.DisequilibriumElement) Locus(org.dash.valid.Locus) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet) FrequencyByRace(org.dash.valid.race.FrequencyByRace)

Aggregations

FrequencyByRace (org.dash.valid.race.FrequencyByRace)6 DisequilibriumElementByRace (org.dash.valid.race.DisequilibriumElementByRace)5 ArrayList (java.util.ArrayList)4 Locus (org.dash.valid.Locus)4 HashMap (java.util.HashMap)3 List (java.util.List)3 DisequilibriumElement (org.dash.valid.DisequilibriumElement)2 DisequilibriumElementComparator (org.dash.valid.DisequilibriumElementComparator)2 DetectedDisequilibriumElement (org.dash.valid.report.DetectedDisequilibriumElement)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 PrintWriter (java.io.PrintWriter)1 HashSet (java.util.HashSet)1 Cell (org.apache.poi.ss.usermodel.Cell)1 LinkageElementsSet (org.dash.valid.LinkageElementsSet)1 Linkages (org.dash.valid.Linkages)1 BaseDisequilibriumElement (org.dash.valid.base.BaseDisequilibriumElement)1 FrequencyByRaceComparator (org.dash.valid.race.FrequencyByRaceComparator)1