Q (sonnet-5.5): In the TCGA PanCancer Atlas endometrial cancer study, what percentage of patients have co-occurring oncogenic mutations in both KRAS and NRAS? ▶ read_guide { "uri": "cbioportal://mutation-frequency-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) ▶ read_guide { "uri": "cbioportal://statistical-tests-guide" } ▶ list_studies { "search": "uterine pan_can_atlas" } ◀ 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) ◀ result {"result":[{"cancer_study_identifier":"ucec_tcga_pan_can_atlas_2018","name":"Uterine Corpus Endometrial Carcinoma (TCGA, PanCancer Atlas)","type_of_cancer_id":"ucec","sample_count":529,"has_guide":true,"url":"https://www.cbioportal.org/study/summary?id=ucec_tcga_pan_can_atlas_2018"},{"cancer_study_identifier":"ucs_tcga_pan_can_atlas_2018","name":"Uterine Carcinosarcoma (TCGA, PanCancer Atlas)","type_of_cancer_id":"ucs","sample_count":57,"has_guide":false,"url":"https://www.cbioportal.org/study/summary?id=ucs_tcga_pan_can_atlas_2018"}]} ▶ clickhouse_run_select_query { "query": "SELECT driver_filter, count() AS mutations FROM genomic_event_derived WHERE cancer_study_identifier='ucec_tcga_pan_can_atlas_2018' AND variant_type='mutation' GROUP BY driver_filter" } ◀ result {"rows":[{"mutations":538948}]} ▶ clickhouse_run_select_query { "query": "WITH prof AS (SELECT DISTINCT c.patient_unique_id AS p FROM sample_to_gene_panel_derived s JOIN (SELECT DISTINCT sample_unique_id, patient_unique_id FROM clinical_data_derived WHERE cancer_study_identifier='ucec_tcga_pan_can_atlas_2018') c USING sample_unique_id WHERE s.cancer_study_identifier='ucec_tcga_pan_can_atlas_2018' AND s.alteration_type='MUTATION_EXTENDED'), m AS (SELECT DISTINCT c.patient_unique_id AS p, g.hugo_gene_symbol AS gene FROM genomic_event_derived g JOIN (SELECT DISTINCT sample_unique_id, patient_unique_id FROM clinical_data_derived WHERE cancer_study_identifier='ucec_tcga_pan_can_atlas_2018') c USING sample_unique_id WHERE g.cancer_study_identifier='ucec_tcga_pan_can_atlas_2018' AND g.variant_type='mutation' AND g.mutation_status!='UNCALLED' AND g.hugo_gene_symbol IN ('KRAS','NRAS')) SELECT (SELECT count() FROM prof) AS profiled, (SELECT uniqExactIf(p, gene='KRAS') FROM m) AS kras, (SELECT uniqExactIf(p, gene='NRAS') FROM m) AS nras, (SELECT count() FROM (SELECT p FROM m GROUP BY p HAVING uniqExact(gene)=2)) AS both" } ◀ result {"rows":[{"profiled":517,"kras":99,"nras":21,"both":4}]} ▶ navigate_to_results_view { "studyIds": [ "ucec_tcga_pan_can_atlas_2018" ], "genes": [ "KRAS: MUT_DRIVER", "NRAS: MUT_DRIVER" ], "tab": "oncoprint" } ◀ result {"success":true,"message":"Navigating to https://www.cbioportal.org/results/oncoprint?cancer_study_list=ucec_tcga_pan_can_atlas_2018&gene_list=KRAS%3A+MUT_DRIVER%0ANRAS%3A+MUT_DRIVER&case_set_id=ucec_tcga_pan_can_atlas_2018_all","url":"https://www.cbioportal.org/results/oncoprint?cancer_study_list=ucec_tcga_pan_can_atlas_2018&gene_list=KRAS%3A+MUT_DRIVER%0ANRAS%3A+MUT_DRIVER&case_set_id=ucec_tcga_pan_can_atlas_2018_all","data":{"studyIds":["ucec_tcga_pan_can_atlas_2018"],"studies":[{"studyId":"ucec_tcga_pan_can_atlas_2018","name":"Uterine Corpus Endometrial Carcinoma (TCGA, PanCancer Atlas)","sampleCount":529}],"genes":["KRAS","NRAS"],"caseSetId":"ucec_tcga_pan_can_atlas_2018_all","pageDescription":"Visual summary of alterations in queried genes across samples."}} ═ answer (success) **About 0.8% of patients (4 of 517)** in the Uterine Corpus Endometrial Carcinoma (TCGA, PanCancer Atlas) study have both a KRAS and an NRAS mutation. I counted patients, using the 517 patients with mutation profiling as the denominator. | Group | Patients | % of 517 | |---|---|---| | KRAS-mutated | 99 | 19.1% | | NRAS-mutated | 21 | 4.1% | | **Both KRAS and NRAS mutated** | **4** | **0.8%** | **"Oncogenic" caveat:** This study has no driver or oncogenicity annotation stored in the database. The counts above are all called somatic or unknown-status mutations in each gene, not only oncogenic ones. OncoKB annotation is applied when you view the data in the portal. The OncoPrint link below uses the `MUT_DRIVER` filter, so it should give the driver-only picture. I haven't tested whether KRAS and NRAS co-occur more or less often than chance would predict. For that, use the Mutual Exclusivity tab in the portal. [View KRAS and NRAS driver mutations in the OncoPrint](https://www.cbioportal.org/results/oncoprint?cancer_study_list=ucec_tcga_pan_can_atlas_2018&gene_list=KRAS%3A+MUT_DRIVER%0ANRAS%3A+MUT_DRIVER&case_set_id=ucec_tcga_pan_can_atlas_2018_all)