Skip to content

Commit

Permalink
fix(reporter): add call-only tsv reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
markwoon committed Feb 4, 2025
1 parent 585ed3a commit 420b48a
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 33 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/pharmgkb/pharmcat/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public class BaseConfig {
List<PrescribingGuidanceSource> reporterSources;
boolean reporterJson;
boolean reporterHtml = true;
boolean reporterCallsOnlyTsv = false;
Path outputDir;
String baseFilename;
boolean deleteIntermediateFiles;
boolean verbose;
SortedSet<String> samples = new TreeSet<>();


Expand Down Expand Up @@ -125,13 +127,15 @@ public class BaseConfig {
reporterTitle = cliHelper.getValue("rt");
reporterCompact = !cliHelper.hasOption("re");
reporterJson = cliHelper.hasOption("reporterJson");
reporterCallsOnlyTsv = cliHelper.hasOption("reporterCallsOnly");

if (researchMode) {
System.out.println("WARNING: REPORTER MODULE NOT AVAILABLE IN RESEARCH MODE");
if (!reporterJson) {
System.out.println("WARNING: FULL REPORTER OUTPUT NOT AVAILABLE IN RESEARCH MODE");
if (!reporterCallsOnlyTsv) {
runReporter = false;
}
reporterHtml = false;
reporterJson = false;
}

if (cliHelper.hasOption("rs")) {
Expand Down Expand Up @@ -166,6 +170,7 @@ public class BaseConfig {
}
baseFilename = cliHelper.getValue("bf");
deleteIntermediateFiles = cliHelper.hasOption("del");
verbose = cliHelper.isVerbose();
}


Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/pharmgkb/pharmcat/BatchPharmCAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static void main(String[] args) {
.addOption("rs", "reporter-sources", "Comma-separated list of sources to limit recommendations to: [CPIC, DPWG, FDA]", false, "sources")
.addOption("re", "reporter-extended", "Write an extended report (includes all possible genes and drugs, even if no data is available)")
.addOption("reporterJson", "reporter-save-json", "Save reporter results as JSON")
.addOption("reporterCallsOnly", "reporter-save-calls-only", "Save calls only as TSV")

// outputs
.addOption("o", "output-dir", "Directory to output to (optional, default is input file directory)", false, "directory")
Expand Down Expand Up @@ -396,7 +397,8 @@ public Pipeline build(Env env, int index, int totalTasks) throws ReportableExcep
m_config.topCandidateOnly, m_config.callCyp2d6, m_config.findCombinations, m_config.matcherHtml,
m_runPhenotyper, m_piFile, m_poFile,
m_runReporter, m_riFile, m_config.reporterTitle,
m_config.reporterSources, m_config.reporterCompact, m_config.reporterJson, m_config.reporterHtml,
m_config.reporterSources, m_config.reporterCompact,
m_config.reporterJson, m_config.reporterHtml, m_config.reporterCallsOnlyTsv,
m_config.outputDir, m_config.baseFilename, m_config.deleteIntermediateFiles,
mode, (index + "/" + totalTasks), m_verbose);
}
Expand Down
21 changes: 5 additions & 16 deletions src/main/java/org/pharmgkb/pharmcat/PharmCAT.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static void main(String[] args) {
.addOption("rs", "reporter-sources", "Comma-separated list of sources to limit recommendations to: [CPIC, DPWG, FDA]", false, "sources")
.addOption("re", "reporter-extended", "Write an extended report (includes all possible genes and drugs, even if no data is available)")
.addOption("reporterJson", "reporter-save-json", "Save reporter results as JSON")
.addOption("reporterCallsOnly", "reporter-save-calls-only", "Save calls only as TSV")

// outputs
.addOption("o", "output-dir", "Directory to output to (optional, default is input file directory)", false, "directory")
Expand Down Expand Up @@ -163,14 +164,8 @@ Please specify a VCF file (-vcf)"""
if (config.samples.size() > 1) {
System.out.println(x + " / " + config.samples.size() + " - " + sampleId);
}
Pipeline pipeline = new Pipeline(env,
config.runMatcher, vcfFile, sampleId, singleSample,
config.topCandidateOnly, config.callCyp2d6, config.findCombinations, config.matcherHtml,
config.runPhenotyper, phenotyperInputFile, phenotyperOutsideCallsFiles,
config.runReporter, reporterInputFile, config.reporterTitle,
config.reporterSources, config.reporterCompact, config.reporterJson, config.reporterHtml,
config.outputDir, config.baseFilename, config.deleteIntermediateFiles,
Pipeline.Mode.CLI, null, cliHelper.isVerbose());
Pipeline pipeline = new Pipeline(env, config, vcfFile, sampleId, singleSample,
phenotyperInputFile, phenotyperOutsideCallsFiles, reporterInputFile);
if (pipeline.call().getStatus() == PipelineResult.Status.NOOP) {
failIfNotTest();
blankRuns.add(sampleId);
Expand All @@ -187,14 +182,8 @@ Please specify a VCF file (-vcf)"""
}

} else {
Pipeline pipeline = new Pipeline(env,
false, null, null, true,
config.topCandidateOnly, config.callCyp2d6, config.findCombinations, config.matcherHtml,
config.runPhenotyper, phenotyperInputFile, phenotyperOutsideCallsFiles,
config.runReporter, reporterInputFile, config.reporterTitle,
config.reporterSources, config.reporterCompact, config.reporterJson, config.reporterHtml,
config.outputDir, config.baseFilename, config.deleteIntermediateFiles,
Pipeline.Mode.CLI, null, cliHelper.isVerbose());
Pipeline pipeline = new Pipeline(env, config, null, null, true,
phenotyperInputFile, phenotyperOutsideCallsFiles, reporterInputFile);
if (pipeline.call().getStatus() == PipelineResult.Status.NOOP) {
cliHelper.printHelp();
System.out.println("Nothing to do.");
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/org/pharmgkb/pharmcat/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.pharmgkb.pharmcat.phenotype.Phenotyper;
import org.pharmgkb.pharmcat.phenotype.model.OutsideCall;
import org.pharmgkb.pharmcat.reporter.ReportContext;
import org.pharmgkb.pharmcat.reporter.format.CallsOnlyFormat;
import org.pharmgkb.pharmcat.reporter.format.HtmlFormat;
import org.pharmgkb.pharmcat.reporter.format.JsonFormat;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;
Expand Down Expand Up @@ -72,6 +73,7 @@ public enum Mode {
private List<PrescribingGuidanceSource> m_reporterSources;
private Path m_reporterJsonFile;
private Path m_reporterHtmlFile;
private Path m_reporterCallsOnlyFile;
private ReportContext m_reportContext;

private final boolean m_deleteIntermediateFiles;
Expand All @@ -83,12 +85,28 @@ public enum Mode {
private final String m_displayCount;


public Pipeline(Env env, BaseConfig config, @Nullable VcfFile vcfFile,
@Nullable String sampleId, boolean singleSample,
@Nullable Path phenotyperInputFile, @Nullable List<Path> phenotyperOutsideCallsFiles,
@Nullable Path reporterInputFile) throws ReportableException {
this(env, config.runMatcher, vcfFile, sampleId, singleSample,
config.topCandidateOnly, config.callCyp2d6, config.findCombinations, config.matcherHtml,
config.runPhenotyper, phenotyperInputFile, phenotyperOutsideCallsFiles,
config.runReporter, reporterInputFile, config.reporterTitle,
config.reporterSources, config.reporterCompact,
config.reporterJson, config.reporterHtml, config.reporterCallsOnlyTsv,
config.outputDir, config.baseFilename, config.deleteIntermediateFiles,
Pipeline.Mode.CLI, null, config.verbose);
}


public Pipeline(Env env,
boolean runMatcher, @Nullable VcfFile vcfFile, @Nullable String sampleId, boolean singleSample,
boolean topCandidateOnly, boolean callCyp2d6, boolean findCombinations, boolean matcherHtml,
boolean runPhenotyper, @Nullable Path phenotyperInputFile, @Nullable List<Path> phenotyperOutsideCallsFile,
boolean runReporter, @Nullable Path reporterInputFile, @Nullable String reporterTitle,
@Nullable List<PrescribingGuidanceSource> reporterSources, boolean reporterCompact, boolean reporterJson, boolean reporterHtml,
@Nullable List<PrescribingGuidanceSource> reporterSources, boolean reporterCompact,
boolean reporterJson, boolean reporterHtml, boolean reporterCallsOnlyTsv,
@Nullable Path outputDir, @Nullable String baseFilename, boolean deleteIntermediateFiles,
Mode mode, @Nullable String displayCount, boolean verbose) throws ReportableException {
m_env = env;
Expand Down Expand Up @@ -151,6 +169,9 @@ public Pipeline(Env env,
if (reporterJson) {
m_reporterJsonFile = m_baseDir.resolve(m_basename + BaseConfig.REPORTER_SUFFIX + ".json");
}
if (reporterCallsOnlyTsv) {
m_reporterCallsOnlyFile = m_baseDir.resolve(m_basename + BaseConfig.REPORTER_SUFFIX + ".tsv");
}
m_reporterTitle = reporterTitle;
if (m_reporterTitle == null) {
m_reporterTitle = m_basename;
Expand Down Expand Up @@ -348,6 +369,16 @@ public PipelineResult call() throws IOException {
new JsonFormat(m_reporterJsonFile, m_env)
.write(m_reportContext);
}
if (m_reporterCallsOnlyFile != null) {
if (!batchDisplayMode) {
output.add("Saving calls-only TSV results to " + m_reporterCallsOnlyFile);
}
CallsOnlyFormat caf = new CallsOnlyFormat(m_reporterCallsOnlyFile, m_env);
if (!m_topCandidateOnly) {
caf.showMatchScores();
}
caf.write(m_reportContext);
}
didSomething = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class NamedAllele implements Comparable<NamedAllele> {
private HashMap<VariantLocus, String> m_alleleMap;
private HashMap<VariantLocus, String> m_cpicAlleleMap;
private List<Integer> m_wobblePositions;
@Expose
@SerializedName("score")
private int m_score;
private transient Pattern m_permutations;
// generated by combinations code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public List<Diplotype> makeComponentDiplotypes(GeneCall geneCall, DataSource sou
}
}
for (NamedAllele na : haps) {
dips.add(new Diplotype(m_gene, na.getName(), null, m_env, source));
dips.add(new Diplotype(m_gene, na.getName(), null, m_env, source, na.getScore()));
}
return dips;
}
Expand All @@ -79,8 +79,7 @@ public List<Diplotype> makeDiplotypes(Collection<DiplotypeMatch> matches, DataSo
if (h2 != null) {
h2Name = h2.getName();
}

Diplotype diplotype = new Diplotype(m_gene, h1.getName(), h2Name, m_env, source);
Diplotype diplotype = new Diplotype(m_gene, h1.getName(), h2Name, m_env, source, dm.getScore());
diplotype.setCombination(h1 instanceof CombinationMatch || h2 instanceof CombinationMatch);
return diplotype;
})
Expand All @@ -92,7 +91,7 @@ public List<Diplotype> makeDiplotypesFromHaplotypeMatches(Collection<HaplotypeMa
return ImmutableList.of(makeUnknownDiplotype(m_gene, m_env, source));
}
return matches.stream()
.map((hm) -> new Diplotype(m_gene, hm.getName(), null, m_env, source))
.map((hm) -> new Diplotype(m_gene, hm.getName(), null, m_env, source, 0))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static SortedSet<Diplotype> inferDiplotypes(GeneReport report, Env env,
List<VariantReport> variants = report.getVariantReports().stream()
.filter(v -> sf_callPosition.equals(v.getDbSnpId()))
.toList();
if (variants.size() == 0) {
if (variants.isEmpty()) {
return report.getSourceDiplotypes();
}
if (variants.size() > 1) {
Expand All @@ -64,13 +64,13 @@ public static SortedSet<Diplotype> inferDiplotypes(GeneReport report, Env env,
return report.getSourceDiplotypes();
}

Diplotype diplotype = new Diplotype(GENE, haps[0], haps[1], env, source);
Diplotype diplotype = new Diplotype(GENE, haps[0], haps[1], env, source, 0);
diplotype.setVariant(variant);
diplotype.setInferred(true);

String[] alleles = Objects.requireNonNull(splitVariant(variant));
diplotype.setInferredSourceDiplotype(new Diplotype(GENE,
sf_callPosition + " " + alleles[0], sf_callPosition + " " + alleles[1], env, source));
sf_callPosition + " " + alleles[0], sf_callPosition + " " + alleles[1], env, source, 0));

SortedSet<Diplotype> dips = new TreeSet<>();
dips.add(diplotype);
Expand Down
Loading

0 comments on commit 420b48a

Please sign in to comment.