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