Search in sources :

Example 6 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 HashMap (java.util.HashMap)3 List (java.util.List)3 Locus (org.dash.valid.Locus)3 DisequilibriumElement (org.dash.valid.DisequilibriumElement)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 DisequilibriumElementComparator (org.dash.valid.DisequilibriumElementComparator)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