Q (sonnet-5.5): give me a contingency table with the number of lung cancer patients with EGFR and/or KRAS alterations ▶ read_guide { "uri": "cbioportal://statistical-tests-guide" } ▶ read_guide { "uri": "cbioportal://mutation-frequency-guide" } ◀ result Statistical Test Selection Guide ================================ Purpose ------- This guide ensures the correct statistical test is selected before performing any group comparison, matching cBioPortal's own Group Comparison defaults. HARD RULES — NEVER FABRICATE A STATISTIC ---------------------------------------- ClickHouse cannot run statistical tests. The agent therefore must NEVER produce a derived statistic that is not a literal column value from a SQL result. Specifically: 1. **Never invent a p-value.** Not "p < 0.001", not "p ≈ 0.05", not any p-value. If the user asks "what is the p-value?", the answer is *"I can't compute that — here is the 2x2 contingency table (or group statistics). Run it in cBioPortal's Group Comparison tab, in R with `fisher.test(...)` / `wilcox.test(...)`, or in Python with `scipy.stats.fisher_exact(...)` / `mannwhitneyu(...)`."* 2. **Never claim mutual exclusivity (or co-occurrence) from a contingency table alone.** A 2x2 table is not a test. The shape "altered/not altered × group A/group B" needs Fisher's exact + a defined direction (odds ratio < 1 with significant p). Without that test, the agent presents the table and stops. Descriptive phrasing is also a claim: "largely/mostly mutually exclusive", "rarely co-occur", "tend to co-occur" are forbidden without the test — point to cBioPortal's Mutual Exclusivity tab instead. 3. **Never report a "median" that came from `AVG(...)` or any non-median aggregate.** "Median" and "mean" are different statistics; for skewed clinical distributions (especially survival) they differ substantially. Use ClickHouse's `quantile(0.5)(...)` for actual median, and label arithmetic averages as "mean", never "median". 4. **Never report a hazard ratio, odds ratio, risk ratio, or relative risk** that wasn't computed by an external tool. These require regression / model fitting that ClickHouse does not do. 5. **Never report median overall survival from `AVG(OS_MONTHS)` or even `quantile(0.5)(OS_MONTHS)`.** Median OS requires Kaplan-Meier estimation, which handles censoring (`OS_STATUS = 0:LIVING` means the event hasn't happened yet). Naive medians/means over `OS_MONTHS` ignore censoring and are systematically wrong. The correct handoff: return the raw `(OS_MONTHS, OS_STATUS)` pairs (or descriptive counts: N events, N censored, follow-up range) and tell the user to run KM in R (`survival::survfit`) or Python (`lifelines.KaplanMeierFitter`), or use cBioPortal's Survival comparison. If asked to do any of (1)–(5), respond with the appropriate handoff template from the "Approved Response Templates" section below — do not produce the number. Ambiguous-Term Clarification (before any analysis) -------------------------------------------------- If the user's question uses an ambiguous term, ask before computing anything. Examples: - **"aggressive"** → could mean shorter overall survival, higher metastasis rate, higher grade/stage, higher TMB, or specific molecular features. Ask which definit … (9984 more chars) ▶ list_studies { "search": "lung", "limit": 50 } ◀ 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 {"result":[{"cancer_study_identifier":"msk_met_2021","name":"MSK MetTropism (MSK, Cell 2021)","type_of_cancer_id":"mixed","sample_count":25775,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=msk_met_2021"},{"cancer_study_identifier":"luad_mskcc_2023_met_organotropism","name":"Lung Adenocarcinoma Met Organotropism (MSK, Cancer Cell 2023)","type_of_cancer_id":"luad","sample_count":2653,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=luad_mskcc_2023_met_organotropism"},{"cancer_study_identifier":"nsclc_ctdx_msk_2022","name":"Metastatic Non-Small Cell Lung Cancer (MSK, Nature Medicine 2022)","type_of_cancer_id":"nsclc","sample_count":2621,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=nsclc_ctdx_msk_2022"},{"cancer_study_identifier":"nsclc_tcga_broad_2016","name":"Pan-Lung Cancer (TCGA, Nat Genet 2016)","type_of_cancer_id":"nsclc","sample_count":1144,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=nsclc_tcga_broad_2016"},{"cancer_study_identifier":"lung_msk_2017","name":"Non-Small Cell Cancer (MSK, Cancer Discov 2017)","type_of_cancer_id":"luad","sample_count":915,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=lung_msk_2017"},{"cancer_study_identifier":"luad_mskcc_2020","name":"Lung Adenocarcinoma (MSK, J Thorac Oncol 2020)","type_of_cancer_id":"luad","sample_count":604,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=luad_mskcc_2020"},{"cancer_study_identifier":"luad_tcga","name":"Lung Adenocarcinoma (TCGA, Firehose Legacy)","type_of_cancer_id":"luad","sample_count":586,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=luad_tcga"},{"cancer_study_identifier":"luad_tcga_gdc","name":"Lung Adenocarcinoma (TCGA GDC, 2025)","type_of_cancer_id":"luad","sample_count":571,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=luad_tcga_gdc"},{"cancer_study_identifier":"luad_tcga_pan_can_atlas_2018","name":"Lung Adenocarcinoma (TCGA, PanCancer Atlas)","type_of_cancer_id":"luad","sample_count":566,"has_guide":true,"url":"https://www.cbioportal.org/study/summary?id=luad_tcga_pan_can_atlas_2018"},{"cancer_study_identifier":"lusc_tcga","name":"Lung Squamous Cell Carcinoma (TCGA, Firehose Legacy)","type_of_cancer_id":"lusc","sample_count":511,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=lusc_tcga"},{"cancer_study_identifier":"lusc_tcga_gdc","name":"Lung Squamous Cell Carcinoma (TCGA GDC, 2025)","type_of_cancer_id":"lusc","sample_count":503,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=lusc_tcga_gdc"},{"cancer_study_identifier":"lusc_tcga_pan_can_atlas_2018","name":"Lung Squamous Cell Carcinoma (TCGA, PanCancer Atlas)","type_of_cancer_id":"lusc","sample_count":487,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=lusc_tcga_pan_can_atlas_2018"},{"cancer_study_identifier":"nsclc_tracerx_2017","name":"Non-Small Cell Lung Cancer (TRACERx, NEJM & N … (7167 more chars) ▶ clickhouse_run_select_query { "query": "WITH cs AS ( SELECT concat(sl.cancer_study_identifier, '_', s.stable_id) AS sid, sl.cancer_study_identifier AS study FROM sample_list_list sll JOIN sample_list sl ON sl.list_id = sll.list_id JOIN sample s ON s.internal_id = sll.sample_id WHERE sl.stable_id IN ('luad_tcga_pan_can_atlas_2018_cnaseq','lusc_tcga_pan_can_atlas_2018_cnaseq') ), pmap AS (SELECT DISTINCT sample_unique_id, patient_unique_id FROM clinical_data_derived WHERE cancer_study_identifier IN ('luad_tcga_pan_can_atlas_2018','lusc_tcga_pan_can_atlas_2018')), ev AS ( SELECT DISTINCT sample_unique_id, hugo_gene_symbol FROM genomic_event_derived WHERE cancer_study_identifier IN ('luad_tcga_pan_can_atlas_2018','lusc_tcga_pan_can_atlas_2018') AND hugo_gene_symbol IN ('EGFR','KRAS') AND ((variant_type='mutation' AND mutation_status != 'UNCALLED') OR (variant_type='cna' AND cna_alteration IN (2,-2))) ), pt AS ( SELECT p.patient_unique_id AS pid, maxIf(1, e.hugo_gene_symbol='EGFR') AS egfr, maxIf(1, e.hugo_gene_symbol='KRAS') AS kras FROM cs JOIN pmap p ON p.sample_unique_id = cs.sid LEFT JOIN ev e ON e.sample_unique_id = cs.sid GROUP BY pid ) SELECT egfr, kras, count() AS patients FROM pt GROUP BY egfr, kras ORDER BY egfr, kras" } ◀ 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 'sl.cancer_study_identifier' cannot be resolved from table with name sl. In scope cs. Maybe you meant: ['sl.cancer_study_id']. (UNKNOWN_IDENTIFIER) (version 26.4.1.2509 (official build))\n"} ▶ clickhouse_run_select_query { "query": "WITH cs AS ( SELECT concat(replaceOne(sl.stable_id,'_cnaseq',''), '_', s.stable_id) AS sid FROM sample_list_list sll JOIN sample_list sl ON sl.list_id = sll.list_id JOIN sample s ON s.internal_id = sll.sample_id WHERE sl.stable_id IN ('luad_tcga_pan_can_atlas_2018_cnaseq','lusc_tcga_pan_can_atlas_2018_cnaseq') ), pmap AS (SELECT DISTINCT sample_unique_id, patient_unique_id FROM clinical_data_derived WHERE cancer_study_identifier IN ('luad_tcga_pan_can_atlas_2018','lusc_tcga_pan_can_atlas_2018')), ev AS ( SELECT DISTINCT sample_unique_id, hugo_gene_symbol FROM genomic_event_derived WHERE cancer_study_identifier IN ('luad_tcga_pan_can_atlas_2018','lusc_tcga_pan_can_atlas_2018') AND hugo_gene_symbol IN ('EGFR','KRAS') AND ((variant_type='mutation' AND mutation_status != 'UNCALLED') OR (variant_type='cna' AND cna_alteration IN (2,-2))) ), pt AS ( SELECT p.patient_unique_id AS pid, maxIf(1, e.hugo_gene_symbol='EGFR') AS egfr, maxIf(1, e.hugo_gene_symbol='KRAS') AS kras FROM cs JOIN pmap p ON p.sample_unique_id = cs.sid LEFT JOIN ev e ON e.sample_unique_id = cs.sid GROUP BY pid ) SELECT egfr, kras, count() AS patients FROM pt GROUP BY egfr, kras ORDER BY egfr, kras" } ▶ resolve_and_route { "studyIds": [ "luad_tcga_pan_can_atlas_2018", "lusc_tcga_pan_can_atlas_2018" ] } ◀ result {"rows":[{"egfr":0,"kras":0,"patients":675},{"egfr":0,"kras":1,"patients":180},{"egfr":1,"kras":0,"patients":110},{"egfr":1,"kras":1,"patients":11}]} ◀ result {"success":true,"message":"Found 2 matching studies. Pick the best match (prefer TCGA → prefer PanCancer Atlas), use its metadata to call the appropriate navigation tool(s) and generate URLs immediately. Present other studies as alternatives.","data":{"totalCount":2,"studiesWithMetadata":[{"studyId":"luad_tcga_pan_can_atlas_2018","name":"Lung Adenocarcinoma (TCGA, PanCancer Atlas)","sampleCount":566,"studyViewUrl":"https://www.cbioportal.org/study?id=luad_tcga_pan_can_atlas_2018","metadata":{"clinicalAttributeIds":["AGE","AJCC_PATHOLOGIC_TUMOR_STAGE","AJCC_STAGING_EDITION","ANEUPLOIDY_SCORE","BUFFA_HYPOXIA_SCORE","CANCER_TYPE","CANCER_TYPE_ACRONYM","CANCER_TYPE_DETAILED","DAYS_LAST_FOLLOWUP","DAYS_TO_BIRTH","DAYS_TO_INITIAL_PATHOLOGIC_DIAGNOSIS","DFS_MONTHS","DFS_STATUS","DSS_MONTHS","DSS_STATUS","ETHNICITY","FORM_COMPLETION_DATE","FRACTION_GENOME_ALTERED","GENETIC_ANCESTRY_LABEL","GRADE","HISTORY_NEOADJUVANT_TRTYN","ICD_10","ICD_O_3_HISTOLOGY","ICD_O_3_SITE","INFORMED_CONSENT_VERIFIED","IN_PANCANPATHWAYS_FREEZE","MSI_SCORE_MANTIS","MSI_SENSOR_SCORE","MUTATION_COUNT","NEW_TUMOR_EVENT_AFTER_INITIAL_TREATMENT","ONCOTREE_CODE","OS_MONTHS","OS_STATUS","OTHER_PATIENT_ID","PATH_M_STAGE","PATH_N_STAGE","PATH_T_STAGE","PERSON_NEOPLASM_CANCER_STATUS","PFS_MONTHS","PFS_STATUS","PRIMARY_LYMPH_NODE_PRESENTATION_ASSESSMENT","PRIOR_DX","RACE","RADIATION_THERAPY","RAGNUM_HYPOXIA_SCORE","SAMPLE_COUNT","SAMPLE_TYPE","SEX","SOMATIC_STATUS","SUBTYPE","TBL_SCORE","TISSUE_PROSPECTIVE_COLLECTION_INDICATOR","TISSUE_RETROSPECTIVE_COLLECTION_INDICATOR","TISSUE_SOURCE_SITE","TISSUE_SOURCE_SITE_CODE","TMB_NONSYNONYMOUS","TUMOR_TISSUE_SITE","TUMOR_TYPE","WEIGHT","WINTER_HYPOXIA_SCORE"],"molecularProfileIds":["luad_tcga_pan_can_atlas_2018_gistic","luad_tcga_pan_can_atlas_2018_log2CNA","luad_tcga_pan_can_atlas_2018_mutations","luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna","luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna_median_Zscores","luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna_median_all_sample_Zscores","luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna_median_all_sample_ref_normal_Zscores","luad_tcga_pan_can_atlas_2018_rppa","luad_tcga_pan_can_atlas_2018_rppa_Zscores","luad_tcga_pan_can_atlas_2018_structural_variants"],"genericAssayProfiles":["luad_tcga_pan_can_atlas_2018_armlevel_cna","luad_tcga_pan_can_atlas_2018_genetic_ancestry","luad_tcga_pan_can_atlas_2018_methylation_hm27_hm450_merge","luad_tcga_pan_can_atlas_2018_methylation_hm450"],"heatmapProfileIds":["luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna_median_Zscores","luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna_median_all_sample_Zscores","luad_tcga_pan_can_atlas_2018_rna_seq_v2_mrna_median_all_sample_ref_normal_Zscores","luad_tcga_pan_can_atlas_2018_rppa_Zscores"],"availableComparisonTabs":["overlap","clinical","survival","alterations","mutations","mrna","protein","generic_assay_armlevel_cna","generic_assay_genetic_ancestry","generic_assay_methylation"]}},{"studyId":"lusc_tcga_pan_can_atlas_2018","name":"Lung Squamous Cell … (2585 more chars) ▶ navigate_to_results_view { "studyIds": [ "luad_tcga_pan_can_atlas_2018", "lusc_tcga_pan_can_atlas_2018" ], "genes": [ "EGFR", "KRAS" ], "tab": "mutualExclusivity" } ◀ result {"success":true,"message":"Navigating to https://www.cbioportal.org/results/mutualExclusivity?cancer_study_list=luad_tcga_pan_can_atlas_2018%2Clusc_tcga_pan_can_atlas_2018&gene_list=EGFR%0AKRAS&case_set_id=all","url":"https://www.cbioportal.org/results/mutualExclusivity?cancer_study_list=luad_tcga_pan_can_atlas_2018%2Clusc_tcga_pan_can_atlas_2018&gene_list=EGFR%0AKRAS&case_set_id=all","data":{"studyIds":["luad_tcga_pan_can_atlas_2018","lusc_tcga_pan_can_atlas_2018"],"studies":[{"studyId":"luad_tcga_pan_can_atlas_2018","name":"Lung Adenocarcinoma (TCGA, PanCancer Atlas)","sampleCount":566},{"studyId":"lusc_tcga_pan_can_atlas_2018","name":"Lung Squamous Cell Carcinoma (TCGA, PanCancer Atlas)","sampleCount":487}],"genes":["EGFR","KRAS"],"caseSetId":"all","pageDescription":"Co-occurrence and mutual exclusivity statistics for all queried gene pairs."}} ═ answer (success) **Cohort:** TCGA PanCancer Atlas lung adenocarcinoma and lung squamous cell carcinoma (`luad_tcga_pan_can_atlas_2018` and `lusc_tcga_pan_can_atlas_2018`). These are the two non-overlapping TCGA lung cohorts. You didn't name a study, so I chose them. There are many other lung studies, so tell me if you want a different one. **Counting unit:** patients, 976 in total. Each patient is counted once if any of their samples is altered. Only samples profiled for both mutations and copy number are included. **Alteration definition:** a somatic mutation, an amplification, or a homozygous deletion in the gene. | | KRAS altered | KRAS not altered | Total | |---|---|---|---| | **EGFR altered** | 11 | 110 | 121 | | **EGFR not altered** | 180 | 675 | 855 | | **Total** | 191 | 785 | 976 | - EGFR altered in 121 patients (12.4%). - KRAS altered in 191 patients (19.6%). - EGFR and/or KRAS altered in 301 patients (30.8%). - Both altered in 11 patients (1.1%). I haven't run any statistical test on this table, so I can't say whether the two genes co-occur or exclude each other. You can run Fisher's exact test in cBioPortal's Mutual Exclusivity tab, or in R with `fisher.test(matrix(c(11,180,110,675), nrow=2))`. The cBioPortal tab may give slightly different counts because it uses its own case set. [View EGFR/KRAS Mutual Exclusivity in cBioPortal](https://www.cbioportal.org/results/mutualExclusivity?cancer_study_list=luad_tcga_pan_can_atlas_2018%2Clusc_tcga_pan_can_atlas_2018&gene_list=EGFR%0AKRAS&case_set_id=all) Co-occurrence and mutual exclusivity statistics for all queried gene pairs. I can rerun this restricted to mutations only, or on a different lung cohort such as an MSK study.