Q (sonnet): How many patients have a shallow deletion for SMARCA4 in the POG study? ▶ list_studies { "search": "POG" } ◀ 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"}]} ▶ read_guide { "uri": "cbioportal://mutation-frequency-guide" } ▶ read_guide { "uri": "cbioportal://sample-filtering-guide" } ◀ result # Mutation Frequency Analysis Guide ## IMPORTANT: Reporting Mutation Frequencies - **ALWAYS report frequencies as percentages**, not raw counts: `frequency = (altered_samples / total_profiled_samples) × 100` - For quick frequency lookups, **prefer the TCGA Pan-Cancer Atlas study first**, then offer to expand to other studies - When reporting across multiple studies, show **ranges** (e.g., "TP53 is mutated in 30–60% of samples") rather than a single average - **NEVER** sum mutation events across studies to compute an aggregate frequency — this can exceed 100% due to double-counting - Warn users that samples may overlap across cohorts (e.g., MSK studies may share patients) - **Choose and state the counting unit**: use patient-level frequencies for prevalence/rate questions unless the user explicitly asks for samples; use sample-level frequencies when the user asks about samples. - **For "across cancer types" questions**, jump to the [Cross-Cancer-Type Mutation Frequency](#cross-cancer-type-mutation-frequency) section below — there is one correct recipe and several common wrong ones. ## Counting Unit: Samples vs Patients Before answering any mutation count or frequency question, decide whether the unit is samples or patients and state that choice in the answer. | User wording | Counting unit | |--------------|---------------| | "prevalence", "rate", "fraction of patients", "patients with", "how common is" | Patient-level: `COUNT(DISTINCT patient_unique_id)` | | "samples", "specimens", "biopsies", sample-level cohort composition | Sample-level: `COUNT(DISTINCT sample_unique_id)` | | Ambiguous | Ask, or default to patient-level for prevalence/rate language and say so | ### Cross-study sample-count caveat When an answer touches more than one study and reports a sample count, prepend a one-line caveat: > Sample IDs are unique within cBioPortal study prefixes, not guaranteed biological-sample identifiers across studies; overlapping cohorts can count the same patient/sample more than once. Prefer one of these safer approaches: - Use a shipped `cancer_study_query_preferences` cohort such as `pan_cancer_tcga` or `all_studies_non_redundant`. - Restrict to one named study. - Aggregate by `patient_unique_id` when the biological question is patient prevalence. ## STOP rule: a frequency above 100% means your query is wrong If your query returns a frequency over 100%, **do not try to debug or explain the data inconsistency to the user**. The cause is always one of these query bugs: - Summing mutation events instead of `COUNT(DISTINCT sample_unique_id)` for the numerator - Using a study-wide sample count as the denominator instead of the gene-specific profiled count - Cross-study aggregation where the same biological sample appears under multiple `sample_unique_id` values (e.g., MSK-IMPACT and MSK-CHORD share patients) - **Joining the profiled CTE through `gene_panel` / `gene_panel_list` without a WES branch.** `gene_panel_id = 'WES'` is *not* a row in … (36467 more chars) ◀ 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) ▶ clickhouse_run_select_query { "query": " SELECT profile_type, alteration_value, count() AS samples FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' GROUP BY profile_type, alteration_value ORDER BY profile_type, alteration_value " } ◀ result {"rows":[{"profile_type":"gistic","alteration_value":"-1","samples":111},{"profile_type":"gistic","alteration_value":"-2","samples":4},{"profile_type":"gistic","alteration_value":"0","samples":394},{"profile_type":"gistic","alteration_value":"1","samples":58},{"profile_type":"gistic","alteration_value":"2","samples":3},{"profile_type":"rna_seq_mrna","alteration_value":"0.2641","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"0.5447","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"0.5689","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.0218","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.3562","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.4979","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.5261","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.7784","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.8345","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"1.9753","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.031","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.0647","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.071","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.1535","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.1539","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.1559","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.1633","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.1713","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.1728","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.2087","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.2272","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.2613","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.2934","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.3038","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.3261","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.3288","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.3812","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.4197","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.4464","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.4662","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.4739","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.499","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.5376","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.5814","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.5816","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.6932","samples":1},{"profile_type":"rna_seq_mrna","alteration_value":"10.7156","sam … (4533 more chars) ▶ clickhouse_run_select_query { "query": " SELECT uniqExact(gad.sample_unique_id) AS shallow_del_samples, uniqExact(cd.patient_unique_id) AS shallow_del_patients FROM genetic_alteration_derived gad JOIN (SELECT DISTINCT sample_unique_id, patient_unique_id FROM clinical_data_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020') cd ON gad.sample_unique_id = cd.sample_unique_id WHERE gad.cancer_study_identifier = 'pog570_bcgsc_2020' AND gad.hugo_gene_symbol = 'SMARCA4' AND gad.profile_type = 'gistic' AND gad.alteration_value = '-1' " } ◀ result {"rows":[{"shallow_del_samples":111,"shallow_del_patients":111}]} ▶ clickhouse_run_select_query { "query": " SELECT count() AS profiled_samples FROM genetic_alteration_derived WHERE cancer_study_identifier = 'pog570_bcgsc_2020' AND hugo_gene_symbol = 'SMARCA4' AND profile_type = 'gistic' AND alteration_value NOT IN ('', 'NA') " } ◀ result {"rows":[{"profiled_samples":570}]} ▶ resolve_and_route { "studyIds": [ "pog570_bcgsc_2020" ] } ◀ result {"success":true,"message":"Found 1 study. Use the metadata to call the appropriate navigation tool(s).","data":{"totalCount":1,"studiesWithMetadata":[{"studyId":"pog570_bcgsc_2020","name":"Pan-cancer Analysis of Advanced and Metastatic Tumors (BCGSC, Nature Cancer 2020)","sampleCount":570,"studyViewUrl":"https://www.cbioportal.org/study?id=pog570_bcgsc_2020","metadata":{"clinicalAttributeIds":["AGE","ANALYSIS_COHORT","BIOPSY_COHORT","BIOPSY_SITE","CANCER_TYPE","CANCER_TYPE_DETAILED","GENDER","HRD_SCORE","ICI","ICI_BEST_RESPONSE","ICI_DURABLE_CLINICAL_BENEFIT","ICI_MUTATION_CATEGORY","MSI_SCORE","MUTATION_COUNT","ONCOTREE_CODE","OS_MONTHS","OS_STATUS","PRIMARY_SITE","SAMPLE_COUNT","SAMPLE_TYPE","SOMATIC_STATUS","TMB_NONSYNONYMOUS","TREATED_WITH_ICI","TREATMENT_CATEGORY","TUMOR_CONTENT","T_CELLS_CD4_MEMORY_ACTIVATED","T_CELLS_CD4_MEMORY_RESTING","T_CELLS_CD4_NAIVE","T_CELLS_CD8","T_CELLS_FOLLICULAR_HELPER","T_CELLS_GAMMA_DELTA","T_CELLS_REGULATORY_TREGS"],"molecularProfileIds":["pog570_bcgsc_2020_gistic","pog570_bcgsc_2020_mutations","pog570_bcgsc_2020_rna_seq_mrna","pog570_bcgsc_2020_rna_seq_mrna_median_all_sample_Zscores","pog570_bcgsc_2020_structural_variants"],"genericAssayProfiles":["pog570_bcgsc_2020_immune_cell_signature"],"heatmapProfileIds":["pog570_bcgsc_2020_rna_seq_mrna_median_all_sample_Zscores"],"availableComparisonTabs":["overlap","clinical","survival","alterations","mutations","mrna","generic_assay_immune_cell_signature"]}}]}} ▶ navigate_to_study_view { "studyIds": [ "pog570_bcgsc_2020" ], "filterJson": { "genomicDataFilters": [ { "hugoGeneSymbol": "SMARCA4", "profileType": "gistic", "values": [ { "value": "-1" } ] } ] } } ◀ result {"success":true,"message":"Navigating to https://www.cbioportal.org/study/summary?id=pog570_bcgsc_2020#filterJson=%7B%22genomicDataFilters%22%3A%5B%7B%22hugoGeneSymbol%22%3A%22SMARCA4%22%2C%22profileType%22%3A%22gistic%22%2C%22values%22%3A%5B%7B%22value%22%3A%22-1%22%7D%5D%7D%5D%7D","url":"https://www.cbioportal.org/study/summary?id=pog570_bcgsc_2020#filterJson=%7B%22genomicDataFilters%22%3A%5B%7B%22hugoGeneSymbol%22%3A%22SMARCA4%22%2C%22profileType%22%3A%22gistic%22%2C%22values%22%3A%5B%7B%22value%22%3A%22-1%22%7D%5D%7D%5D%7D","data":{"studyIds":["pog570_bcgsc_2020"],"studies":[{"studyId":"pog570_bcgsc_2020","name":"Pan-cancer Analysis of Advanced and Metastatic Tumors (BCGSC, Nature Cancer 2020)","sampleCount":570}],"tab":"summary","hasFilters":true,"hasPlotsConfig":false,"pageDescription":"Overview of all study data displayed as interactive charts summarizing available clinical and genomic data. Click within a chart to filter. Additional charts may be available in the Charts menu."}} ═ answer (success) [View SMARCA4 shallow deletion cohort in POG570](https://www.cbioportal.org/study/summary?id=pog570_bcgsc_2020#filterJson=%7B%22genomicDataFilters%22%3A%5B%7B%22hugoGeneSymbol%22%3A%22SMARCA4%22%2C%22profileType%22%3A%22gistic%22%2C%22values%22%3A%5B%7B%22value%22%3A%22-1%22%7D%5D%7D%5D%7D) This filters the study cohort to the 111 patients with SMARCA4 shallow deletion, letting you explore their clinical and genomic characteristics interactively.