Skip to content

Commit

Permalink
fix(phenotyper): pass through outside calls even if no recommendation…
Browse files Browse the repository at this point in the history
…s are available

Fix-for: #154
  • Loading branch information
markwoon committed Sep 22, 2023
1 parent 0183251 commit 03f7f7c
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/examples/pharmcat.example.match.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h3>VKORC1</h3>
<hr />
<footer class="container-fluid">
<p>
<small>Generated on 09/20/23.</small>
<small>Generated on 09/22/23.</small>
</p>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/pharmcat.example.match.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"namedAlleleMatcherVersion": "2.0.0",
"genomeBuild": "GRCh38.p13",
"inputFilename": "pharmcat.example.vcf",
"timestamp": "Sep 20, 2023, 3:53:35 PM",
"timestamp": "Sep 22, 2023, 3:03:49 PM",
"topCandidatesOnly": true,
"findCombinations": false,
"callCyp2d": false
Expand Down
32 changes: 16 additions & 16 deletions docs/examples/pharmcat.example.report.html
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@
</div>
<div class="metadata">
<table>
<tr><th>Date created</th><td>September 20, 2023</td></tr>
<tr><th>PharmCAT Version</th><td>v2.7.1-13-g4406afea</td></tr>
<tr><th>Date created</th><td>September 22, 2023</td></tr>
<tr><th>PharmCAT Version</th><td>v2.7.1-19-g0d11f2b6</td></tr>
<tr><th>CPIC Version</th><td></td></tr>
</table>
</div>
Expand Down Expand Up @@ -1435,18 +1435,18 @@ <h2>Section I: Genotype Summary</h2>
</td>
</tr>

<tr class="top-aligned gs-IFNL3/4">
<tr class="top-aligned gs-IFNL3_4">
<td>

<div class="drugName">

<a href="#peginterferon_alfa_2a">peginterferon alfa-2a</a>
<a href="#peginterferon_alfa-2a">peginterferon alfa-2a</a>

</div>

<div class="drugName">

<a href="#peginterferon_alfa_2b">peginterferon alfa-2b</a>
<a href="#peginterferon_alfa-2b">peginterferon alfa-2b</a>

</div>

Expand All @@ -1459,7 +1459,7 @@ <h2>Section I: Genotype Summary</h2>
</td>
<td>
<span class="noWrap">
<a href="#IFNL3/4" class="normalWrap">IFNL3/4</a>
<a href="#IFNL3_4" class="normalWrap">IFNL3/4</a>

<sup><a href="#genotypes-ddagger">&ddagger;</a></sup>
</span>
Expand Down Expand Up @@ -8603,8 +8603,8 @@ <h4 id="other-considerations">Other Considerations</h4>

</section>

<section class="guideline peginterferon_alfa_2a">
<h3 id="peginterferon_alfa_2a">peginterferon alfa-2a</h3>
<section class="guideline peginterferon_alfa-2a">
<h3 id="peginterferon_alfa-2a">peginterferon alfa-2a</h3>



Expand All @@ -8621,7 +8621,7 @@ <h3 id="peginterferon_alfa_2a">peginterferon alfa-2a</h3>
<tbody>


<tr class="top-aligned cpic-peginterferon_alfa_2a">
<tr class="top-aligned cpic-peginterferon_alfa-2a">
<td class="top-aligned">
<p>
<b>CPIC</b>
Expand Down Expand Up @@ -8667,8 +8667,8 @@ <h3 id="peginterferon_alfa_2a">peginterferon alfa-2a</h3>

</section>

<section class="guideline peginterferon_alfa_2b">
<h3 id="peginterferon_alfa_2b">peginterferon alfa-2b</h3>
<section class="guideline peginterferon_alfa-2b">
<h3 id="peginterferon_alfa-2b">peginterferon alfa-2b</h3>



Expand All @@ -8685,7 +8685,7 @@ <h3 id="peginterferon_alfa_2b">peginterferon alfa-2b</h3>
<tbody>


<tr class="top-aligned cpic-peginterferon_alfa_2b">
<tr class="top-aligned cpic-peginterferon_alfa-2b">
<td class="top-aligned">
<p>
<b>CPIC</b>
Expand Down Expand Up @@ -12492,7 +12492,7 @@ <h2>Section III: Allele Matching Details</h2>

<li><a href="#HLA-B">HLA-B allele match data</a></li>

<li><a href="#IFNL3/4">IFNL3/4 allele match data</a></li>
<li><a href="#IFNL3_4">IFNL3/4 allele match data</a></li>

<li><a href="#MT-RNR1">MT-RNR1 allele match data</a></li>

Expand Down Expand Up @@ -18028,7 +18028,7 @@ <h4>Other Positions of Interest</h4>
<tbody>

<tr>
<td id="94645745">chr10:94645745</td>
<td id="chr10_94645745">chr10:94645745</td>
<td id="rs12777823">rs12777823</td>


Expand Down Expand Up @@ -26105,8 +26105,8 @@ <h3 id="HLA-B">HLA-B allele match data</h3>

</section>

<section class="gene IFNL3/4">
<h3 id="IFNL3/4">IFNL3/4 allele match data</h3>
<section class="gene IFNL3_4">
<h3 id="IFNL3_4">IFNL3/4 allele match data</h3>


<table>
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/pharmcat.example.report.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "pharmcat.example",
"timestamp": "Sep 20, 2023, 3:53:36 PM",
"pharmcatVersion": "v2.7.1-13-g4406afea",
"timestamp": "Sep 22, 2023, 3:03:50 PM",
"pharmcatVersion": "v2.7.1-19-g0d11f2b6",
"cpicVersion": null,
"dpwgVersion": "2023-09-07-21-06",
"genes": {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/org/pharmgkb/pharmcat/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.pharmgkb.pharmcat.definition.DefinitionReader;
import org.pharmgkb.pharmcat.phenotype.PhenotypeMap;
Expand Down Expand Up @@ -75,19 +74,16 @@ public PgkbGuidelineCollection getDrugs() {
}


public SortedSet<String> getGenes() {
return m_drugs.getGenes();
}

public boolean hasGene(DataSource source, String gene) {
return m_drugs.getGenesUsedInSource(source).contains(gene);
}

/**
* Checks if gene is used in any drug recommendation from any source.
* Checks if gene can be called by NamedAlleleMatcher or is used in any drug recommendation from any source.
*/
public boolean hasGene(String gene) {
return getGenes().contains(gene);
return m_definitionReader.getGenes().contains(gene) ||
m_drugs.getGenesWithRecommendations().contains(gene);
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/org/pharmgkb/pharmcat/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.invoke.MethodHandles;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -25,8 +24,6 @@
import org.pharmgkb.pharmcat.reporter.format.HtmlFormat;
import org.pharmgkb.pharmcat.reporter.format.JsonFormat;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
Expand All @@ -35,7 +32,6 @@
* @author Mark Woon
*/
public class Pipeline implements Callable<PipelineResult> {
private static final Logger sf_logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public enum Mode {
/**
* Default mode. Prints informative messages to console.
Expand Down Expand Up @@ -286,16 +282,14 @@ public PipelineResult call() throws IOException {
for (OutsideCall call : OutsideCallParser.parse(m_phenotyperOutsideCallsFile)) {
if (!m_env.hasGene(call.getGene())) {
String msg = "Discarded outside call for " + call.getGene() + " because it is not supported by PharmCAT.";
warnings.put(call.getGene(), List.of(msg));
sf_logger.warn(msg);
output.add(AnsiConsole.styleWarning(msg));
continue;
}
if (!m_env.isActivityScoreGene(call.getGene())) {
if (call.getDiplotype() == null && call.getPhenotype() == null) {
String msg = call.getGene() + " is not an activity score gene but has outside call with only an " +
"activity score. PharmCAT will not be able to provide any recommendations based on this gene.";
warnings.put(call.getGene(), List.of(msg));
sf_logger.warn(msg);
output.add(AnsiConsole.styleWarning(msg));
}
}
outsideCalls.add(call);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Set<String> getChemicalsUsedInSource(DataSource source) {
.collect(Collectors.toSet());
}

public SortedSet<String> getGenes() {
public SortedSet<String> getGenesWithRecommendations() {
if (m_genes == null) {
m_genes = f_guidelinePackages.stream()
.flatMap(p -> p.getRecommendations().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ public static String externalHref(String href, String text) {
}

public static String sanitizeCssSelector(String value) {
return value.replaceAll("\\W+", "_")
return value.replaceAll("[^\\w-]+", "_")
.replaceAll("_-_", "-")
.replaceAll("_+", "_")
.replaceAll("^_+", "")
.replaceAll("_+$", "");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/pharmgkb/pharmcat/util/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public static void main(String[] args) {
definitionReader = DefinitionReader.defaultReader();
}

List<String> genesUsedInDrugRecommendations = new ArrayList<>(pgkbGuidelineCollection.getGenes());
List<String> genesUsedInDrugRecommendations = new ArrayList<>(pgkbGuidelineCollection.getGenesWithRecommendations());
genesUsedInDrugRecommendations.removeAll(definitionReader.getGeneAlleleCount().keySet());
genesUsedInDrugRecommendations.stream()
.filter(g -> !g.startsWith("HLA"))
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/org/pharmgkb/pharmcat/reporter/report.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</thead>
<tbody>
{{#each summaries}}
<tr class="top-aligned gs-{{symbol}}">
<tr class="top-aligned gs-{{{sanitizeCssSelector symbol}}}">
<td>
{{#each relatedDrugs}}
<div class="drugName">
Expand All @@ -103,7 +103,7 @@
</td>
<td>
<span class="noWrap">
<a href="#{{symbol}}" class="normalWrap">{{symbol}}</a>
<a href="#{{{sanitizeCssSelector symbol}}}" class="normalWrap">{{symbol}}</a>
{{#if hasMessages}}<sup><a href="#genotypes-dagger">&dagger;</a></sup>{{/if}}
{{#if showUnphasedNote}}<sup><a href="#genotypes-ddagger">&ddagger;</a></sup>{{/if}}
</span>
Expand Down Expand Up @@ -142,10 +142,10 @@
</p>
{{/if}}
{{#if treatUndocumentedVariationsAsReference}}
<p class="tdNote" id="gs-undocVarAsRef-{{symbol}}">
<p class="tdNote" id="gs-undocVarAsRef-{{{sanitizeCssSelector symbol}}}">
There are genetic variations in this gene that do not match what is in the allele definition.
<b>These undocumented variations were replaced with reference.</b>
See <a href="#{{symbol}}">Section III</a> for details.
See <a href="#{{{sanitizeCssSelector symbol}}}">Section III</a> for details.
</p>
{{/if}}
</td>
Expand Down Expand Up @@ -359,7 +359,7 @@
{{#if (thereAre geneReports)}}
<ol>
{{#each geneReports}}
<li><a href="#{{geneDisplay}}">{{geneDisplay}} allele match data</a></li>
<li><a href="#{{{sanitizeCssSelector geneDisplay}}}">{{geneDisplay}} allele match data</a></li>
{{/each}}
</ol>
{{/if}}
Expand All @@ -369,8 +369,8 @@


{{#each geneReports}}
<section class="gene {{geneDisplay}}">
<h3 id="{{geneDisplay}}">{{geneDisplay}} allele match data</h3>
<section class="gene {{{sanitizeCssSelector geneDisplay}}}">
<h3 id="{{{sanitizeCssSelector geneDisplay}}}">{{geneDisplay}} allele match data</h3>

{{#if (amdNoCall)}}
<div class="alert alert-warning no-data">
Expand Down Expand Up @@ -504,7 +504,7 @@
<tbody>
{{#each variantOfInterestReports}}
<tr>
<td id="{{position}}">{{chr}}:{{position}}</td>
<td id="{{chr}}_{{position}}">{{chr}}:{{position}}</td>
<td id="{{dbSnpId}}">{{dbSnpId}}</td>
{{#if missing}}
<td class="missingVariant"><em>missing</em></td>
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/pharmgkb/pharmcat/PharmCATTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,45 @@ void outsideCallsOnly(TestInfo testInfo) throws Exception {
}
}

@Test
void outsideCallsNoRecs(TestInfo testInfo) throws Exception {
Path vcfFile = PathUtils.getPathToResource("org/pharmgkb/pharmcat/reference.vcf");
Path outsideCallFile = PathUtils.getPathToResource("org/pharmgkb/pharmcat/PharmCATTest-outsideCallsNoRecs.tsv");

Path outputDir = TestUtils.getTestOutputDir(testInfo, true);
Path matcherOutput = outputDir.resolve("reference.match.json");
Path phenotyperOutput = outputDir.resolve("reference.phenotype.json");
Path reporterOutput = outputDir.resolve("reference.report.html");

try {
String systemOut = tapSystemOut(() -> PharmCAT.main(new String[] {
"-vcf", vcfFile.toString(),
"-po", outsideCallFile.toString(),
"-o", outputDir.toString(),
}));
System.out.println(systemOut);
assertTrue(systemOut.contains("Done."));
assertTrue(Files.exists(matcherOutput));
assertTrue(Files.exists(phenotyperOutput));
assertTrue(Files.exists(reporterOutput));

Collection<GeneReport> reports = Phenotyper.read(phenotyperOutput).getGeneReports().get(DataSource.CPIC)
.values();
Optional<GeneReport> grOpt = reports.stream()
.filter(gr -> gr.getGene().equals("IFNL3"))
.findFirst();
assertTrue(grOpt.isPresent());
assertTrue(grOpt.get().isCalled());
assertTrue(grOpt.get().isOutsideCall());

Document document = Jsoup.parse(reporterOutput.toFile());
assertEquals(1, document.select(".gene.IFNL3_4 .alert-warning.pcat-outside-call").size());

} finally {
TestUtils.deleteTestFiles(outputDir);
}
}

/**
* This test is dependent on CYP2C19 definition.
* It may fail if CYP2C19 definition changes too much.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ReportHelpersTest {
void testSanitizeCssSelector() {
assertEquals("ABC", ReportHelpers.sanitizeCssSelector("__ABC__"));
assertEquals("ABC", ReportHelpers.sanitizeCssSelector("(ABC)!"));
assertEquals("A_B_C", ReportHelpers.sanitizeCssSelector("A B - C"));
assertEquals("A_B-C", ReportHelpers.sanitizeCssSelector("A B - C"));
assertEquals("MT-RNR1", ReportHelpers.sanitizeCssSelector("MT-RNR1"));
assertEquals("IFNL3_4", ReportHelpers.sanitizeCssSelector("IFNL3/4"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IFNL3 rs12979860 variant (T)/rs12979860 variant (T)
CYP4F2 *1/*3

0 comments on commit 03f7f7c

Please sign in to comment.