Skip to content

Commit

Permalink
Put calculation back into SQL for simpler code
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan committed Jun 21, 2024
1 parent 4d72818 commit 454bf20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,11 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilte
// Error handling may need to be added
for (GenomicDataFilter genomicDataFilter : genomicDataFilters) {
Map<String, Integer> counts = studyViewRepository.getMutationCounts(studyViewFilter, categorizedClinicalDataCountFilter, genomicDataFilter);
int totalCount = counts.getOrDefault("totalCount", 0);
int profiledCount = counts.getOrDefault("profiledCount", 0);
int mutatedCount = counts.getOrDefault("mutatedCount", 0);
int notMutatedCount = profiledCount - mutatedCount;
int notProfiledCount = totalCount - profiledCount;

List<GenomicDataCount> genomicDataCountList = List.of(
new GenomicDataCount("Mutated", "MUTATED", mutatedCount, mutatedCount),
new GenomicDataCount("Not Mutated", "NOT_MUTATED", notMutatedCount, notMutatedCount),
new GenomicDataCount("Not Profiled", "NOT_PROFILED", notProfiledCount, notProfiledCount)
new GenomicDataCount("Mutated", "MUTATED", counts.get("mutatedCount"), counts.get("mutatedCount")),
new GenomicDataCount("Not Mutated", "NOT_MUTATED", counts.get("notMutatedCount"), counts.get("notMutatedCount")),
new GenomicDataCount("Not Profiled", "NOT_PROFILED", counts.get("notProfiledCount"), counts.get("notProfiledCount"))
);

genomicDataCountItemList.add(new GenomicDataCountItem(genomicDataFilter.getHugoGeneSymbol(), "mutations", genomicDataCountList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,31 +219,31 @@

<!-- for /mutation-data-counts/fetch (returns GenomicDataCountItem objects) mutation counts pie chart part -->
<select id="getMutationCounts">
WITH total_samples as (
SELECT DISTINCT sample_unique_id
WITH total_count as (
SELECT count(distinct sample_unique_id)
FROM sample_to_gene_panel
WHERE sample_unique_id IN (<include refid="sampleUniqueIdsFromStudyViewFilter"/>)
),
profiled_samples as (
SELECT DISTINCT stgp.sample_unique_id
profiled_count as (
SELECT count(distinct stgp.sample_unique_id)
FROM sample_to_gene_panel stgp
JOIN gene_panel_to_gene gpg ON stgp.gene_panel_id = gpg.gene_panel_id
WHERE
sample_unique_id IN (<include refid="sampleUniqueIdsFromStudyViewFilter"/>)
AND gpg.gene = #{genomicDataFilter.hugoGeneSymbol}
),
mutated_samples as (
SELECT DISTINCT sample_unique_id
mutated_count as (
SELECT count(distinct sample_unique_id)
FROM genomic_event_derived
WHERE
sample_unique_id IN (<include refid="sampleUniqueIdsFromStudyViewFilter"/>)
AND hugo_gene_symbol = #{genomicDataFilter.hugoGeneSymbol}
AND variant_type = 'mutation'
)
SELECT
cast((SELECT count(*) FROM total_samples) as INTEGER) as totalCount,
cast((SELECT count(*) FROM profiled_samples) as INTEGER) as profiledCount,
cast((SELECT count(*) FROM mutated_samples) as INTEGER) as mutatedCount
cast((SELECT * FROM mutated_count) as INTEGER) as mutatedCount,
cast(((SELECT * FROM profiled_count) - (SELECT * FROM mutated_count)) as INTEGER) as notMutatedCount,
cast(((SELECT * FROM total_count) - (SELECT * FROM profiled_count)) as INTEGER) as notProfiledCount
</select>

<!-- for /mutation-data-counts/fetch - (returns GenomicDataCountItem objects) mutation type counts table part-->
Expand Down

0 comments on commit 454bf20

Please sign in to comment.