Skip to content

Commit

Permalink
Update search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinlu3 committed Jan 2, 2024
1 parent 4657f47 commit 4282296
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 184 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private static Set<Evidence> getEvidence(ReferenceGenome referenceGenome, Eviden

if (query.getGene() != null) {
genes.add(query.getGene());
if (query.getExactMatchedAlteration() == null && query.getAlterations().isEmpty() && query.getAlleles().isEmpty()) {
if ((query.getExactMatchedAlteration() != null && query.getExactMatchedAlteration().getAlteration().length() == 0) && query.getAlterations().isEmpty() && query.getAlleles().isEmpty()) {
alterations.addAll(AlterationUtils.getAllAlterations(referenceGenome, query.getGene()));
} else {
if (query.getAlterations() != null) {
Expand Down Expand Up @@ -394,6 +394,8 @@ private static Set<Evidence> filterEvidence(Set<Evidence> evidences, EvidenceQue
//Add all gene specific evidences
if (evidence.getAlterations().isEmpty()) {
filtered.add(evidence);
} else if (evidenceQuery.getExactMatchedAlteration() != null && StringUtils.isEmpty(evidenceQuery.getExactMatchedAlteration().getAlteration())) {
filtered.add(evidence);
} else {
boolean hasjointed = !Collections.disjoint(evidence.getAlterations(), evidenceQuery.getAlterations());
if (!hasjointed) {
Expand Down
87 changes: 48 additions & 39 deletions core/src/main/java/org/mskcc/cbio/oncokb/util/IndicatorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.mskcc.cbio.oncokb.util.LevelUtils.getTherapeuticLevelsWithPriorityLIstIterator;
import static org.mskcc.cbio.oncokb.util.SummaryUtils.allelesToStr;
Expand Down Expand Up @@ -276,38 +277,39 @@ public static IndicatorQueryResp processQuery(Query query,
indicatorQuery.setMutationEffect(mutationEffectResp);
}
}
}

if (hasTreatmentEvidence) {
if (StringUtils.isEmpty(query.getTumorType())) {
treatmentEvidences = EvidenceUtils.getRelevantEvidences(query, matchedAlt,
selectedTreatmentEvidence, levels, relevantAlterationsWithoutAlternativeAlleles, alleles);
} else {
treatmentEvidences = EvidenceUtils.keepHighestLevelForSameTreatments(
EvidenceUtils.getRelevantEvidences(query, matchedAlt,
selectedTreatmentEvidence, levels, relevantAlterationsWithoutAlternativeAlleles, alleles), query.getReferenceGenome(), matchedAlt);
}
// Set implications
if (hasTreatmentEvidence) {
if (StringUtils.isEmpty(query.getTumorType())) {
treatmentEvidences = EvidenceUtils.getRelevantEvidences(query, matchedAlt,
selectedTreatmentEvidence, levels, relevantAlterationsWithoutAlternativeAlleles, alleles);
} else {
treatmentEvidences = EvidenceUtils.keepHighestLevelForSameTreatments(
EvidenceUtils.getRelevantEvidences(query, matchedAlt,
selectedTreatmentEvidence, levels, relevantAlterationsWithoutAlternativeAlleles, alleles), query.getReferenceGenome(), matchedAlt);
}
}

if (hasDiagnosticImplicationEvidence) {
List<Implication> implications = new ArrayList<>();
implications.addAll(getImplications(matchedAlt, alleles, relevantAlterationsWithoutAlternativeAlleles, EvidenceType.DIAGNOSTIC_IMPLICATION, matchedTumorType, StringUtils.isEmpty(query.getTumorType()) ? null : relevantDownwardTumorTypes, query.getHugoSymbol(), Collections.singleton(LevelOfEvidence.LEVEL_Dx1)));

// For Dx2 and Dx3, the logic is the same as Tx/Px
Set<LevelOfEvidence> levelOfEvidences = new HashSet<>();
levelOfEvidences.add(LevelOfEvidence.LEVEL_Dx2);
levelOfEvidences.add(LevelOfEvidence.LEVEL_Dx3);
implications.addAll(getImplications(matchedAlt, alleles, relevantAlterationsWithoutAlternativeAlleles, EvidenceType.DIAGNOSTIC_IMPLICATION, matchedTumorType, StringUtils.isEmpty(query.getTumorType()) ? null : relevantUpwardTumorTypes, query.getHugoSymbol(), levelOfEvidences));
indicatorQuery.setDiagnosticImplications(implications);
if (indicatorQuery.getDiagnosticImplications().size() > 0) {
indicatorQuery.setHighestDiagnosticImplicationLevel(LevelUtils.getHighestDiagnosticImplicationLevel(indicatorQuery.getDiagnosticImplications().stream().map(implication -> implication.getLevelOfEvidence()).collect(Collectors.toSet())));
}
if (gene != null && hasDiagnosticImplicationEvidence) {
List<Implication> implications = new ArrayList<>();
implications.addAll(getImplications(gene, matchedAlt, alleles, relevantAlterationsWithoutAlternativeAlleles, EvidenceType.DIAGNOSTIC_IMPLICATION, matchedTumorType, StringUtils.isEmpty(query.getTumorType()) ? null : relevantDownwardTumorTypes, query.getHugoSymbol(), Collections.singleton(LevelOfEvidence.LEVEL_Dx1)));

// For Dx2 and Dx3, the logic is the same as Tx/Px
Set<LevelOfEvidence> levelOfEvidences = new HashSet<>();
levelOfEvidences.add(LevelOfEvidence.LEVEL_Dx2);
levelOfEvidences.add(LevelOfEvidence.LEVEL_Dx3);
implications.addAll(getImplications(gene, matchedAlt, alleles, relevantAlterationsWithoutAlternativeAlleles, EvidenceType.DIAGNOSTIC_IMPLICATION, matchedTumorType, StringUtils.isEmpty(query.getTumorType()) ? null : relevantUpwardTumorTypes, query.getHugoSymbol(), levelOfEvidences));
indicatorQuery.setDiagnosticImplications(implications);
if (indicatorQuery.getDiagnosticImplications().size() > 0) {
indicatorQuery.setHighestDiagnosticImplicationLevel(LevelUtils.getHighestDiagnosticImplicationLevel(indicatorQuery.getDiagnosticImplications().stream().map(implication -> implication.getLevelOfEvidence()).collect(Collectors.toSet())));
}
}

if (hasPrognosticImplicationEvidence) {
indicatorQuery.setPrognosticImplications(getImplications(matchedAlt, alleles, relevantAlterationsWithoutAlternativeAlleles, EvidenceType.PROGNOSTIC_IMPLICATION, matchedTumorType, StringUtils.isEmpty(query.getTumorType()) ? null : relevantUpwardTumorTypes, query.getHugoSymbol(), null));
if (indicatorQuery.getPrognosticImplications().size() > 0) {
indicatorQuery.setHighestPrognosticImplicationLevel(LevelUtils.getHighestPrognosticImplicationLevel(indicatorQuery.getPrognosticImplications().stream().map(implication -> implication.getLevelOfEvidence()).collect(Collectors.toSet())));
}
if (gene != null && hasPrognosticImplicationEvidence) {
indicatorQuery.setPrognosticImplications(getImplications(gene, matchedAlt, alleles, relevantAlterationsWithoutAlternativeAlleles, EvidenceType.PROGNOSTIC_IMPLICATION, matchedTumorType, StringUtils.isEmpty(query.getTumorType()) ? null : relevantUpwardTumorTypes, query.getHugoSymbol(), null));
if (indicatorQuery.getPrognosticImplications().size() > 0) {
indicatorQuery.setHighestPrognosticImplicationLevel(LevelUtils.getHighestPrognosticImplicationLevel(indicatorQuery.getPrognosticImplications().stream().map(implication -> implication.getLevelOfEvidence()).collect(Collectors.toSet())));
}
}

Expand Down Expand Up @@ -536,23 +538,30 @@ private static List<Implication> getImplicationFromEvidence(List<Evidence> evide
return implications;
}

private static List<Implication> getImplications(Alteration matchedAlt, List<Alteration> alternativeAlleles, List<Alteration> relevantAlterations, EvidenceType evidenceType, TumorType matchedTumorType, List<TumorType> tumorTypes, String queryHugoSymbol, Set<LevelOfEvidence> levelOfEvidences) {
private static List<Implication> getImplications(Gene gene, Alteration matchedAlt, List<Alteration> alternativeAlleles, List<Alteration> relevantAlterations, EvidenceType evidenceType, TumorType matchedTumorType, List<TumorType> tumorTypes, String queryHugoSymbol, Set<LevelOfEvidence> levelOfEvidences) {
List<Implication> implications = new ArrayList<>();

// Find alteration specific evidence
List<Evidence> selfAltEvis = EvidenceUtils.getEvidence(Collections.singletonList(matchedAlt), Collections.singleton(evidenceType), matchedTumorType, tumorTypes, levelOfEvidences);
if (selfAltEvis != null && selfAltEvis.size() > 0) {
implications.addAll(getImplicationFromEvidence(selfAltEvis, queryHugoSymbol));
}
if (matchedAlt != null && !StringUtils.isEmpty(matchedAlt.getAlteration())) {
// Find alteration specific evidence
List<Evidence> selfAltEvis = EvidenceUtils.getEvidence(Collections.singletonList(matchedAlt), Collections.singleton(evidenceType), matchedTumorType, tumorTypes, levelOfEvidences);
if (selfAltEvis != null && selfAltEvis.size() > 0) {
implications.addAll(getImplicationFromEvidence(selfAltEvis, queryHugoSymbol));
}

List<Alteration> listToBeRemoved = new ArrayList<>(alternativeAlleles);
listToBeRemoved.add(matchedAlt);
List<Alteration> listToBeRemoved = new ArrayList<>(alternativeAlleles);
listToBeRemoved.add(matchedAlt);

for (Alteration alt : AlterationUtils.removeAlterationsFromList(relevantAlterations, listToBeRemoved)) {
List<Evidence> altEvis = EvidenceUtils.getEvidence(Collections.singletonList(alt), Collections.singleton(evidenceType), matchedTumorType, tumorTypes, levelOfEvidences);
if (altEvis != null && altEvis.size() > 0) {
implications.addAll(getImplicationFromEvidence(altEvis, queryHugoSymbol));
for (Alteration alt : AlterationUtils.removeAlterationsFromList(relevantAlterations, listToBeRemoved)) {
List<Evidence> altEvis = EvidenceUtils.getEvidence(Collections.singletonList(alt), Collections.singleton(evidenceType), matchedTumorType, tumorTypes, levelOfEvidences);
if (altEvis != null && altEvis.size() > 0) {
implications.addAll(getImplicationFromEvidence(altEvis, queryHugoSymbol));
}
}
} else {
Set<Evidence> geneEvisSet = EvidenceUtils.getEvidenceByGeneAndEvidenceTypes(gene, Stream.of(evidenceType).collect(Collectors.toSet()));
List<Evidence> geneEvis = new ArrayList<>();
geneEvis.addAll(geneEvisSet);
implications.addAll(getImplicationFromEvidence(geneEvis, queryHugoSymbol));
}
return filterImplication(implications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ResponseEntity<List<IndicatorQueryResp>> searchPost(
@RequestMapping(value = "/search/actionableGenes",
produces = {"application/json"},
method = RequestMethod.GET)
ResponseEntity<LinkedHashSet<ActionableGeneSearchResp>> actionableGenesSearchGet(
ResponseEntity<LinkedHashSet<IndicatorQueryResp>> actionableGenesSearchGet(
@ApiParam(value = "The search query, it could be hugoSymbol, entrezGeneId, variant or cancer type. At least two characters. Maximum two keywords are supported, separated by space", required = true) @RequestParam(value = "query") String query,
@ApiParam(value = "The limit of returned result.") @RequestParam(value = "limit", required = false) Integer limit
);
Expand Down
Loading

0 comments on commit 4282296

Please sign in to comment.