Skip to content

Commit

Permalink
Retire relevantCancerTypes in favor of excludedRCTs field
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinlu3 committed Aug 5, 2024
1 parent acfbf2f commit e481b1b
Showing 1 changed file with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -400,10 +400,8 @@ private void parseMutation(Gene gene, JSONObject mutationObj, Integer nestLevel)
excludedCancerTypes = getTumorTypes(cancers.getJSONObject(i).getJSONArray("excludedCancerTypes"));
}

List<TumorType> relevantCancerTypes = new ArrayList<>();
if (cancers.getJSONObject(i).has("relevantCancerTypes")) {
relevantCancerTypes = getTumorTypes(cancers.getJSONObject(i).getJSONArray("relevantCancerTypes"));
}
List<TumorType> relevantCancerTypes = getRelevantCancerTypesIfExistsFromJsonObject(cancers.getJSONObject(i), tumorTypes, excludedCancerTypes, null);

parseCancer(gene, alterations, cancers.getJSONObject(i), tumorTypes, excludedCancerTypes, relevantCancerTypes, nestLevel + 1);
}
}
Expand Down Expand Up @@ -570,27 +568,29 @@ private void parseCancer(Gene gene, Set<Alteration> alterations, JSONObject canc
EvidenceType.DIAGNOSTIC_IMPLICATION, nestLevel + 1);

// diagnostic summary
List<TumorType> diagnosticRCT = getRelevantCancerTypesIfExistsFromJsonObject(cancerObj.getJSONObject("diagnostic"), tumorTypes, excludedCancerTypes, diagnosticEvidence == null ? null : diagnosticEvidence.getLevelOfEvidence());
saveDxPxSummaries(
cancerObj,
"diagnosticSummary",
gene,
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<TumorType> 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()
Expand Down Expand Up @@ -828,8 +828,9 @@ private void parseTherapeuticImplications(Gene gene, Set<Alteration> alterations
evidence.setExcludedCancerTypes(new HashSet<>(excludedCancerTypes));
}

if (drugObj.has("relevantCancerTypes")) {
evidence.setRelevantCancerTypes(new HashSet<>(getTumorTypes(drugObj.getJSONArray("relevantCancerTypes"))));
List<TumorType> 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));
}
Expand Down Expand Up @@ -865,8 +866,9 @@ private Evidence parseImplication(Gene gene, Set<Alteration> alterations, List<T
addDateToLastEditSetFromObject(lastEditDates, implication, "level");
}

if (implication.has("relevantCancerTypes")) {
evidence.setRelevantCancerTypes(new HashSet<>(getTumorTypes(implication.getJSONArray("relevantCancerTypes"))));
List<TumorType> 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())) {
Expand Down Expand Up @@ -1021,4 +1023,35 @@ private ImmutablePair<EvidenceType, String> getEvidenceTypeAndKnownEffectFromDru

return new ImmutablePair<EvidenceType, String>(evidenceType, type);
}

private List<TumorType> getRelevantCancerTypes(List<TumorType> tumorTypes, List<TumorType> excludedTumorTypes, LevelOfEvidence level, List<TumorType> excludedRelevantCancerTypes) {
RelevantTumorTypeDirection direction = level != null && LevelOfEvidence.LEVEL_Dx1.equals(level) ? RelevantTumorTypeDirection.UPWARD : RelevantTumorTypeDirection.DOWNWARD;

Set<TumorType> queriedTumorTypes = tumorTypes.stream().map(tt -> {
return TumorTypeUtils.findRelevantTumorTypes(TumorTypeUtils.getTumorTypeName(tt), StringUtils.isEmpty(tt.getSubtype()), direction);
})
.flatMap(Collection::stream)
.collect(Collectors.toSet());

Set<TumorType> 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<TumorType> getRelevantCancerTypesIfExistsFromJsonObject(JSONObject jsonObject, List<TumorType> tumorTypes, List<TumorType> excludedCancerTypes, LevelOfEvidence level) throws JSONException, Exception {
List<TumorType> relevantCancerTypes = new ArrayList<>();
if (jsonObject.has(EXCLUDED_RCTS_KEY)) {
List<TumorType> excludedRCT = getTumorTypes(jsonObject.getJSONArray(EXCLUDED_RCTS_KEY));
relevantCancerTypes = getRelevantCancerTypes(tumorTypes, excludedCancerTypes, level, excludedRCT);
}
return relevantCancerTypes;
}
}

0 comments on commit e481b1b

Please sign in to comment.