Skip to content

Commit

Permalink
test(pharmcat): update unit tests for new FDA content
Browse files Browse the repository at this point in the history
  • Loading branch information
whaleyr committed Mar 14, 2024
1 parent e9a6547 commit 420de6d
Show file tree
Hide file tree
Showing 12 changed files with 671 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public Set<GuidelinePackage> getGuidelinesFromSource(DataSource dataSource) {
.collect(Collectors.toSet());
}

public Set<GuidelinePackage> getGuidelinesFromSource(PrescribingGuidanceSource source) {
return f_guidelineMap.values().stream()
.filter(g -> g.isDataSourceType(source))
.collect(Collectors.toSet());
}

public Set<String> getChemicalsUsedInSource(DataSource source) {
return f_guidelineMap.values().stream()
.map(GuidelinePackage::getGuideline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class GuidelinePackage implements Comparable<GuidelinePackage> {
@Expose
@SerializedName("citations")
private List<Publication> citations = new ArrayList<>();
@Expose
@SerializedName("url")
private String url;


/**
Expand Down Expand Up @@ -52,6 +55,10 @@ public List<Publication> getCitations() {
return citations;
}

public String getUrl() {
return this.url;
}


public Set<String> getGenes() {
return guideline.getRelatedGenes().stream()
Expand All @@ -73,19 +80,7 @@ public boolean isDataSourceType(PrescribingGuidanceSource type) {
@Override
public String toString() {
if (guideline != null) {
String chemicals = recommendations.stream()
.flatMap((r) -> r.getRelatedChemicals().stream())
.map(AccessionObject::getName)
.distinct()
.sorted()
.collect(Collectors.joining("_"));
return String.format(
"%s_%s_%s_and_%s.json",
guideline.getSource(),
guideline.getObjCls(),
chemicals,
guideline.getRelatedGenes().stream().map(AccessionObject::getSymbol).collect(Collectors.joining("_"))
).replaceAll("[\\s\\/]", "_");
return guideline.getName();
}
else {
return super.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.pharmgkb.pharmcat.UnexpectedStateException;
import org.pharmgkb.pharmcat.reporter.TextConstants;
import org.pharmgkb.pharmcat.reporter.model.MessageAnnotation;
import org.pharmgkb.pharmcat.reporter.model.pgkb.OntologyTerm;
import org.pharmgkb.pharmcat.reporter.model.pgkb.RecommendationAnnotation;


Expand Down Expand Up @@ -86,7 +87,7 @@ public AnnotationReport(RecommendationAnnotation recommendation, String localId)
m_implications.addAll(recommendation.getImplications());
}
m_drugRecommendation = recommendation.getText().getHtmlStripped();
m_classification = recommendation.getClassification() != null ? recommendation.getClassification().getTerm() : null;
m_classification = normalizeClassification(recommendation.getClassification());

m_population = recommendation.getPopulation();

Expand Down Expand Up @@ -221,6 +222,13 @@ public void checkDiplotypes() {
}
}

private static String normalizeClassification(OntologyTerm term) {
if (term != null && !TextConstants.isUnspecified(term.getTerm())) {
return term.getTerm();
}
return TextConstants.UNSPECIFIED;
}


@Override
public int compareTo(@NonNull AnnotationReport o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public DrugReport(String name, List<GuidelinePackage> guidelinePackages, ReportC
// DPWG drug can have multiple guideline reports
for (GuidelinePackage guidelinePackage : guidelinePackages) {
m_source = PrescribingGuidanceSource.typeFor(guidelinePackage.getGuideline());
m_urls.add(guidelinePackage.getGuideline().getUrl());
m_urls.add(guidelinePackage.getUrl());
if (guidelinePackage.getCitations() != null) {
m_citations.addAll(guidelinePackage.getCitations());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public GuidelineReport(GuidelinePackage guidelinePackage, ReportContext reportCo
m_name = guidelinePackage.getGuideline().getName();
m_source = PrescribingGuidanceSource.typeFor(guidelinePackage.getGuideline());
m_version = reportContext.getCpicVersion();
m_url = guidelinePackage.getGuideline().getUrl();
m_url = guidelinePackage.getUrl();
initializeGenes(guidelinePackage.getGenes(), reportContext);
matchAnnotations(guidelinePackage, drugName);
}
Expand Down

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions src/main/resources/org/pharmgkb/pharmcat/reporter/report.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,7 @@
<tr class="top-aligned {{{rxAnnotationClass source drug}}}">
<td>
<p>
<b>{{source}}</b>
{{#unless notCalled}}
<sup class="sources">
{{{listSources urls}}}
</sup>
{{/unless}}
<b><a href="{{url}}" target="_blank">{{source}}</a></b>
</p>
<p>Population:<br />{{capitalizeNA population}}</p>
{{{annotationTags this}}}
Expand Down
21 changes: 8 additions & 13 deletions src/test/java/org/pharmgkb/pharmcat/DpydTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ public static void dpydHasReports(PipelineWrapper testWrapper, RecPresence hasCp
assertNotNull(dpwgDpydGeneReport);
assertEquals(1, dpwgDpydGeneReport.getRecommendationDiplotypes().size());

int numAnnotations = 0;

if (hasCpicReport == RecPresence.YES) {
testWrapper.testAnyMatchFromSource("fluorouracil", PrescribingGuidanceSource.CPIC_GUIDELINE);
testWrapper.testAnyMatchFromSource("capecitabine", PrescribingGuidanceSource.CPIC_GUIDELINE);
numAnnotations += 1;
testWrapper.testMatchedAnnotations("fluorouracil", PrescribingGuidanceSource.CPIC_GUIDELINE, 1);
testWrapper.testMatchedAnnotations("capecitabine", PrescribingGuidanceSource.CPIC_GUIDELINE, 1);

} else {
testWrapper.testNoMatchFromSource("fluorouracil", PrescribingGuidanceSource.CPIC_GUIDELINE);
Expand All @@ -107,17 +106,13 @@ public static void dpydHasReports(PipelineWrapper testWrapper, RecPresence hasCp
if (hasDpwgReport == RecPresence.YES) {
testWrapper.testAnyMatchFromSource("fluorouracil", PrescribingGuidanceSource.DPWG_GUIDELINE);
testWrapper.testAnyMatchFromSource("capecitabine", PrescribingGuidanceSource.DPWG_GUIDELINE);
numAnnotations += 1;
testWrapper.testMatchedAnnotations("fluorouracil", PrescribingGuidanceSource.DPWG_GUIDELINE, 1);
testWrapper.testMatchedAnnotations("capecitabine", PrescribingGuidanceSource.DPWG_GUIDELINE, 1);

} else {
testWrapper.testNoMatchFromSource("fluorouracil", PrescribingGuidanceSource.DPWG_GUIDELINE);
testWrapper.testNoMatchFromSource("capecitabine", PrescribingGuidanceSource.DPWG_GUIDELINE);
}

if (numAnnotations > 0) {
testWrapper.testMatchedAnnotations("fluorouracil", numAnnotations);
testWrapper.testMatchedAnnotations("capecitabine", numAnnotations);
}
}


Expand Down Expand Up @@ -264,7 +259,7 @@ static void dpydHtmlChecks(Document document, @Nullable List<String> expectedCal
.map(c -> "DPYD:" + c)
.toList();

Elements cpicCapecitabineDips = capecitabineSection.select(".cpic-capecitabine .rx-dip");
Elements cpicCapecitabineDips = capecitabineSection.select(".cpic-guideline-capecitabine .rx-dip");
if (hasCpicAnnotation == RecPresence.YES) {
assertEquals(expectedRxCalls,
cpicCapecitabineDips.stream()
Expand All @@ -273,21 +268,21 @@ static void dpydHtmlChecks(Document document, @Nullable List<String> expectedCal

} else {
assertEquals(0, cpicCapecitabineDips.size());
Elements unmatchedDips = capecitabineSection.select(".cpic-capecitabine .rx-unmatched-dip");
Elements unmatchedDips = capecitabineSection.select(".cpic-guideline-capecitabine .rx-unmatched-dip");
assertEquals(expectedRxCalls, unmatchedDips.stream()
.map(e -> cleanupRxDip(e, List.of("DPYD")))
.toList());
}

Elements dpwgCapecitabineDips = capecitabineSection.select(".dpwg-capecitabine .rx-dip");
Elements dpwgCapecitabineDips = capecitabineSection.select(".dpwg-guideline-capecitabine .rx-dip");
if (hasDpwgAnnotation == RecPresence.YES) {
assertEquals(expectedRxCalls,
dpwgCapecitabineDips.stream()
.map(e -> cleanupRxDip(e, List.of("DPYD")))
.toList());
} else {
assertEquals(0, dpwgCapecitabineDips.size());
Elements unmatchedDips = capecitabineSection.select(".dpwg-capecitabine .rx-unmatched-dip");
Elements unmatchedDips = capecitabineSection.select(".dpwg-guideline-capecitabine .rx-unmatched-dip");
assertEquals(expectedRxCalls, unmatchedDips.stream()
.map(e -> cleanupRxDip(e, List.of("DPYD")))
.toList());
Expand Down
Loading

0 comments on commit 420de6d

Please sign in to comment.