Skip to content

Commit

Permalink
resolve issue cBioPortal#5613 fixing mutated genes table shows incorr…
Browse files Browse the repository at this point in the history
…ect frequencies
  • Loading branch information
khzhu committed May 14, 2019
1 parent 4ccece8 commit ebafefa
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ List<MutationCountByGene> getSampleCountByEntrezGeneIdsAndSampleIds(String molec
List<MutationCountByGene> getSampleCountInMultipleMolecularProfiles(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneIds);

List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForMutationOrFusion(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneIds,
Boolean fusionOnly);

List<MutationCountByGene> getPatientCountByEntrezGeneIdsAndSampleIds(String molecularProfileId,
List<String> patientIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ List<MutationCountByGene> getPatientCountByEntrezGeneIdsAndSampleIds(String mole
List<String> patientIds,
List<Integer> entrezGeneIds,
Boolean snpOnly);

List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForMutationOrFusion(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneIds,
Boolean fusionOnly);

MutationCountByPosition getMutationCountByPosition(Integer entrezGeneId, Integer proteinPosStart,
Integer proteinPosEnd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public List<MutationCountByGene> getSampleCountInMultipleMolecularProfiles(List<
return mutationMapper.getSampleCountInMultipleMolecularProfiles(molecularProfileIds, sampleIds, entrezGeneIds, null);
}

@Override
public List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForMutationOrFusion(List<String> molecularProfileIds,
List<String> sampleIds, List<Integer> entrezGeneIds,
Boolean fusionOnly) {

return mutationMapper.getSampleCountInMultipleMolecularProfilesForMutationOrFusion(molecularProfileIds,
sampleIds, entrezGeneIds, fusionOnly);
}

@Override
public List<MutationCountByGene> getPatientCountByEntrezGeneIdsAndSampleIds(String molecularProfileId,
List<String> patientIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,65 @@
GROUP BY mutation.ENTREZ_GENE_ID
</select>

<select id="getSampleCountInMultipleMolecularProfilesForMutationOrFusion" resultType="org.cbioportal.model.MutationCountByGene">
SELECT
mutation.ENTREZ_GENE_ID AS entrezGeneId,
gene.HUGO_GENE_SYMBOL AS hugoGeneSymbol,
COUNT(*) AS totalCount,
COUNT(DISTINCT(mutation.SAMPLE_ID)) AS countByEntity
FROM mutation
INNER JOIN mutation_event ON mutation_event.MUTATION_EVENT_ID = mutation.MUTATION_EVENT_ID
INNER JOIN genetic_profile ON mutation.GENETIC_PROFILE_ID = genetic_profile.GENETIC_PROFILE_ID
INNER JOIN sample ON mutation.SAMPLE_ID = sample.INTERNAL_ID
INNER JOIN gene ON mutation.ENTREZ_GENE_ID = gene.ENTREZ_GENE_ID
WHERE
<if test="sampleIds != null and !sampleIds.isEmpty()">
mutation.SAMPLE_ID IN (
SELECT sample.INTERNAL_ID from sample
INNER JOIN patient ON sample.PATIENT_ID = patient.INTERNAL_ID
INNER JOIN genetic_profile ON patient.CANCER_STUDY_ID = genetic_profile.CANCER_STUDY_ID
WHERE
<if test="@java.util.Arrays@stream(molecularProfileIds.toArray()).distinct().count() == 1">
genetic_profile.STABLE_ID = #{molecularProfileIds[0]} AND
sample.STABLE_ID IN
<foreach item="item" collection="sampleIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="@java.util.Arrays@stream(molecularProfileIds.toArray()).distinct().count() > 1">
(sample.STABLE_ID, genetic_profile.STABLE_ID) IN
<foreach index="i" collection="sampleIds" open="(" separator="," close=")">
(#{sampleIds[${i}]}, #{molecularProfileIds[${i}]})
</foreach>
AND genetic_profile.STABLE_ID IN
<foreach item="item" collection="molecularProfileIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
AND sample.INTERNAL_ID = mutation.SAMPLE_ID
AND genetic_profile.GENETIC_PROFILE_ID = mutation.GENETIC_PROFILE_ID)
</if>
<if test="sampleIds == null">
genetic_profile.STABLE_ID IN
<foreach item="item" collection="molecularProfileIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="entrezGeneIds != null and !entrezGeneIds.isEmpty()">
AND mutation.ENTREZ_GENE_ID IN
<foreach item="item" collection="entrezGeneIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="fusionOnly == false">
AND mutation_event.MUTATION_TYPE != 'Fusion'
</if>
<if test="fusionOnly == true">
AND mutation_event.MUTATION_TYPE = 'Fusion'
</if>
GROUP BY mutation.ENTREZ_GENE_ID
</select>

<select id="getPatientCountByEntrezGeneIdsAndSampleIds" resultType="org.cbioportal.model.MutationCountByGene">
SELECT
mutation.ENTREZ_GENE_ID AS entrezGeneId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ List<MutationCountByGene> getSampleCountInMultipleMolecularProfiles(List<String>
List<Integer> entrezGeneIds,
boolean includeFrequency);

List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForMutation(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneId);

List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForFusion(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneId);

List<MutationCountByGene> getPatientCountByEntrezGeneIdsAndSampleIds(String molecularProfileId,
List<String> patientIds,
List<Integer> entrezGeneIds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,37 @@ public List<MutationCountByGene> getSampleCountInMultipleMolecularProfiles(List<
return result;
}

@Override
public List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForMutation(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneIds) {
List<MutationCountByGene> result;
if (molecularProfileIds.isEmpty()) {
result = Collections.emptyList();
} else {
result = mutationRepository.getSampleCountInMultipleMolecularProfilesForMutationOrFusion(
molecularProfileIds, sampleIds, entrezGeneIds, false);
geneFrequencyCalculator.calculate(molecularProfileIds, sampleIds, result);
}
return result;
}

@Override
public List<MutationCountByGene> getSampleCountInMultipleMolecularProfilesForFusion(List<String> molecularProfileIds,
List<String> sampleIds,
List<Integer> entrezGeneIds) {

List<MutationCountByGene> result;
if (molecularProfileIds.isEmpty()) {
result = Collections.emptyList();
} else {
result = mutationRepository.getSampleCountInMultipleMolecularProfilesForMutationOrFusion(
molecularProfileIds, sampleIds, entrezGeneIds,true);
}

return result;
}

@Override
public List<MutationCountByGene> getPatientCountByEntrezGeneIdsAndSampleIds(String molecularProfileId,
List<String> patientIds,
Expand Down
37 changes: 35 additions & 2 deletions web/src/main/java/org/cbioportal/web/StudyViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public ResponseEntity<List<MutationCountByGene>> fetchMutatedGenes(
List<String> studyIds = new ArrayList<>();
List<String> sampleIds = new ArrayList<>();
studyViewFilterUtil.extractStudyAndSampleIds(filteredSampleIdentifiers, studyIds, sampleIds);
result = mutationService.getSampleCountInMultipleMolecularProfiles(molecularProfileService
.getFirstMutationProfileIds(studyIds, sampleIds), sampleIds, null, true);
result = mutationService.getSampleCountInMultipleMolecularProfilesForMutation(molecularProfileService
.getFirstMutationProfileIds(studyIds, sampleIds), sampleIds, null);
result.sort((a, b) -> b.getCountByEntity() - a.getCountByEntity());
List<String> distinctStudyIds = studyIds.stream().distinct().collect(Collectors.toList());
if (distinctStudyIds.size() == 1 && !result.isEmpty()) {
Expand All @@ -208,6 +208,39 @@ public ResponseEntity<List<MutationCountByGene>> fetchMutatedGenes(

return new ResponseEntity<>(result, HttpStatus.OK);
}

@PreAuthorize("hasPermission(#studyViewFilter, 'StudyViewFilter', 'read')")
@RequestMapping(value = "/fusion-genes/fetch", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Fetch fusion genes by study view filter")
public ResponseEntity<List<MutationCountByGene>> fetchFusionGenes(
@ApiParam(required = true, value = "Study view filter")
@Valid @RequestBody StudyViewFilter studyViewFilter) throws StudyNotFoundException {

List<SampleIdentifier> filteredSampleIdentifiers = studyViewFilterApplier.apply(studyViewFilter);
List<MutationCountByGene> result = new ArrayList<>();
if (!filteredSampleIdentifiers.isEmpty()) {
List<String> studyIds = new ArrayList<>();
List<String> sampleIds = new ArrayList<>();
studyViewFilterUtil.extractStudyAndSampleIds(filteredSampleIdentifiers, studyIds, sampleIds);
result = mutationService.getSampleCountInMultipleMolecularProfilesForFusion(molecularProfileService
.getFirstMutationProfileIds(studyIds, sampleIds), sampleIds, null);
result.sort((a, b) -> b.getCountByEntity() - a.getCountByEntity());
List<String> distinctStudyIds = studyIds.stream().distinct().collect(Collectors.toList());
if (distinctStudyIds.size() == 1 && !result.isEmpty()) {
Map<Integer, MutSig> mutSigMap = significantlyMutatedGeneService.getSignificantlyMutatedGenes(
distinctStudyIds.get(0), Projection.SUMMARY.name(), null, null, null, null).stream().collect(
Collectors.toMap(MutSig::getEntrezGeneId, Function.identity()));
result.forEach(r -> {
if (mutSigMap.containsKey(r.getEntrezGeneId())) {
r.setqValue(mutSigMap.get(r.getEntrezGeneId()).getqValue());
}
});
}
}

return new ResponseEntity<>(result, HttpStatus.OK);
}

@PreAuthorize("hasPermission(#studyViewFilter, 'StudyViewFilter', 'read')")
@RequestMapping(value = "/cna-genes/fetch", method = RequestMethod.POST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public void fetchMutatedGenes() throws Exception {
mutationCount2.setTotalCount(2);
mutationCounts.add(mutationCount2);

Mockito.when(mutationService.getSampleCountInMultipleMolecularProfiles(Mockito.anyListOf(String.class),
Mockito.anyListOf(String.class), Mockito.anyListOf(Integer.class), Mockito.anyBoolean())).thenReturn(mutationCounts);
Mockito.when(mutationService.getSampleCountInMultipleMolecularProfilesForMutation(Mockito.anyListOf(String.class),
Mockito.anyListOf(String.class), Mockito.anyListOf(Integer.class))).thenReturn(mutationCounts);

StudyViewFilter studyViewFilter = new StudyViewFilter();
studyViewFilter.setStudyIds(Arrays.asList(TEST_STUDY_ID));
Expand Down

0 comments on commit ebafefa

Please sign in to comment.