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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations