Skip to content

Commit

Permalink
Rfc80/fix patient level filtering for alteration counts endpoints (#1…
Browse files Browse the repository at this point in the history
…0857)

* Add patient_id column to genomic_event_derived

* Update sql to convert list of patients to list of samples
  • Loading branch information
haynescd authored Jun 24, 2024
1 parent a484e2e commit 14b7105
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/main/resources/db-scripts/clickhouse/clickhouse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ CREATE TABLE IF NOT EXISTS genomic_event_derived
driver_tiers_filter LowCardinality(String),
cna_alteration Nullable(Int8),
cna_cytoband String,
sv_event_info String
sv_event_info String,
patient_unique_id String
) ENGINE = MergeTree
ORDER BY ( variant_type, hugo_gene_symbol, genetic_profile_stable_id, sample_unique_id);

Expand Down
16 changes: 12 additions & 4 deletions src/main/resources/db-scripts/clickhouse/clickhouse_migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) AS sample_uniqu
'NA' AS drivet_tiers_filter,
NULL AS cna_alteration,
'' AS cna_cytoband,
'' AS sv_event_info
'' AS sv_event_info,
concat(cs.cancer_study_identifier, '_', patient.stable_id) AS patient_unique_id
FROM mutation
INNER JOIN mutation_event AS me ON mutation.mutation_event_id = me.mutation_event_id
INNER JOIN sample_profile sp
Expand All @@ -49,6 +50,7 @@ FROM mutation
LEFT JOIN genetic_profile g ON sp.genetic_profile_id = g.genetic_profile_id
INNER JOIN cancer_study cs ON g.cancer_study_id = cs.cancer_study_id
INNER JOIN sample ON mutation.sample_id = sample.internal_id
INNER JOIN patient on sample.patient_id = patient.internal_id
LEFT JOIN gene ON mutation.entrez_gene_id = gene.entrez_gene_id
UNION ALL
SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) AS sample_unique_id,
Expand All @@ -64,14 +66,16 @@ SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) AS sample_uniqu
'NA' AS drivet_tiers_filter,
ce.alteration AS cna_alteration,
rgg.cytoband AS cna_cytoband,
'' AS sv_event_info
'' AS sv_event_info,
concat(cs.cancer_study_identifier, '_', patient.stable_id) AS patient_unique_id
FROM cna_event ce
INNER JOIN sample_cna_event sce ON ce.cna_event_id = sce.cna_event_id
INNER JOIN sample_profile sp ON sce.sample_id = sp.sample_id AND sce.genetic_profile_id = sp.genetic_profile_id
LEFT JOIN gene_panel gp ON sp.panel_id = gp.internal_id
INNER JOIN genetic_profile g ON sp.genetic_profile_id = g.genetic_profile_id
INNER JOIN cancer_study cs ON g.cancer_study_id = cs.cancer_study_id
INNER JOIN sample ON sce.sample_id = sample.internal_id
INNER JOIN patient on sample.patient_id = patient.internal_id
INNER JOIN gene ON ce.entrez_gene_id = gene.entrez_gene_id
INNER JOIN reference_genome_gene rgg ON rgg.entrez_gene_id = ce.entrez_gene_id
UNION ALL
Expand All @@ -88,10 +92,12 @@ SELECT concat(cs.cancer_study_identifier, '_', s.stable_id) AS sample_unique_id,
'NA' AS drivet_tiers_filter,
NULL AS cna_alteration,
'' AS cna_cytoband,
event_info AS sv_event_info
event_info AS sv_event_info,
concat(cs.cancer_study_identifier, '_', patient.stable_id) AS patient_unique_id
FROM structural_variant sv
INNER JOIN genetic_profile gp ON sv.genetic_profile_id = gp.genetic_profile_id
INNER JOIN sample s ON sv.sample_id = s.internal_id
INNER JOIN patient on s.patient_id = patient.internal_id
INNER JOIN cancer_study cs ON gp.cancer_study_id = cs.cancer_study_id
INNER JOIN gene ON sv.site1_entrez_gene_id = gene.entrez_gene_id
INNER JOIN sample_profile ON s.internal_id = sample_profile.sample_id AND sample_profile.genetic_profile_id = sv.genetic_profile_id
Expand All @@ -110,10 +116,12 @@ SELECT concat(cs.cancer_study_identifier, '_', s.stable_id) AS sample_unique_id,
'NA' AS drivet_tiers_filter,
NULL AS cna_alteration,
'' AS cna_cytoband,
event_info AS sv_event_info
event_info AS sv_event_info,
concat(cs.cancer_study_identifier, '_', patient.stable_id) AS patient_unique_id
FROM structural_variant sv
INNER JOIN genetic_profile gp ON sv.genetic_profile_id = gp.genetic_profile_id
INNER JOIN sample s ON sv.sample_id = s.internal_id
INNER JOIN patient on s.patient_id = patient.internal_id
INNER JOIN cancer_study cs ON gp.cancer_study_id = cs.cancer_study_id
INNER JOIN gene ON sv.site2_entrez_gene_id = gene.entrez_gene_id
INNER JOIN sample_profile ON s.internal_id = sample_profile.sample_id AND sample_profile.genetic_profile_id = sv.genetic_profile_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@
<where>
stgp.alteration_type = '${alterationType}'
AND
<include refid="applyStudyViewFilter"/>
sample_unique_id IN ( <include refid="sampleUniqueIdsFromStudyViewFilter"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="getSampleIdsFromPatientIds"/>
</if>
)
</where>
</select>

Expand All @@ -306,8 +310,13 @@
select distinct gene_panel_id
from sample_to_gene_panel
<where>
alteration_type = '${alterationType}' AND
<include refid="applyStudyViewFilter"/>
alteration_type = '${alterationType}'
AND
sample_unique_id IN ( <include refid="sampleUniqueIdsFromStudyViewFilter"/>
<if test="applyPatientIdFilters == true">
INTERSECT <include refid="getSampleIdsFromPatientIds"/>
</if>
)
</where>
)
</where>
Expand Down

0 comments on commit 14b7105

Please sign in to comment.