Q (haiku): How many patients have a shallow deletion for SMARCA4 in the POG study? ▶ read_guide { "uri": "cbioportal://sample-filtering-guide" } ▶ list_studies { "search": "POG" } ◀ result # Sample and Study Filtering Guide ## Overview Proper filtering is essential for meaningful cBioPortal analysis. This guide covers filtering by studies, sample types, and other criteria. ## Study-Level Filtering ### 1. Always Filter by Study Every query should specify a study to ensure consistent results: ```sql -- Always include study filtering SELECT * FROM your_table WHERE cancer_study_identifier = 'your_study_id' -- Additional filters... ``` ### 2. Find Available Studies ```sql -- Discover available studies SELECT cancer_study_identifier, name, description, type_of_cancer_id FROM cancer_study ORDER BY cancer_study_identifier; ``` ### 3. Study Information ```sql -- Get detailed study information SELECT cs.cancer_study_identifier, cs.name as study_name, cs.description, cs.sample_count, COUNT(DISTINCT p.internal_id) as patient_count FROM cancer_study cs LEFT JOIN patient p ON cs.cancer_study_id = p.cancer_study_id WHERE cs.cancer_study_identifier = 'your_study_id' GROUP BY cs.cancer_study_identifier, cs.name, cs.description, cs.sample_count; ``` ### 4. Find Studies by Available Data Types Use this when the user asks *"which studies have mutation and copy-number data for X"*, *"studies with expression for Y"*, *"is there any imaging data"*, or any *"studies with Z data"* question. `cancer_study` has one precomputed sample count per data type — filter on them. No join and no schema exploration needed. These are the same counts as the portal's study list and its "Data type" filter. **Canonical query — studies with ALL requested data types for a cancer type:** ```sql SELECT cancer_study_identifier, name, sample_count, mutation_sample_count, cna_sample_count FROM cancer_study WHERE type_of_cancer_id = 'luad' -- ← OncoTree code from search_oncotree AND mutation_sample_count > 0 -- ← one condition per required data type AND cna_sample_count > 0 ORDER BY sample_count DESC; ``` **Data type → column** (a count of 0 means the study doesn't have that data): | Data type in the user's question | Column (portal "Data type" filter label) | |---|---| | samples in the study | `sample_count` | | mutation / mutations | `mutation_sample_count` ("Mutations") | | copy-number / CNA / amplification / deletion | `cna_sample_count` ("CNA") | | structural variant / fusion | `structural_variant_sample_count` | | RNA / mRNA / gene expression (any platform) | `mrna_expression_sample_count` — use this for "which studies have expression data" | | specifically the portal's "RNA-Seq" filter | `rna_seq_sample_count` ("RNA-Seq") — counts only the `_rna_seq_v2_mrna` list; 0 for many GDC and iAtlas studies that do have RNA-Seq | | specifically the portal's "RNA (microarray)" filter | `mrna_microarray_sample_count` ("RNA (microarray)") — counts only the `_mrna` list | | microRNA | `mirna_sample_count` ("miRNA") | | protein / RPPA | `rppa_sample_count` ("RPPA") | | mas … (7866 more chars) ◀ result {"result":[{"cancer_study_identifier":"pog570_bcgsc_2020","name":"Pan-cancer Analysis of Advanced and Metastatic Tumors (BCGSC, Nature Cancer 2020)","type_of_cancer_id":"mixed","sample_count":570,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=pog570_bcgsc_2020"}]} ▶ clickhouse_list_table_columns { "table": "genomic_event_derived" } ✗ error Error: No such tool available: mcp__clickhouse_list_table_columns ▶ clickhouse_list_table_columns { "table": "genetic_alteration_derived" } ✗ error Error: No such tool available: mcp__clickhouse_list_table_columns ▶ clickhouse_list_table_columns { "table": "genomic_event_derived" } ▶ clickhouse_list_table_columns { "table": "genetic_alteration_derived" } ◀ result {"columns":[{"name":"sample_unique_id","type":"String"},{"name":"hugo_gene_symbol","type":"String","comment":"HUGO gene symbol (e.g., TP53, KRAS, BRAF). Use for gene-specific queries."},{"name":"entrez_gene_id","type":"Int32"},{"name":"gene_panel_stable_id","type":"LowCardinality(String)"},{"name":"cancer_study_identifier","type":"LowCardinality(String)"},{"name":"genetic_profile_stable_id","type":"LowCardinality(String)"},{"name":"variant_type","type":"LowCardinality(String)","comment":"Type of genomic event: \"mutation\" for SNVs/indels, \"cna\" for copy number alterations, \"structural_variant\" for SVs. Always filter by this."},{"name":"mutation_variant","type":"String","comment":"Protein change notation (e.g., p.V600E, p.R175H). Use for specific variant queries. \"NA\" for non-mutation events."},{"name":"mutation_type","type":"LowCardinality(String)"},{"name":"mutation_status","type":"LowCardinality(String)","comment":"For mutations: Somatic, Germline, UNKNOWN, or UNCALLED. Filter mutation_status != \"UNCALLED\" to exclude uncertain calls. Include all other statuses."},{"name":"driver_filter","type":"LowCardinality(String)"},{"name":"driver_filter_annotation","type":"String"},{"name":"driver_tiers_filter","type":"LowCardinality(String)"},{"name":"driver_tiers_filter_annotation","type":"String"},{"name":"cna_alteration","type":"Nullable(Int8)","comment":"Copy number alteration: only 2 = amplification (AMP) and -2 = deep deletion (HOMDEL) are stored. Shallow deletion (-1), diploid (0) and gain (1) are not in this table; query genetic_alteration_derived WHERE profile_type = 'gistic' (alteration_value is a String, e.g. '-1'). NULL for non-CNA events."},{"name":"cna_cytoband","type":"String"},{"name":"sv_event_info","type":"String"},{"name":"patient_unique_id","type":"String"},{"name":"off_panel","type":"Bool","comment":"Boolean: 1 = mutation outside gene panel coverage (off-panel), 0 = within panel (on-panel). Filter off_panel = 0 for reliable frequency calculations."}]} ◀ result {"columns":[{"name":"sample_unique_id","type":"String"},{"name":"cancer_study_identifier","type":"LowCardinality(String)"},{"name":"hugo_gene_symbol","type":"String"},{"name":"profile_type","type":"LowCardinality(String)"},{"name":"alteration_value","type":"Nullable(String)"}]} ▶ clickhouse_run_select_query { "query": " SELECT COUNT(DISTINCT p.patient_unique_id) AS patient_count, COUNT(DISTINCT g.sample_unique_id) AS sample_count FROM genetic_alteration_derived g JOIN patient p ON g.sample_unique_id = SUBSTR(p.patient_id, 1, LENGTH(p.patient_id) - 3) WHERE g.cancer_study_identifier = 'pog570_bcgsc_2020' AND g.hugo_gene_symbol = 'SMARCA4' AND g.profile_type = 'gistic' AND g.alteration_value = '-1' ", "max_rows": 10 } ◀ result {"error_message":"Query execution failed: HTTPDriver for https://dl96orhu96.us-east-1.aws.clickhouse.cloud:8443 received ClickHouse error code 47\n Code: 47. DB::Exception: Identifier 'p.patient_id' cannot be resolved from table with name p. In scope SELECT COUNTDistinct(p.patient_unique_id) AS patient_count, COUNTDistinct(g.sample_unique_id) AS sample_count FROM genetic_alteration_derived AS g INNER JOIN patient AS p ON g.sample_unique_id = SUBSTR(p.patient_id, 1, LENGTH(p.patient_id) - 3) WHERE (g.cancer_study_identifier = 'pog570_bcgsc_2020') AND (g.hugo_gene_symbol = 'SMARCA4') AND (g.profile_type = 'gistic') AND (g.alteration_value = '-1'). (UNKNOWN_IDENTIFIER) (version 26.4.1.2359 (official build))\n"} ▶ clickhouse_list_table_columns { "table": "patient" } ◀ result {"columns":[{"name":"internal_id","type":"Int64","comment":"Primary key. Unique internal identifier for the patient."},{"name":"stable_id","type":"String","comment":"Stable patient identifier within the study. Combined with cancer_study_identifier forms patient_unique_id."},{"name":"cancer_study_id","type":"Int64","comment":"Foreign key to cancer_study.cancer_study_id. Links patient to their study."}]} ▶ clickhouse_list_table_columns { "table": "sample" } ◀ result {"columns":[{"name":"internal_id","type":"Int64","comment":"Primary key. Unique internal identifier for the sample."},{"name":"stable_id","type":"String","comment":"Stable identifier for the sample within the study. Combined with cancer_study_identifier forms sample_unique_id."},{"name":"patient_id","type":"Int64","comment":"Foreign key to patient.internal_id. Links sample to its patient."}]} ▶ clickhouse_run_select_query { "query": " SELECT COUNT(DISTINCT p.internal_id) AS patient_count, COUNT(DISTINCT s.internal_id) AS sample_count FROM genetic_alteration_derived g JOIN sample s ON g.sample_unique_id = CONCAT(cs.cancer_study_identifier, '_', s.stable_id) JOIN patient p ON s.patient_id = p.internal_id JOIN cancer_study cs ON p.cancer_study_id = cs.cancer_study_id WHERE g.cancer_study_identifier = 'pog570_bcgsc_2020' AND g.hugo_gene_symbol = 'SMARCA4' AND g.profile_type = 'gistic' AND g.alteration_value = '-1' ", "max_rows": 10 } ◀ result {"error_message":"Query execution failed: HTTPDriver for https://dl96orhu96.us-east-1.aws.clickhouse.cloud:8443 received ClickHouse error code 47\n Code: 47. DB::Exception: Unknown expression or function identifier `cs.cancer_study_identifier` in scope SELECT COUNTDistinct(p.internal_id) AS patient_count, COUNTDistinct(s.internal_id) AS sample_count FROM genetic_alteration_derived AS g INNER JOIN sample AS s ON g.sample_unique_id = CONCAT(cs.cancer_study_identifier, '_', s.stable_id) INNER JOIN patient AS p ON s.patient_id = p.internal_id INNER JOIN cancer_study AS cs ON p.cancer_study_id = cs.cancer_study_id WHERE (g.cancer_study_identifier = 'pog570_bcgsc_2020') AND (g.hugo_gene_symbol = 'SMARCA4') AND (g.profile_type = 'gistic') AND (g.alteration_value = '-1'). Maybe you meant: ['g.cancer_study_identifier']. (UNKNOWN_IDENTIFIER) (version 26.4.1.2359 (official build))\n"} ▶ clickhouse_run_select_query { "query": " WITH smarca4_shallow_del AS ( SELECT DISTINCT sample_unique_id, hugo_gene_symbol FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value = '-1' ) SELECT COUNT(*) AS samples_with_shallow_deletion, hugo_gene_symbol FROM smarca4_shallow_del GROUP BY hugo_gene_symbol ", "max_rows": 10 } ◀ result {"rows":[{"samples_with_shallow_deletion":111,"hugo_gene_symbol":"SMARCA4"}]} ▶ clickhouse_run_select_query { "query": " WITH smarca4_shallow_del AS ( SELECT DISTINCT sample_unique_id FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value = '-1' ), samples_to_patients AS ( SELECT DISTINCT SUBSTR(sd.sample_unique_id, 1, POSITION('_' IN sd.sample_unique_id) - 1) as study_id, SUBSTR(sd.sample_unique_id, POSITION('_' IN sd.sample_unique_id) + 1) as sample_id FROM smarca4_shallow_del sd ) SELECT COUNT(DISTINCT sample_unique_id) as samples, uniqExact(SUBSTR(sample_unique_id, POSITION('_' IN sample_unique_id) + 1, POSITION('_' IN REVERSE(SUBSTR(sample_unique_id, POSITION('_' IN sample_unique_id) + 1))) - 1)) as patient_count FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value = '-1' ", "max_rows": 10 } ◀ result {"rows":[{"samples":111,"patient_count":1}]} ▶ clickhouse_run_select_query { "query": " SELECT sample_unique_id, COUNT(*) as count FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value = '-1' GROUP BY sample_unique_id LIMIT 20 ", "max_rows": 100 } ◀ result {"rows":[{"sample_unique_id":"pog570_bcgsc_2020_24295","count":1},{"sample_unique_id":"pog570_bcgsc_2020_25501","count":1},{"sample_unique_id":"pog570_bcgsc_2020_24177","count":1},{"sample_unique_id":"pog570_bcgsc_2020_30491","count":1},{"sample_unique_id":"pog570_bcgsc_2020_30311","count":1},{"sample_unique_id":"pog570_bcgsc_2020_28638","count":1},{"sample_unique_id":"pog570_bcgsc_2020_37719","count":1},{"sample_unique_id":"pog570_bcgsc_2020_28131","count":1},{"sample_unique_id":"pog570_bcgsc_2020_18843","count":1},{"sample_unique_id":"pog570_bcgsc_2020_31509","count":1},{"sample_unique_id":"pog570_bcgsc_2020_31043","count":1},{"sample_unique_id":"pog570_bcgsc_2020_31518","count":1},{"sample_unique_id":"pog570_bcgsc_2020_33532","count":1},{"sample_unique_id":"pog570_bcgsc_2020_36700","count":1},{"sample_unique_id":"pog570_bcgsc_2020_33740","count":1},{"sample_unique_id":"pog570_bcgsc_2020_28012","count":1},{"sample_unique_id":"pog570_bcgsc_2020_13268","count":1},{"sample_unique_id":"pog570_bcgsc_2020_30897","count":1},{"sample_unique_id":"pog570_bcgsc_2020_33033","count":1},{"sample_unique_id":"pog570_bcgsc_2020_23737","count":1}]} ▶ clickhouse_run_select_query { "query": " SELECT COUNT(DISTINCT sample_unique_id) as samples_with_shallow_deletion FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value = '-1' ", "max_rows": 10 } ◀ result {"rows":[{"samples_with_shallow_deletion":111}]} ▶ clickhouse_run_select_query { "query": " WITH smarca4_samples AS ( SELECT DISTINCT sample_unique_id FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value = '-1' ) SELECT COUNT(DISTINCT patient_unique_id) as patient_count, COUNT(DISTINCT sample_unique_id) as sample_count FROM clinical_data_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND sample_unique_id IN (SELECT sample_unique_id FROM smarca4_samples) ", "max_rows": 10 } ◀ result {"rows":[{"patient_count":111,"sample_count":111}]} ═ answer (success) Perfect! Now I have the answer. Let me provide the result: ## Answer **111 patients** in the POG (Pan-cancer Analysis of Advanced and Metastatic Tumors) study have a shallow deletion (−1 copy) for **SMARCA4**. **Study:** Pan-cancer Analysis of Advanced and Metastatic Tumors (BCGSC, Nature Cancer 2020) - 570 total samples **Shallow deletion definition:** In the gistic CNA profile, alteration value = −1 represents heterozygous loss (shallow deletion).