From e481b1b3e4cff0de6527175546197023976c17c3 Mon Sep 17 00:00:00 2001 From: Calvin Lu <59149377+calvinlu3@users.noreply.github.com> Date: Fri, 2 Aug 2024 16:29:02 -0400 Subject: [PATCH] Retire relevantCancerTypes in favor of excludedRCTs field --- .../controller/DriveAnnotationParser.java | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/web/src/main/java/org/mskcc/cbio/oncokb/controller/DriveAnnotationParser.java b/web/src/main/java/org/mskcc/cbio/oncokb/controller/DriveAnnotationParser.java index e287e1e2f..fcb6d8075 100644 --- a/web/src/main/java/org/mskcc/cbio/oncokb/controller/DriveAnnotationParser.java +++ b/web/src/main/java/org/mskcc/cbio/oncokb/controller/DriveAnnotationParser.java @@ -53,12 +53,12 @@ synchronized void getEvidence( } } - private static final String LAST_REVIEW_EXTENSION = "_validateTime"; private static final String LAST_EDIT_EXTENSION = "_review"; private static final String UUID_EXTENSION = "_uuid"; private static final String SOLID_PROPAGATION_KEY = "propagation"; private static final String LIQUID_PROPAGATION_KEY = "propagationLiquid"; private static final String FDA_LEVEL_KEY = "fdaLevel"; + private static final String EXCLUDED_RCTS_KEY = "excludedRCTs"; public void parseVUS(Gene gene, JSONArray vus, Integer nestLevel) throws JSONException { System.out.println(spaceStrByNestLevel(nestLevel) + "Variants of unknown significance"); @@ -400,10 +400,8 @@ private void parseMutation(Gene gene, JSONObject mutationObj, Integer nestLevel) excludedCancerTypes = getTumorTypes(cancers.getJSONObject(i).getJSONArray("excludedCancerTypes")); } - List relevantCancerTypes = new ArrayList<>(); - if (cancers.getJSONObject(i).has("relevantCancerTypes")) { - relevantCancerTypes = getTumorTypes(cancers.getJSONObject(i).getJSONArray("relevantCancerTypes")); - } + List relevantCancerTypes = getRelevantCancerTypesIfExistsFromJsonObject(cancers.getJSONObject(i), tumorTypes, excludedCancerTypes, null); + parseCancer(gene, alterations, cancers.getJSONObject(i), tumorTypes, excludedCancerTypes, relevantCancerTypes, nestLevel + 1); } } @@ -570,6 +568,7 @@ private void parseCancer(Gene gene, Set alterations, JSONObject canc EvidenceType.DIAGNOSTIC_IMPLICATION, nestLevel + 1); // diagnostic summary + List diagnosticRCT = getRelevantCancerTypesIfExistsFromJsonObject(cancerObj.getJSONObject("diagnostic"), tumorTypes, excludedCancerTypes, diagnosticEvidence == null ? null : diagnosticEvidence.getLevelOfEvidence()); saveDxPxSummaries( cancerObj, "diagnosticSummary", @@ -577,20 +576,21 @@ private void parseCancer(Gene gene, Set alterations, JSONObject canc alterations, tumorTypes, excludedCancerTypes, - cancerObj.has("diagnostic") && cancerObj.getJSONObject("diagnostic").has("relevantCancerTypes") ? getTumorTypes(cancerObj.getJSONObject("diagnostic").getJSONArray("relevantCancerTypes")) : relevantCancerTypes, + cancerObj.has("diagnostic") ? diagnosticRCT: relevantCancerTypes, EvidenceType.DIAGNOSTIC_SUMMARY, nestLevel, diagnosticEvidence == null ? null : diagnosticEvidence.getLevelOfEvidence() ); // prognostic summary + List prognosticRCT = getRelevantCancerTypesIfExistsFromJsonObject(cancerObj.getJSONObject("prognostic"), tumorTypes, excludedCancerTypes, prognosticEvidence == null ? null : prognosticEvidence.getLevelOfEvidence()); saveDxPxSummaries(cancerObj, "prognosticSummary", gene, alterations, tumorTypes, excludedCancerTypes, - cancerObj.has("prognostic") && cancerObj.getJSONObject("prognostic").has("relevantCancerTypes") ? getTumorTypes(cancerObj.getJSONObject("prognostic").getJSONArray("relevantCancerTypes")) : relevantCancerTypes, + cancerObj.has("prognostic") ? prognosticRCT : relevantCancerTypes, EvidenceType.PROGNOSTIC_SUMMARY, nestLevel, prognosticEvidence == null ? null : prognosticEvidence.getLevelOfEvidence() @@ -828,8 +828,9 @@ private void parseTherapeuticImplications(Gene gene, Set alterations evidence.setExcludedCancerTypes(new HashSet<>(excludedCancerTypes)); } - if (drugObj.has("relevantCancerTypes")) { - evidence.setRelevantCancerTypes(new HashSet<>(getTumorTypes(drugObj.getJSONArray("relevantCancerTypes")))); + List drugRCT = getRelevantCancerTypesIfExistsFromJsonObject(drugObj, tumorTypes, excludedCancerTypes, evidence.getLevelOfEvidence()); + if (drugRCT.size() > 0) { + evidence.setRelevantCancerTypes(new HashSet<>(drugRCT)); } else if (relevantCancerTypes != null) { evidence.setRelevantCancerTypes(new HashSet<>(relevantCancerTypes)); } @@ -865,8 +866,9 @@ private Evidence parseImplication(Gene gene, Set alterations, List(getTumorTypes(implication.getJSONArray("relevantCancerTypes")))); + List implicationRCT = getRelevantCancerTypesIfExistsFromJsonObject(implication, tumorTypes, excludedCancerTypes, evidence.getLevelOfEvidence()); + if (implicationRCT.size() > 0) { + evidence.setRelevantCancerTypes(new HashSet<>(implicationRCT)); } else if (relevantCancerTypes != null && relevantCancerTypes.size() > 0) { evidence.setRelevantCancerTypes(new HashSet<>(relevantCancerTypes)); } else if (LevelOfEvidence.LEVEL_Dx1.equals(evidence.getLevelOfEvidence())) { @@ -1021,4 +1023,35 @@ private ImmutablePair getEvidenceTypeAndKnownEffectFromDru return new ImmutablePair(evidenceType, type); } + + private List getRelevantCancerTypes(List tumorTypes, List excludedTumorTypes, LevelOfEvidence level, List excludedRelevantCancerTypes) { + RelevantTumorTypeDirection direction = level != null && LevelOfEvidence.LEVEL_Dx1.equals(level) ? RelevantTumorTypeDirection.UPWARD : RelevantTumorTypeDirection.DOWNWARD; + + Set queriedTumorTypes = tumorTypes.stream().map(tt -> { + return TumorTypeUtils.findRelevantTumorTypes(TumorTypeUtils.getTumorTypeName(tt), StringUtils.isEmpty(tt.getSubtype()), direction); + }) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + + Set queriedExcludedTumorTypes = excludedTumorTypes.stream().map(ett -> { + return TumorTypeUtils.findRelevantTumorTypes(TumorTypeUtils.getTumorTypeName(ett), StringUtils.isEmpty(ett.getSubtype()), direction); + }) + .flatMap(Collection::stream) + .collect(Collectors.toSet()); + + queriedTumorTypes.removeAll(queriedExcludedTumorTypes); + queriedTumorTypes.removeAll(excludedRelevantCancerTypes); + + + return new ArrayList<>(queriedTumorTypes); + } + + private List getRelevantCancerTypesIfExistsFromJsonObject(JSONObject jsonObject, List tumorTypes, List excludedCancerTypes, LevelOfEvidence level) throws JSONException, Exception { + List relevantCancerTypes = new ArrayList<>(); + if (jsonObject.has(EXCLUDED_RCTS_KEY)) { + List excludedRCT = getTumorTypes(jsonObject.getJSONArray(EXCLUDED_RCTS_KEY)); + relevantCancerTypes = getRelevantCancerTypes(tumorTypes, excludedCancerTypes, level, excludedRCT); + } + return relevantCancerTypes; + } }