Skip to content

Commit

Permalink
feat(pharmcat): add FDA PGx association recommendations
Browse files Browse the repository at this point in the history
- add FDA PGx Assocation recommendation data
- add new DataSourceType class to group recommendation datas
- rename recommendation data files to accommodate two FDA data types
  • Loading branch information
whaleyr committed Mar 12, 2024
1 parent 999d579 commit 768f874
Show file tree
Hide file tree
Showing 339 changed files with 15,307 additions and 457 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/pharmgkb/pharmcat/BaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.pharmgkb.common.util.CliHelper;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;


/**
Expand All @@ -40,7 +40,7 @@ public class BaseConfig {
boolean runReporter = true;
String reporterTitle;
boolean reporterCompact = true;
List<DataSource> reporterSources;
List<PrescribingGuidanceSource> reporterSources;
boolean reporterJson;
boolean reporterHtml = true;
Path outputDir;
Expand Down Expand Up @@ -93,7 +93,6 @@ public class BaseConfig {
topCandidateOnly = !cliHelper.hasOption("ma");

if (cliHelper.hasOption("research")) {
//noinspection UnstableApiUsage
List<String> types = sf_commaSplitter.splitToStream(Objects.requireNonNull(cliHelper.getValue("research")))
.map(String::toLowerCase)
.collect(Collectors.toList());
Expand Down Expand Up @@ -134,7 +133,7 @@ public class BaseConfig {
reporterSources = new ArrayList<>();
for (String src : sf_commaSplitter.splitToList(Objects.requireNonNull(cliHelper.getValue("rs")))) {
try {
reporterSources.add(DataSource.valueOf(src.toUpperCase()));
reporterSources.add(PrescribingGuidanceSource.valueOf(src));
} catch (IllegalArgumentException ex) {
throw new ReportableException("Unknown source: " + src);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/pharmgkb/pharmcat/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.pharmgkb.pharmcat.reporter.caller.Cyp2d6CopyNumberCaller;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.MessageAnnotation;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;
import org.pharmgkb.pharmcat.reporter.model.result.Haplotype;


Expand Down Expand Up @@ -68,6 +69,10 @@ public String getReferenceAllele(String gene) {
return m_phenotypeMap.getPhenotype(gene, source);
}

public @Nullable GenePhenotype getPhenotype(String gene, PrescribingGuidanceSource source) {
return m_phenotypeMap.getPhenotype(gene, source.getPhenoSource());
}


public PgkbGuidelineCollection getDrugs() {
return m_drugs;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/pharmgkb/pharmcat/Pipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.pharmgkb.pharmcat.reporter.ReportContext;
import org.pharmgkb.pharmcat.reporter.format.HtmlFormat;
import org.pharmgkb.pharmcat.reporter.format.JsonFormat;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;


/**
Expand Down Expand Up @@ -64,7 +64,7 @@ public enum Mode {
private Path m_reporterInputFile;
private String m_reporterTitle;
private boolean m_reporterCompact;
private List<DataSource> m_reporterSources;
private List<PrescribingGuidanceSource> m_reporterSources;
private Path m_reporterJsonFile;
private Path m_reporterHtmlFile;
private ReportContext m_reportContext;
Expand All @@ -83,7 +83,7 @@ public Pipeline(Env env,
boolean topCandidateOnly, boolean callCyp2d6, boolean findCombinations, boolean matcherHtml,
boolean runPhenotyper, @Nullable Path phenotyperInputFile, @Nullable Path phenotyperOutsideCallsFile,
boolean runReporter, @Nullable Path reporterInputFile, @Nullable String reporterTitle,
@Nullable List<DataSource> reporterSources, boolean reporterCompact, boolean reporterJson, boolean reporterHtml,
@Nullable List<PrescribingGuidanceSource> reporterSources, boolean reporterCompact, boolean reporterJson, boolean reporterHtml,
@Nullable Path outputDir, @Nullable String baseFilename, boolean deleteIntermediateFiles,
Mode mode, @Nullable String displayCount, boolean verbose) throws ReportableException {
m_env = env;
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/org/pharmgkb/pharmcat/reporter/MessageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.MatchLogic;
import org.pharmgkb.pharmcat.reporter.model.MessageAnnotation;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;
import org.pharmgkb.pharmcat.reporter.model.VariantReport;
import org.pharmgkb.pharmcat.reporter.model.result.AnnotationReport;
import org.pharmgkb.pharmcat.reporter.model.result.CallSource;
Expand Down Expand Up @@ -153,11 +154,11 @@ else if (!StringUtils.isBlank(match.getVariant()) &&
* @param drugReport a {@link DrugReport} to add message annotations to
* @param reportContext the report context to pull related information from
*/
public void addMatchingMessagesTo(DrugReport drugReport, ReportContext reportContext, DataSource source) {
public void addMatchingMessagesTo(DrugReport drugReport, ReportContext reportContext, PrescribingGuidanceSource source) {
Collection<MessageAnnotation> allMessages = m_drugMap.get(drugReport.getName()).stream()
.filter((ma) -> allowedForSource(ma, source))
.toList();
if (allMessages.size() == 0) {
if (allMessages.isEmpty()) {
return;
}
List<MessageAnnotation> reportAsGenotype = new ArrayList<>();
Expand All @@ -171,15 +172,15 @@ public void addMatchingMessagesTo(DrugReport drugReport, ReportContext reportCon
}
}

if (reportAsGenotype.size() > 0) {
if (!reportAsGenotype.isEmpty()) {
for (MessageAnnotation msgAnn : reportAsGenotype) {
String geneSymbol = msgAnn.getMatches().getGene();
String genotype = null;
for (GuidelineReport guidelineReport : drugReport.getGuidelines()) {
if (geneSymbol == null || guidelineReport.getGenes().contains(geneSymbol)) {
for (AnnotationReport annotationReport : guidelineReport.getAnnotations()) {
if (genotype == null) {
genotype = computeGenotype(msgAnn, reportContext, source);
genotype = computeGenotype(msgAnn, reportContext, source.getPhenoSource());
}
annotationReport.addHighlightedVariant(genotype);
}
Expand All @@ -189,18 +190,15 @@ public void addMatchingMessagesTo(DrugReport drugReport, ReportContext reportCon
}
}

private boolean allowedForSource(MessageAnnotation messageAnnotation, DataSource source) {
private boolean allowedForSource(MessageAnnotation messageAnnotation, PrescribingGuidanceSource source) {
String key = messageAnnotation.getName();
if (key.contains("cpic-") && source != DataSource.CPIC) {
if (key.contains("cpic-") && source != PrescribingGuidanceSource.CPIC_GUIDELINE) {
return false;
}
if (key.contains("dpwg-") && source != DataSource.DPWG) {
if (key.contains("dpwg-") && source != PrescribingGuidanceSource.DPWG_GUIDELINE) {
return false;
}
if (key.contains("fda-") && source != DataSource.FDA) {
return false;
}
return true;
return !key.contains("fda-") || source == PrescribingGuidanceSource.FDA_LABEL;
}


Expand Down Expand Up @@ -237,7 +235,7 @@ private String computeGenotype(MessageAnnotation msgAnn, ReportContext reportCon
* @return true if the message is a match, false otherwise
*/
private boolean matchDrugReport(MessageAnnotation message, ReportContext reportContext,
DataSource source) {
PrescribingGuidanceSource source) {
String gene = message.getMatches().getGene();
if (StringUtils.isBlank(gene)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.collect.TreeMultimap;
import org.pharmgkb.common.util.PathUtils;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;
import org.pharmgkb.pharmcat.reporter.model.pgkb.AccessionObject;
import org.pharmgkb.pharmcat.reporter.model.pgkb.GuidelinePackage;
import org.pharmgkb.pharmcat.util.DataSerializer;
Expand All @@ -41,7 +42,7 @@ public PgkbGuidelineCollection(Path dir) throws IOException {
stream.filter(f -> f.getFileName().toString().endsWith(".json"))
.forEach(annotationFiles::add);
}}
if (annotationFiles.size() == 0) {
if (annotationFiles.isEmpty()) {
throw new IOException("Cannot find annotations");
}

Expand All @@ -60,9 +61,9 @@ public List<GuidelinePackage> getGuidelinePackages() {
return f_guidelinePackages;
}

public List<GuidelinePackage> findGuidelinePackages(String chemicalName, DataSource source) {
public List<GuidelinePackage> findGuidelinePackages(String chemicalName, PrescribingGuidanceSource source) {
return f_guidelineMap.get(chemicalName).stream()
.filter(p -> p.getGuideline().getSource().equalsIgnoreCase(source.getPharmgkbName()))
.filter(p -> p.isDataSourceType(source))
.collect(Collectors.toList());
}

Expand Down
29 changes: 14 additions & 15 deletions src/main/java/org/pharmgkb/pharmcat/reporter/ReportContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.pharmgkb.pharmcat.Env;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.MessageAnnotation;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;
import org.pharmgkb.pharmcat.reporter.model.pgkb.GuidelinePackage;
import org.pharmgkb.pharmcat.reporter.model.result.DrugReport;
import org.pharmgkb.pharmcat.reporter.model.result.GeneReport;
Expand All @@ -30,8 +30,6 @@
* @author Ryan Whaley
*/
public class ReportContext {
private static final List<DataSource> DRUG_REPORT_SOURCES = ImmutableList.of(DataSource.CPIC, DataSource.DPWG, DataSource.FDA);

@Expose
@SerializedName("title")
private final String f_title;
Expand All @@ -52,7 +50,7 @@ public class ReportContext {
private final SortedMap<DataSource, SortedMap<String, GeneReport>> m_geneReports;
@Expose
@SerializedName("drugs")
private final SortedMap<DataSource, SortedMap<String, DrugReport>> m_drugReports = new TreeMap<>();
private final SortedMap<PrescribingGuidanceSource, SortedMap<String, DrugReport>> m_drugReports = new TreeMap<>();
@Expose
@SerializedName("messages")
private final List<MessageAnnotation> f_messages = new ArrayList<>();
Expand All @@ -70,12 +68,12 @@ public ReportContext(Env env, SortedMap<DataSource, SortedMap<String, GeneReport
m_cpicVersion = validateVersions(env.getDrugs(), DataSource.CPIC);
m_dpwgVersion = validateVersions(env.getDrugs(), DataSource.DPWG);

for (DataSource dataSource : DRUG_REPORT_SOURCES) {
Map<String, DrugReport> drugReports = m_drugReports.computeIfAbsent(dataSource, (s) -> new TreeMap<>());
for (PrescribingGuidanceSource dataSourceType : PrescribingGuidanceSource.values()) {
Map<String, DrugReport> drugReports = m_drugReports.computeIfAbsent(dataSourceType, (s) -> new TreeMap<>());
// go through all drugs, we iterate this way because one guideline may have multiple chemicals/drugs
for (String drugName : env.getDrugs().getGuidelineMap().keys()) {
List<GuidelinePackage> guidelinePackages = env.getDrugs().findGuidelinePackages(drugName, dataSource);
if (guidelinePackages != null && guidelinePackages.size() > 0) {
List<GuidelinePackage> guidelinePackages = env.getDrugs().findGuidelinePackages(drugName, dataSourceType);
if (guidelinePackages != null && !guidelinePackages.isEmpty()) {
DrugReport newDrugReport = new DrugReport(drugName, guidelinePackages, this);
drugReports.put(drugName.toLowerCase(), newDrugReport);
}
Expand All @@ -89,7 +87,7 @@ public ReportContext(Env env, SortedMap<DataSource, SortedMap<String, GeneReport
.flatMap((m) -> m.values().stream())
.forEach(messageHelper::addMatchingMessagesTo);
// to drug reports
for (DataSource source : m_drugReports.keySet()) {
for (PrescribingGuidanceSource source : m_drugReports.keySet()) {
for (DrugReport drugReport : m_drugReports.get(source).values()) {
messageHelper.addMatchingMessagesTo(drugReport, this, source);

Expand Down Expand Up @@ -150,7 +148,7 @@ private String validateVersions(PgkbGuidelineCollection guidelineCollection, Dat
*
* @return a map of {@link DrugReport} objects
*/
public Map<DataSource, SortedMap<String, DrugReport>> getDrugReports() {
public Map<PrescribingGuidanceSource, SortedMap<String, DrugReport>> getDrugReports() {
return m_drugReports;
}

Expand All @@ -168,8 +166,8 @@ public List<DrugReport> getDrugReports(String drug) {
.toList();
}

public @Nullable DrugReport getDrugReport(DataSource source, String drug) {
return m_drugReports.get(source).get(drug);
public @Nullable DrugReport getDrugReport(PrescribingGuidanceSource type, String drug) {
return m_drugReports.get(type).get(drug);
}

public List<GeneReport> getGeneReports(String gene) {
Expand All @@ -180,12 +178,13 @@ public List<GeneReport> getGeneReports(String gene) {
}

public @Nullable GeneReport getGeneReport(DataSource source, String gene) {
if (source == DataSource.FDA) {
return m_geneReports.get(DataSource.CPIC).get(gene);
}
return m_geneReports.get(source).get(gene);
}

public @Nullable GeneReport getGeneReport(PrescribingGuidanceSource source, String gene) {
return m_geneReports.get(source.getPhenoSource()).get(gene);
}

/**
* The user-freindly title for the report
* @return the title string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.helper.StringHelpers;
import com.github.jknack.handlebars.io.ClassPathTemplateLoader;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.SortedSetMultimap;
import com.google.common.collect.TreeMultimap;
Expand All @@ -31,6 +32,7 @@
import org.pharmgkb.pharmcat.reporter.handlebars.ReportHelpers;
import org.pharmgkb.pharmcat.reporter.model.DataSource;
import org.pharmgkb.pharmcat.reporter.model.MessageAnnotation;
import org.pharmgkb.pharmcat.reporter.model.PrescribingGuidanceSource;
import org.pharmgkb.pharmcat.reporter.model.result.CallSource;
import org.pharmgkb.pharmcat.reporter.model.result.DrugLink;
import org.pharmgkb.pharmcat.reporter.model.result.DrugReport;
Expand All @@ -48,7 +50,8 @@ public class HtmlFormat extends AbstractFormat {
private static final String sf_templatePrefix = "/org/pharmgkb/pharmcat/reporter";
private static final String sf_handlebarTemplateName = "report";
private static final boolean sf_compact_drugs = false;
private List<DataSource> m_sources = Lists.newArrayList(DataSource.CPIC, DataSource.DPWG, DataSource.FDA);
private Set<DataSource> m_geneSources = ImmutableSet.of(DataSource.CPIC, DataSource.DPWG);
private List<PrescribingGuidanceSource> m_sources = PrescribingGuidanceSource.listValues();
private boolean m_compact;
private final boolean f_testMode;

Expand All @@ -63,8 +66,11 @@ public HtmlFormat(Path outputPath, Env env, boolean testMode) {
f_testMode = testMode;
}

public HtmlFormat sources(List<DataSource> sources) {
public HtmlFormat sources(List<PrescribingGuidanceSource> sources) {
if (sources != null) {
m_geneSources = sources.stream()
.map(PrescribingGuidanceSource::getPhenoSource)
.collect(Collectors.toSet());
m_sources = sources;
}
return this;
Expand Down Expand Up @@ -122,7 +128,7 @@ private Map<String,Object> compile(ReportContext reportContext) {
SortedSetMultimap<String, GeneReport> geneReportMap = TreeMultimap.create();
Map<String, Map<String, String>> functionMap = new HashMap<>();
for (DataSource source : new TreeSet<>(reportContext.getGeneReports().keySet())) {
if (!m_sources.contains(source)) {
if (!m_geneSources.contains(source)) {
continue;
}
for (GeneReport geneReport : reportContext.getGeneReports().get(source).values()) {
Expand Down Expand Up @@ -151,7 +157,7 @@ private Map<String,Object> compile(ReportContext reportContext) {
}

// skip gene reports that aren't related to any drugs
if (geneReport.getRelatedDrugs().size() == 0) {
if (geneReport.getRelatedDrugs().isEmpty()) {
continue;
}

Expand Down Expand Up @@ -225,7 +231,7 @@ private Map<String,Object> compile(ReportContext reportContext) {

// Section II: Prescribing Recommendations
SortedMap<String, Recommendation> recommendationMap = new TreeMap<>();
for (DataSource source : reportContext.getDrugReports().keySet()) {
for (PrescribingGuidanceSource source : reportContext.getDrugReports().keySet()) {
if (!m_sources.contains(source)) {
continue;
}
Expand Down
Loading

0 comments on commit 768f874

Please sign in to comment.