Skip to content

Commit

Permalink
Repaired reporting order of linkages and now express as a haplotype.
Browse files Browse the repository at this point in the history
Remove multiple xml headers from single output.
  • Loading branch information
mpresteg committed Jun 6, 2017
1 parent 845c275 commit 4e60688
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 55 deletions.
4 changes: 4 additions & 0 deletions ld-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
<id>normalize-frequency-file</id>
<mainClass>org.nmdp.validation.tools.NormalizeFrequencyFile</mainClass>
</program>
<!-- <program>
<id>post-population-frequencies</id>
<mainClass>org.nmdp.validation.tools.PostPopulationFrequencies</mainClass>
</program> -->
</programs>
</configuration>
<executions>
Expand Down
1 change: 1 addition & 0 deletions ld-tools/src/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
1 change: 1 addition & 0 deletions ld-tools/src/main/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
1 change: 1 addition & 0 deletions ld-tools/src/main/java/org/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
1 change: 1 addition & 0 deletions ld-tools/src/main/java/org/nmdp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.dash.valid.report.CommonWellDocumentedWriter;
import org.dash.valid.report.DetectedFindingsWriter;
import org.dash.valid.report.DetectedLinkageFindings;
import org.dash.valid.report.DetectedLinkageFindingsList;
import org.dash.valid.report.HaplotypePairWriter;
import org.dash.valid.report.LinkageDisequilibriumWriter;
import org.dash.valid.report.SummaryWriter;
Expand Down Expand Up @@ -149,13 +150,17 @@ private void writeOutput(List<DetectedLinkageFindings> findingsList) throws IOEx
writer = writer(outputFile, true);
}

DetectedLinkageFindingsList allFindings = new DetectedLinkageFindingsList();
allFindings.setFindings(findingsList);
String summaryFindings = SummaryWriter.formatDetectedLinkages(allFindings);

for (DetectedLinkageFindings findings : findingsList) {
if (warnings != null && warnings == Boolean.TRUE && !findings.hasAnomalies()) {
continue;
}

if (writeToDir) {
summaryWriter.write(SummaryWriter.formatDetectedLinkages(findings));
//summaryWriter.write(SummaryWriter.formatDetectedLinkages(findings));

if (findings.hasAnomalies()) {
pairWarningsWriter.write(HaplotypePairWriter.formatDetectedLinkages(findings));
Expand All @@ -169,12 +174,13 @@ private void writeOutput(List<DetectedLinkageFindings> findingsList) throws IOEx
}
}
else {
writer.write(SummaryWriter.formatDetectedLinkages(findings));
//writer.write(SummaryWriter.formatDetectedLinkages(findings));
}

}

if (writeToDir) {
summaryWriter.write(summaryFindings);
summaryWriter.close();
pairWriter.close();
pairWarningsWriter.close();
Expand All @@ -184,6 +190,7 @@ private void writeOutput(List<DetectedLinkageFindings> findingsList) throws IOEx
detectedFindingsWriter.close();
}
else {
writer.write(summaryFindings);
writer.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
///*
//
// Copyright (c) 2014-2015 National Marrow Donor Program (NMDP)
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 3 of the License, or (at
// your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
// License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// > http://www.gnu.org/licenses/lgpl.html
//
//*/
//package org.nmdp.validation.tools;
//
//import static org.dishevelled.compress.Readers.reader;
//
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.IOException;
//import java.math.BigDecimal;
//import java.util.HashMap;
//import java.util.concurrent.Callable;
//
//import org.dash.valid.gl.GLStringConstants;
//import org.dishevelled.commandline.ArgumentList;
//import org.dishevelled.commandline.CommandLine;
//import org.dishevelled.commandline.CommandLineParseException;
//import org.dishevelled.commandline.CommandLineParser;
//import org.dishevelled.commandline.Switch;
//import org.dishevelled.commandline.Usage;
//import org.dishevelled.commandline.argument.FileArgument;
//import org.dishevelled.commandline.argument.StringArgument;
//
//import io.swagger.client.model.HFCurationRequest1;
//import io.swagger.client.model.HaplotypeFrequency1;
//import io.swagger.client.model.HaplotypeFrequencyData1;
//import io.swagger.client.model.License1;
//
///**
// * PostPopulationFrequencies
// *
// */
//public class PostPopulationFrequencies implements Callable<Integer> {
//
// private final File inputFile;
// private final String accessId;
// private final String cohortId;
//
// private static final String USAGE = "post-population-frequencies [args]";
//
//
// /**
// * Post population frequencies to the frequency curation service
// *
// * @param inputFile input file
// * @param accessId
// * @param cohortId
// */
// public PostPopulationFrequencies(File inputFile, String accessId, String cohortId) {
// this.inputFile = inputFile;
// this.accessId = accessId;
// this.cohortId = cohortId;
// }
//
// @Override
// public Integer call() throws Exception {
// postPopulationFrequencies(reader(inputFile));
//
// return 0;
// }
//
// public void postPopulationFrequencies(BufferedReader reader) throws IOException {
// String row;
// String[] columns;
//
// HashMap<String, HaplotypeFrequencyData1> populationMap = new HashMap<String, HaplotypeFrequencyData1>();
// HaplotypeFrequencyData1 haplotypeFrequencyData;
//
// License1 license = new License1();
// license.setTypeOfLicense(io.swagger.client.model.License1.TypeOfLicenseEnum.CC0);
//
// while ((row = reader.readLine()) != null) {
// columns = row.split(GLStringConstants.COMMA);
//
// String race = columns[0];
// String haplotype = columns[1];
// Double frequency = new Double(columns[2]);
//
// if (populationMap.containsKey(race)) {
// haplotypeFrequencyData = populationMap.get(race);
// }
// else {
// haplotypeFrequencyData = new HaplotypeFrequencyData1();
// haplotypeFrequencyData.setLicense(license);
// }
//
// HaplotypeFrequency1 hapFrequency = new HaplotypeFrequency1();
// hapFrequency.setFrequency(new BigDecimal(frequency));
// hapFrequency.setHaplotypeString(haplotype);
// haplotypeFrequencyData.addHaplotypeFrequencyListItem(hapFrequency);
//
// populationMap.put(race, haplotypeFrequencyData);
// }
//
// reader.close();
//
// for (String populationId : populationMap.keySet()) {
// HFCurationRequest1 hfCurationRequest = new HFCurationRequest1();
//
// hfCurationRequest.setAccessID(accessId);
// hfCurationRequest.setPopulationID(populationId);
// hfCurationRequest.setHaplotypeFrequencyData(populationMap.get(populationId));
// hfCurationRequest.setCohortID(cohortId);
//
// //HFCurationResponse1 response = api.hfcPost(hfCurationRequest);
// //System.out.println(response);
//
// System.out.println("Population: " + hfCurationRequest.getPopulationID() + " and haplotypes: " + hfCurationRequest.getHaplotypeFrequencyData().getHaplotypeFrequencyList().size());
//
// System.out.println("Here's the first two...");
//
// System.out.println(hfCurationRequest.getHaplotypeFrequencyData().getHaplotypeFrequencyList().get(0));
// System.out.println(hfCurationRequest.getHaplotypeFrequencyData().getHaplotypeFrequencyList().get(1));
// }
// }
//
// /**
// * Main.
// *
// * @param args command line args
// */
// public static void main(final String[] args) {
// Switch about = new Switch("a", "about", "display about message");
// Switch help = new Switch("h", "help", "display help message");
// FileArgument inputFile = new FileArgument("i", "input-file", "input file, default stdin", true);
// StringArgument accessId = new StringArgument("s", "accessId", "accessId", true);
// StringArgument cohortId = new StringArgument("c", "cohortId", "cohortId", true);
//
// ArgumentList arguments = new ArgumentList(about, help, inputFile, accessId, cohortId);
// CommandLine commandLine = new CommandLine(args);
//
// PostPopulationFrequencies postPopulationFrequencies = null;
// try
// {
// CommandLineParser.parse(commandLine, arguments);
// if (about.wasFound()) {
// About.about(System.out);
// System.exit(0);
// }
// if (help.wasFound()) {
// Usage.usage(USAGE, null, commandLine, arguments, System.out);
// System.exit(0);
// }
// postPopulationFrequencies = new PostPopulationFrequencies(inputFile.getValue(), accessId.getValue(), cohortId.getValue());
// }
// catch (CommandLineParseException | IllegalArgumentException e) {
// Usage.usage(USAGE, e, commandLine, arguments, System.err);
// System.exit(-1);
// }
// try {
// System.exit(postPopulationFrequencies.call());
// }
// catch (Exception e) {
// e.printStackTrace();
// System.exit(1);
// }
// }
//
//}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.dash.valid.report.CommonWellDocumentedWriter;
import org.dash.valid.report.DetectedFindingsWriter;
import org.dash.valid.report.DetectedLinkageFindings;
import org.dash.valid.report.DetectedLinkageFindingsList;
import org.dash.valid.report.HaplotypePairWriter;
import org.dash.valid.report.LinkageDisequilibriumWriter;
import org.dash.valid.report.SummaryWriter;
Expand Down Expand Up @@ -76,6 +77,8 @@ public static void main(String[] args) {
}

DetectedFindingsWriter.getInstance().closeWriters();

SummaryWriter.getInstance().closeWriters();
}

private static void analyzeGLStringFiles(String[] filenames) throws IOException {
Expand Down Expand Up @@ -109,8 +112,13 @@ public static void analyzeGLStringFile(String filename) throws IOException {
HaplotypePairWriter.getInstance().reportDetectedLinkages(findings);
CommonWellDocumentedWriter.getInstance().reportCommonWellDocumented(findings);
DetectedFindingsWriter.getInstance().reportDetectedFindings(findings);
SummaryWriter.getInstance().reportDetectedLinkages(findings);
//SummaryWriter.getInstance().reportDetectedLinkages(findings);
}

DetectedLinkageFindingsList allFindings = new DetectedLinkageFindingsList();
allFindings.setFindings(findingsList);

SummaryWriter.getInstance().reportDetectedLinkages(allFindings);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class HLAFrequenciesLoader {

private static final String UNDERSCORE = "_";

private static final String WIKIVERSITY_BC_FREQUENCIES = "frequencies/wikiversity/BCLinkageDisequilibrium.txt";
private static final String WIKIVERSITY_DRDQ_FREQUENCIES = "frequencies/wikiversity/DRDQLinkageDisequilibrium.txt";
public static final String WIKIVERSITY_BC_FREQUENCIES = "frequencies/wikiversity/BCLinkageDisequilibrium.txt";
public static final String WIKIVERSITY_DRDQ_FREQUENCIES = "frequencies/wikiversity/DRDQLinkageDisequilibrium.txt";

public static final String NMDP_ABC_FREQUENCIES = "frequencies/nmdp/A~C~B.xlsx";
public static final String NMDP_BC_FREQUENCIES = "frequencies/nmdp/C~B.xlsx";
Expand Down Expand Up @@ -607,7 +607,7 @@ private static List<FrequencyByRace> loadFrequencyAndRank(Row row, Cell cell,
return frequenciesByRace;
}

private List<DisequilibriumElement> loadLinkageReferenceData(String filename, Locus[] locusPositions) throws FileNotFoundException, IOException {
public List<DisequilibriumElement> loadLinkageReferenceData(String filename, Locus[] locusPositions) throws FileNotFoundException, IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(HLAFrequenciesLoader.class.getClassLoader().getResourceAsStream(filename)));
String row;
String[] columns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public HaplotypePair() {

}

public HaplotypePair(Haplotype haplotype1, Haplotype haplotype2) {
if (new HaplotypeComparator().compare(haplotype1, haplotype2) <= 0) {
this.haplotype1 = haplotype1;
this.haplotype2 = haplotype2;
public HaplotypePair(Haplotype hap1, Haplotype hap2) {
if (new HaplotypeComparator().compare(hap1, hap2) <= 0) {
this.haplotype1 = hap1;
this.haplotype2 = hap2;
}
else {
this.haplotype2 = haplotype1;
this.haplotype1 = haplotype2;
this.haplotype2 = hap1;
this.haplotype1 = hap2;
}

setLoci(Locus.lookup(haplotype1.getLoci()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
*/
package org.dash.valid.report;

import java.util.Set;
import java.util.logging.Logger;

import org.dash.valid.CoreDisequilibriumElement;
import org.dash.valid.DisequilibriumElement;
import org.dash.valid.Locus;
import org.dash.valid.LocusComparator;
import org.dash.valid.LocusSet;
import org.dash.valid.gl.GLStringConstants;


Expand All @@ -49,13 +52,23 @@ public void setDisequilibriumElement(DisequilibriumElement disequilibriumElement
public String toString() {
StringBuffer sb = new StringBuffer();

for (Locus locus : getDisequilibriumElement().getLoci()) {
sb.append(locus.getShortName() + " Locus: " + getDisequilibriumElement().getHlaElement(locus) + GLStringConstants.NEWLINE);
}

sb.append(((CoreDisequilibriumElement) getDisequilibriumElement()).getFrequencyInfo());
Set<Locus> loci = new LocusSet(new LocusComparator());
loci.addAll(getDisequilibriumElement().getLoci());

return sb.toString();
for (Locus locus : loci) {
// TODO: Make less clumsy to get rid of brackets?

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.dash.valid.report;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="gl-freqs")
public class DetectedLinkageFindingsList {

private List<DetectedLinkageFindings> findings = null;

@XmlElement(name="gl-freq")
public List<DetectedLinkageFindings> getFindings() {
return findings;
}

public void setFindings(List<DetectedLinkageFindings> findings) {
this.findings = findings;
}
}
Loading

0 comments on commit 4e60688

Please sign in to comment.