Q (haiku): 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" } ◀ 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) ▶ clickhouse_run_select_query { "query": " SELECT SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 1 THEN 1 ELSE 0 END) AS both_altered, SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 0 THEN 1 ELSE 0 END) AS egfr_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 1 THEN 1 ELSE 0 END) AS kras_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 0 THEN 1 ELSE 0 END) AS neither_altered, SUM(egfr_altered) AS total_egfr_altered, SUM(kras_altered) AS total_kras_altered, COUNT(DISTINCT patient_id) AS total_patients FROM ( SELECT DISTINCT patient_id, MAX(CASE WHEN hugo_gene_symbol = 'EGFR' AND off_panel = FALSE THEN 1 ELSE 0 END) AS egfr_altered, MAX(CASE WHEN hugo_gene_symbol = 'KRAS' AND off_panel = FALSE THEN 1 ELSE 0 END) AS kras_altered FROM genomic_event_derived WHERE cancer_type_code IN ( SELECT cancer_type_code FROM cancer_study_query_preferences WHERE cancer_type_code IN (SELECT DISTINCT cancer_type_code FROM genomic_event_derived WHERE cancer_type_code LIKE '%LUAD%' OR cancer_type_code LIKE '%LUNG%') ) GROUP BY patient_id ) ", "max_rows": 100 } ◀ 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 identifier `patient_id` in scope SELECT DISTINCT patient_id, MAX(multiIf((hugo_gene_symbol = 'EGFR') AND (off_panel = false), 1, 0)) AS egfr_altered, MAX(multiIf((hugo_gene_symbol = 'KRAS') AND (off_panel = false), 1, 0)) AS kras_altered FROM genomic_event_derived WHERE cancer_type_code IN (SELECT cancer_type_code FROM cancer_study_query_preferences WHERE cancer_type_code IN (SELECT DISTINCT cancer_type_code FROM genomic_event_derived WHERE (cancer_type_code LIKE '%LUAD%') OR (cancer_type_code LIKE '%LUNG%'))) GROUP BY patient_id. (UNKNOWN_IDENTIFIER) (version 26.4.1.2359 (official build))\n"} ▶ clickhouse_list_table_columns { "table": "genomic_event_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."}]} ▶ search_oncotree { "search_term": "lung adenocarcinoma" } ◀ result {"result":[{"code":"LUAD","name":"Lung Adenocarcinoma","score":80,"mainType":"Non-Small Cell Lung Cancer","tissue":"Lung","hierarchy":"LUNG > NSCLC > LUAD"},{"code":"LAIS","name":"Lung Adenocarcinoma In Situ","score":60,"mainType":"Non-Small Cell Lung Cancer","tissue":"Lung","hierarchy":"LUNG > LAIS"}]} ▶ clickhouse_run_select_query { "query": " WITH lung_patients AS ( SELECT DISTINCT patient_unique_id FROM genomic_event_derived WHERE cancer_study_identifier IN ( SELECT DISTINCT cancer_study_identifier FROM genomic_event_derived WHERE cancer_type_code = 'LUAD' ) ), patient_alterations AS ( SELECT patient_unique_id, MAX(CASE WHEN hugo_gene_symbol = 'EGFR' AND off_panel = FALSE THEN 1 ELSE 0 END) AS egfr_altered, MAX(CASE WHEN hugo_gene_symbol = 'KRAS' AND off_panel = FALSE THEN 1 ELSE 0 END) AS kras_altered FROM genomic_event_derived WHERE patient_unique_id IN (SELECT patient_unique_id FROM lung_patients) GROUP BY patient_unique_id ) SELECT SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 1 THEN 1 ELSE 0 END) AS both_altered, SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 0 THEN 1 ELSE 0 END) AS egfr_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 1 THEN 1 ELSE 0 END) AS kras_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 0 THEN 1 ELSE 0 END) AS neither, COUNT(*) AS total_patients FROM patient_alterations ", "max_rows": 100 } ◀ 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 `cancer_type_code` in scope (SELECT DISTINCT cancer_study_identifier FROM genomic_event_derived WHERE cancer_type_code = 'LUAD'). (UNKNOWN_IDENTIFIER) (version 26.4.1.2359 (official build))\n"} ▶ clickhouse_list_tables {} ◀ result {"tables":[{"name":"allele_specific_copy_number"},{"name":"alteration_driver_annotation"},{"name":"cancer_study"},{"name":"cancer_study_query_preferences"},{"name":"cancer_study_tags"},{"name":"cbioportal_sequence_state"},{"name":"clinical_attribute_counts"},{"name":"clinical_attribute_meta"},{"name":"clinical_data_derived"},{"name":"clinical_event"},{"name":"clinical_event_data"},{"name":"clinical_event_data_derived"},{"name":"clinical_event_derived"},{"name":"clinical_patient"},{"name":"clinical_sample"},{"name":"cna_event"},{"name":"cna_panel_gene_coverage"},{"name":"cna_wes_coverage"},{"name":"co_altered_genes_in_study"},{"name":"copy_number_seg"},{"name":"copy_number_seg_file"},{"name":"gene"},{"name":"gene_alias"},{"name":"gene_alteration_frequency_by_cancer_type"},{"name":"gene_cna_distribution_in_study"},{"name":"gene_mutation_frequency_by_cancer_type"},{"name":"gene_mutation_frequency_in_studies"},{"name":"gene_mutation_frequency_in_study"},{"name":"gene_mutation_variants_in_study"},{"name":"gene_pair_coexpression"},{"name":"gene_panel"},{"name":"gene_panel_list"},{"name":"gene_panel_to_gene_derived"},{"name":"generic_assay_data_derived"},{"name":"generic_assay_meta_derived"},{"name":"generic_assay_profile_entity_derived"},{"name":"generic_entity_properties"},{"name":"geneset"},{"name":"geneset_gene"},{"name":"geneset_hierarchy_leaf"},{"name":"geneset_hierarchy_node"},{"name":"genetic_alteration"},{"name":"genetic_alteration_derived"},{"name":"genetic_entity"},{"name":"genetic_profile"},{"name":"genetic_profile_link"},{"name":"genetic_profile_samples"},{"name":"genomic_event_derived"},{"name":"gistic"},{"name":"gistic_to_gene"},{"name":"info"},{"name":"mut_sig"},{"name":"mutation"},{"name":"mutation_count_by_keyword"},{"name":"mutation_derived"},{"name":"mutation_event"},{"name":"mutation_panel_gene_coverage"},{"name":"mutation_wes_coverage"},{"name":"patient"},{"name":"reference_genome"},{"name":"reference_genome_gene"},{"name":"resource_definition"},{"name":"resource_patient"},{"name":"resource_sample"},{"name":"resource_study"},{"name":"sample"},{"name":"sample_cna_event"},{"name":"sample_derived"},{"name":"sample_list"},{"name":"sample_list_list"},{"name":"sample_profile"},{"name":"sample_to_gene_panel_derived"},{"name":"structural_variant"},{"name":"sv_panel_gene_coverage"},{"name":"sv_wes_coverage"},{"name":"top_cna_genes_in_study"},{"name":"top_mutated_genes_in_cohort"},{"name":"top_mutated_genes_in_study"},{"name":"top_sv_genes_in_study"},{"name":"treatment_counts_in_study"},{"name":"treatment_regimens_in_study"},{"name":"type_of_cancer"}]} ▶ clickhouse_list_table_columns { "table": "cancer_study" } ▶ clickhouse_list_table_columns { "table": "type_of_cancer" } ◀ result {"columns":[{"name":"cancer_study_id","type":"Int64","comment":"Internal numeric ID. Prefer cancer_study_identifier for queries as it is more readable and stable."},{"name":"cancer_study_identifier","type":"Nullable(String)","comment":"Stable string identifier for the study (e.g., \"msk_chord_2024\", \"brca_tcga\"). Use this for filtering, not cancer_study_id."},{"name":"type_of_cancer_id","type":"String"},{"name":"name","type":"String","comment":"Full descriptive name of the study (e.g., \"MSK-CHORD (MSK, Nature 2024)\")."},{"name":"description","type":"String"},{"name":"public","type":"Int32"},{"name":"pmid","type":"Nullable(String)"},{"name":"citation","type":"Nullable(String)"},{"name":"groups","type":"Nullable(String)"},{"name":"status","type":"Nullable(Int64)"},{"name":"import_date","type":"Nullable(DateTime64(6))"},{"name":"reference_genome_id","type":"Nullable(Int64)"},{"name":"sample_count","type":"UInt32","comment":"Samples in the study (members of _all), as shown in the portal study list. Precomputed daily at LLM-prep time."},{"name":"mutation_sample_count","type":"UInt32","comment":"Samples profiled for mutations (_sequenced) — portal \"Data type\" filter: \"Mutations\". 0 = no mutation data."},{"name":"cna_sample_count","type":"UInt32","comment":"Samples profiled for copy-number alterations (_cna) — \"CNA\". 0 = no CNA data."},{"name":"structural_variant_sample_count","type":"UInt32","comment":"Distinct samples with at least one structural variant (fusions etc.). 0 = none."},{"name":"rna_seq_sample_count","type":"UInt32","comment":"Samples with RNA-Seq expression (_rna_seq_v2_mrna) — \"RNA-Seq\"."},{"name":"mrna_microarray_sample_count","type":"UInt32","comment":"Samples with microarray mRNA expression (_mrna) — \"RNA (microarray)\"."},{"name":"mirna_sample_count","type":"UInt32","comment":"Samples with microRNA expression (_microrna) — \"miRNA\"."},{"name":"rppa_sample_count","type":"UInt32","comment":"Samples with RPPA protein levels (_rppa) — \"RPPA\"."},{"name":"mass_spectrometry_sample_count","type":"UInt32","comment":"Samples with mass-spectrometry protein quantification (_protein_quantification) — \"Protein Mass-Spectrometry\"."},{"name":"treatment_patient_count","type":"UInt32","comment":"PATIENTS (not samples) with treatment clinical events — \"Treatment\". 0 = no treatment data."},{"name":"resource_sample_counts","type":"Map(String, UInt32)","comment":"Samples with each linked resource, keyed by display name: imaging and pathology such as 'Slide Microscopy', 'Computed Tomography', 'Magnetic Resonance', 'H&E Slide', 'MxIF Image'. Query with mapKeys(resource_sample_counts) or resource_sample_counts['Slide Microscopy'] > 0."},{"name":"mrna_expression_sample_count","type":"UInt32","comment":"Samples in any mRNA expression profile (RNA-Seq, microarray, TPM, z-scores; from sample_profile). Use this for \"does the study have expression data\" — rna_seq_sample_count and mrna_m … (136 more chars) ◀ result {"columns":[{"name":"type_of_cancer_id","type":"String"},{"name":"name","type":"String"},{"name":"dedicated_color","type":"String"},{"name":"short_name","type":"Nullable(String)"},{"name":"parent","type":"Nullable(String)"},{"name":"main_type","type":"String","comment":"Broad OncoTree grouping (e.g. Non-Small Cell Lung Cancer, Glioma). Useful for grouping related subtypes."},{"name":"tissue","type":"String","comment":"Tissue of origin (e.g. Lung, CNS/Brain, Breast). Top-level anatomical grouping."},{"name":"level","type":"UInt8","comment":"Depth in OncoTree hierarchy: 1 = tissue, 2-6 = increasingly specific subtypes. Lower = broader."},{"name":"revocations","type":"Array(String)","comment":"Deprecated OncoTree codes that this code replaces (e.g. BLL replaces ALL, GB replaces GBM). Search here when a user code is not found."},{"name":"precursors","type":"Array(String)","comment":"Previous codes merged into this code (e.g. CLLSLL merges CLL and SLL). Similar to revocations but for code merges."}]} ▶ clickhouse_run_select_query { "query": " WITH lung_studies AS ( SELECT cancer_study_identifier FROM cancer_study WHERE type_of_cancer_id = 'LUAD' ), patient_alterations AS ( SELECT patient_unique_id, MAX(CASE WHEN hugo_gene_symbol = 'EGFR' AND off_panel = FALSE THEN 1 ELSE 0 END) AS egfr_altered, MAX(CASE WHEN hugo_gene_symbol = 'KRAS' AND off_panel = FALSE THEN 1 ELSE 0 END) AS kras_altered FROM genomic_event_derived WHERE cancer_study_identifier IN (SELECT cancer_study_identifier FROM lung_studies) GROUP BY patient_unique_id ) SELECT SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 1 THEN 1 ELSE 0 END) AS both_altered, SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 0 THEN 1 ELSE 0 END) AS egfr_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 1 THEN 1 ELSE 0 END) AS kras_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 0 THEN 1 ELSE 0 END) AS neither, COUNT(*) AS total_patients FROM patient_alterations ", "max_rows": 100 } ◀ result {"rows":[{"both_altered":0,"egfr_only":0,"kras_only":0,"neither":0,"total_patients":0}]} ▶ clickhouse_run_select_query { "query": " SELECT DISTINCT cancer_study_identifier, type_of_cancer_id FROM cancer_study WHERE type_of_cancer_id LIKE '%LU%' ORDER BY cancer_study_identifier LIMIT 20 ", "max_rows": 100 } ◀ result {"rows":[]} ▶ clickhouse_run_select_query { "query": " SELECT DISTINCT type_of_cancer_id, name FROM type_of_cancer WHERE tissue = 'Lung' ORDER BY type_of_cancer_id ", "max_rows": 100 } ◀ result {"rows":[{"type_of_cancer_id":"aluca","name":"Atypical Lung Carcinoid"},{"type_of_cancer_id":"blclc","name":"Basaloid Large Cell Carcinoma of the Lung"},{"type_of_cancer_id":"cclc","name":"Clear Cell Carcinoma of the Lung"},{"type_of_cancer_id":"cmpt","name":"Ciliated Muconodular Papillary Tumor of the Lung"},{"type_of_cancer_id":"csclc","name":"Combined Small Cell Lung Carcinoma"},{"type_of_cancer_id":"gclc","name":"Giant Cell Carcinoma of the Lung"},{"type_of_cancer_id":"imtl","name":"Inflammatory Myofibroblastic Lung Tumor"},{"type_of_cancer_id":"lais","name":"Lung Adenocarcinoma In Situ"},{"type_of_cancer_id":"lam","name":"Pulmonary Lymphangiomyomatosis"},{"type_of_cancer_id":"lclc","name":"Large Cell Lung Carcinoma"},{"type_of_cancer_id":"leclc","name":"Lymphoepithelioma-like Carcinoma of the Lung"},{"type_of_cancer_id":"lnet","name":"Lung Neuroendocrine Tumor"},{"type_of_cancer_id":"luacc","name":"Adenoid Cystic Carcinoma of the Lung"},{"type_of_cancer_id":"luad","name":"Lung Adenocarcinoma"},{"type_of_cancer_id":"luas","name":"Lung Adenosquamous Carcinoma"},{"type_of_cancer_id":"luca","name":"Lung Carcinoid"},{"type_of_cancer_id":"lumec","name":"Mucoepidermoid Carcinoma of the Lung"},{"type_of_cancer_id":"lune","name":"Large Cell Neuroendocrine Carcinoma"},{"type_of_cancer_id":"lung","name":"Lung"},{"type_of_cancer_id":"lupc","name":"Pleomorphic Carcinoma of the Lung"},{"type_of_cancer_id":"lusc","name":"Lung Squamous Cell Carcinoma"},{"type_of_cancer_id":"nsclc","name":"Non-Small Cell Lung Cancer"},{"type_of_cancer_id":"nsclcpd","name":"Poorly Differentiated Non-Small Cell Lung Cancer"},{"type_of_cancer_id":"nutcl","name":"NUT Carcinoma of the Lung"},{"type_of_cancer_id":"ppb","name":"Pleuropulmonary Blastoma"},{"type_of_cancer_id":"rlclc","name":"Large Cell Lung Carcinoma With Rhabdoid Phenotype"},{"type_of_cancer_id":"sarcl","name":"Sarcomatoid Carcinoma of the Lung"},{"type_of_cancer_id":"sclc","name":"Small Cell Lung Cancer"},{"type_of_cancer_id":"sgttl","name":"Salivary Gland-Type Tumor of the Lung"},{"type_of_cancer_id":"spcc","name":"Spindle Cell Carcinoma of the Lung"}]} ▶ clickhouse_run_select_query { "query": " SELECT cancer_study_identifier, name, type_of_cancer_id, sample_count FROM cancer_study WHERE type_of_cancer_id IN ('luad', 'lusc', 'nsclc', 'sclc', 'lung') ORDER BY sample_count DESC LIMIT 20 ", "max_rows": 100 } ◀ result {"rows":[{"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},{"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},{"cancer_study_identifier":"nsclc_tcga_broad_2016","name":"Pan-Lung Cancer (TCGA, Nat Genet 2016)","type_of_cancer_id":"nsclc","sample_count":1144},{"cancer_study_identifier":"lung_msk_2017","name":"Non-Small Cell Cancer (MSK, Cancer Discov 2017)","type_of_cancer_id":"luad","sample_count":915},{"cancer_study_identifier":"luad_mskcc_2020","name":"Lung Adenocarcinoma (MSK, J Thorac Oncol 2020)","type_of_cancer_id":"luad","sample_count":604},{"cancer_study_identifier":"luad_tcga","name":"Lung Adenocarcinoma (TCGA, Firehose Legacy)","type_of_cancer_id":"luad","sample_count":586},{"cancer_study_identifier":"luad_tcga_gdc","name":"Lung Adenocarcinoma (TCGA GDC, 2025)","type_of_cancer_id":"luad","sample_count":571},{"cancer_study_identifier":"luad_tcga_pan_can_atlas_2018","name":"Lung Adenocarcinoma (TCGA, PanCancer Atlas)","type_of_cancer_id":"luad","sample_count":566},{"cancer_study_identifier":"lusc_tcga","name":"Lung Squamous Cell Carcinoma (TCGA, Firehose Legacy)","type_of_cancer_id":"lusc","sample_count":511},{"cancer_study_identifier":"lusc_tcga_gdc","name":"Lung Squamous Cell Carcinoma (TCGA GDC, 2025)","type_of_cancer_id":"lusc","sample_count":503},{"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},{"cancer_study_identifier":"nsclc_tracerx_2017","name":"Non-Small Cell Lung Cancer (TRACERx, NEJM & Nature 2017)","type_of_cancer_id":"nsclc","sample_count":447},{"cancer_study_identifier":"luad_msk_npjpo_2021","name":"Lung Adenocarcinoma (MSK, NPJ Precision Oncology 2021)","type_of_cancer_id":"luad","sample_count":426},{"cancer_study_identifier":"bm_nsclc_mskcc_2023","name":"Non-Small Cell Lung Cancer Brain Metastasis (MSK, Nat Commun 2023)","type_of_cancer_id":"nsclc","sample_count":322},{"cancer_study_identifier":"lung_msk_pdx","name":"Thoracic PDX (MSK, Provisional)","type_of_cancer_id":"lung","sample_count":318},{"cancer_study_identifier":"luad_oncosg_2020","name":"Lung Adenocarcinoma (OncoSG, Nat Genet 2020)","type_of_cancer_id":"luad","sample_count":305},{"cancer_study_identifier":"lung_msk_mind_2020","name":"Lung Adenocarcinoma (MSK Mind,Nature Cancer 2022)","type_of_cancer_id":"lung","sample_count":247},{"cancer_study_identifier":"luad_cptac_gdc","name":"Lung Adenocarcinoma (CPTAC GDC, 2025)","type_of_cancer_id":"luad","sample_count":241},{"cancer_study_identifier":"nsclc_pd1_msk_2018","name":"Non-Small Cell Lung Cancer (MSK, J Clin Oncol 2018)","type_of_cancer_id":"nsclc","sample_count":240},{"cancer_study_identifier":"lung_nci_2022","name":"Lung Cancer in Never Smokers … (78 more chars) ▶ clickhouse_run_select_query { "query": " WITH lung_studies AS ( SELECT cancer_study_identifier FROM cancer_study WHERE type_of_cancer_id IN ('luad', 'lusc', 'nsclc') ), patient_alterations AS ( SELECT patient_unique_id, MAX(CASE WHEN hugo_gene_symbol = 'EGFR' AND off_panel = FALSE THEN 1 ELSE 0 END) AS egfr_altered, MAX(CASE WHEN hugo_gene_symbol = 'KRAS' AND off_panel = FALSE THEN 1 ELSE 0 END) AS kras_altered FROM genomic_event_derived WHERE cancer_study_identifier IN (SELECT cancer_study_identifier FROM lung_studies) GROUP BY patient_unique_id ) SELECT SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 1 THEN 1 ELSE 0 END) AS both_altered, SUM(CASE WHEN egfr_altered = 1 AND kras_altered = 0 THEN 1 ELSE 0 END) AS egfr_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 1 THEN 1 ELSE 0 END) AS kras_only, SUM(CASE WHEN egfr_altered = 0 AND kras_altered = 0 THEN 1 ELSE 0 END) AS neither, COUNT(*) AS total_patients FROM patient_alterations ", "max_rows": 100 } ◀ result {"rows":[{"both_altered":166,"egfr_only":2817,"kras_only":2876,"neither":6399,"total_patients":12258}]} ═ answer (success) Excellent! Now let me present this as a proper 2×2 contingency table with percentages: ## Contingency Table: EGFR and KRAS Alterations in Lung Cancer **Total patients:** 12,258 (across lung adenocarcinoma, squamous cell carcinoma, and non-small cell lung cancer studies in cBioPortal) | | **KRAS Altered** | **KRAS Not Altered** | **Total** | |---|---|---|---| | **EGFR Altered** | 166 (1.4%) | 2,817 (23.0%) | **2,983 (24.3%)** | | **EGFR Not Altered** | 2,876 (23.5%) | 6,399 (52.2%) | **9,275 (75.7%)** | | **Total** | **3,042 (24.8%)** | **9,216 (75.2%)** | **12,258 (100%)** | ### Key observations: - **Co-alteration is rare:** Only 166 patients (1.4% of cohort) harbor both EGFR and KRAS alterations - **EGFR-only:** 2,817 patients (23.0%) - **KRAS-only:** 2,876 patients (23.5%) - **Neither:** 6,399 patients (52.2%) --- ### Statistical Note This contingency table shows the frequencies but does **not** indicate whether the two genes are mutually exclusive or co-occurring. To test for mutual exclusivity, the appropriate test is **Fisher's exact test (two-tailed)**. You can compute the p-value in: - **cBioPortal's Group Comparison tab** (recommended) - **R:** `fisher.test(matrix(c(166, 2817, 2876, 6399), nrow=2))` - **Python:** `from scipy.stats import fisher_exact; fisher_exact([[166, 2817], [2876, 6399]])` Raw counts alone do not support claims of mutual exclusivity — the test is required.