Q (sonnet): Can you please generate a survival curve for colorectal cancer patients based on the expression levels of IMPDH2? ▶ 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) ▶ read_guide { "uri": "cbioportal://gene-expression-guide" } ▶ resolve_and_route { "studyKeywords": [ "TCGA", "colorectal" ] } ◀ result # Gene Expression Analysis Guide This guide covers continuous-value genomic data: gene **expression**, **copy number** values, **methylation**, and related profile types. Mutation/CNA/SV *frequency* analysis lives in `cbioportal://mutation-frequency-guide`. ## Where this data lives Continuous per-sample-per-gene values are stored in `genetic_alteration_derived`: | Column | Description | |---|---| | `sample_unique_id` | `_` | | `cancer_study_identifier` | study scope | | `hugo_gene_symbol` | gene | | `profile_type` | which assay/normalization (see below) | | `alteration_value` | the actual value — stored as Nullable(String); cast with `toFloat64OrNull` | `alteration_value` is a string because the same column hosts many different value scales. The `''` and `'NA'` sentinels mean "missing"; always filter them out and use `toFloat64OrNull(alteration_value) IS NOT NULL` for downstream math. ## Discovering profile types for a study Different studies expose different profile types depending on what assays were run and how the data was normalized. Always check what a specific study supports before picking one: ```sql SELECT DISTINCT profile_type FROM genetic_alteration_derived WHERE cancer_study_identifier = 'brca_metabric' ORDER BY profile_type; ``` Common values across the public portal: | Family | Profile types | |---|---| | mRNA expression | `rna_seq_v2_mrna`, `rna_seq_v2_mrna_median_Zscores`, `rna_seq_v2_mrna_median_all_sample_Zscores` (TCGA PanCancer Atlas), `mrna`, `mrna_median_Zscores`, `mrna_seq_v2_rsem`, `mrna_seq_v2_rsem_Zscores`, `mrna_seq_cpm`, `mrna_seq_fpkm`, `mrna_U133`, `mrna_outliers` | | Copy number (continuous) | `cna`, `linear_CNA`, `log2CNA`, `cna_consensus`, `cna_rae`, `gistic` | | Methylation | `methylation_hm27`, `methylation_hm450`, `methylation_epic`, `methylation_promoters_rrbs` | | miRNA | `mirna`, `mirna_median_Zscores` | | Protein | `protein_quantification`, `protein_level`, `RPPA` | **Z-score vs raw choice.** When the user asks "is X correlated with Y", either works for Spearman (rank-based) — Pearson would care. Default to the non-Z-score variant if both exist, and call out which one in the response. ## Canonical recipe — Spearman correlation between two genes ```sql SELECT * FROM gene_pair_coexpression( study = 'brca_metabric', gene_a = 'TP53', gene_b = 'MYC', profile_type = 'mrna' ); ``` Returns one row: `(gene_a, gene_b, profile_type, spearman_correlation, num_samples)`. - `spearman_correlation` in [−1, 1]; `NULL` when fewer than 3 valid paired samples. - Mirrors cbioportal-backend's `ClickhouseCoExpressionMapper.getCoExpressions`, simplified to a pair lookup (the backend computes one ref gene vs ALL other genes for the coexpression page; here the agent asks about a specific pair). ### Verified examples | Study | gene_a | gene_b | profile_type | spearman | n | |---|---|---|---|---|---| | `brca_metabric` | TP53 | MYC | `mrna` | 0.118 | 1980 | | … (4931 more chars) ◀ result {"success":true,"message":"Found 3 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":3,"studiesWithMetadata":[{"studyId":"coadread_tcga","name":"Colorectal Adenocarcinoma (TCGA, Firehose Legacy)","sampleCount":640,"studyViewUrl":"https://www.cbioportal.org/study?id=coadread_tcga","metadata":{"clinicalAttributeIds":["AGE","AJCC_METASTASIS_PATHOLOGIC_PM","AJCC_NODES_PATHOLOGIC_PN","AJCC_PATHOLOGIC_TUMOR_STAGE","AJCC_STAGING_EDITION","AJCC_TUMOR_PATHOLOGIC_PT","BRAF_GENE_ANALYSIS_INDICATOR","BRAF_GENE_ANALYSIS_RESULT","CANCER_TYPE","CANCER_TYPE_DETAILED","CLINICAL_STAGE","CLIN_M_STAGE","CLIN_N_STAGE","CLIN_T_STAGE","DAYS_TO_COLLECTION","DAYS_TO_INITIAL_PATHOLOGIC_DIAGNOSIS","DAYS_TO_PATIENT_PROGRESSION_FREE","DAYS_TO_SPECIMEN_COLLECTION","DAYS_TO_TUMOR_PROGRESSION","DFS_MONTHS","DFS_STATUS","DISEASE_CODE","ETHNICITY","EXTRANODAL_INVOLVEMENT","FORM_COMPLETION_DATE","FRACTION_GENOME_ALTERED","HEIGHT","HISTOLOGICAL_DIAGNOSIS","HISTORY_NEOADJUVANT_TRTYN","HISTORY_OTHER_MALIGNANCY","ICD_10","ICD_O_3_HISTOLOGY","ICD_O_3_SITE","INFORMED_CONSENT_VERIFIED","INITIAL_PATHOLOGIC_DIAGNOSIS_METHOD","INITIAL_PATHOLOGIC_DX_YEAR","IS_FFPE","KRAS_GENE_ANALYSIS_INDICATOR","KRAS_MUTATION","LONGEST_DIMENSION","LYMPHOVASCULAR_INVASION_INDICATOR","LYMPH_NODES_EXAMINED","LYMPH_NODES_EXAMINED_HE_COUNT","LYMPH_NODES_EXAMINED_IHC_COUNT","LYMPH_NODE_EXAMINED_COUNT","METHOD_OF_SAMPLE_PROCUREMENT","MUTATION_COUNT","NEW_TUMOR_EVENT_AFTER_INITIAL_TREATMENT","OCT_EMBEDDED","ONCOTREE_CODE","OS_MONTHS","OS_STATUS","OTHER_METHOD_OF_SAMPLE_PROCUREMENT","OTHER_PATIENT_ID","OTHER_SAMPLE_ID","PATHOLOGY_REPORT_FILE_NAME","PATHOLOGY_REPORT_UUID","PERINEURAL_INVASION","PHARMACEUTICAL_TX_ADJUVANT","PRIMARY_SITE_PATIENT","PROJECT_CODE","PROSPECTIVE_COLLECTION","RACE","RADIATION_TREATMENT_ADJUVANT","RESIDUAL_TUMOR","RETROSPECTIVE_COLLECTION","SAMPLE_COUNT","SAMPLE_INITIAL_WEIGHT","SAMPLE_TYPE","SAMPLE_TYPE_ID","SEX","SHORTEST_DIMENSION","SITE_OF_TUMOR_TISSUE","SOMATIC_STATUS","SPECIMEN_CURRENT_WEIGHT","SPECIMEN_FREEZING_METHOD","SPECIMEN_SECOND_LONGEST_DIMENSION","STAGE_OTHER","TIME_BETWEEN_CLAMPING_AND_FREEZING","TIME_BETWEEN_EXCISION_AND_FREEZING","TISSUE_SOURCE_SITE","TMB_NONSYNONYMOUS","TREATMENT_OUTCOME_FIRST_COURSE","TUMOR_STATUS","VASCULAR_INVASION_INDICATOR","VIAL_NUMBER","WEIGHT"],"molecularProfileIds":["coadread_tcga_gistic","coadread_tcga_linear_CNA","coadread_tcga_methylation_hm450","coadread_tcga_mrna","coadread_tcga_mrna_median_Zscores","coadread_tcga_mrna_median_all_sample_Zscores","coadread_tcga_mutations","coadread_tcga_protein_quantification","coadread_tcga_protein_quantification_zscores","coadread_tcga_rna_seq_v2_mrna","coadread_tcga_rna_seq_v2_mrna_median_Zscores","coadread_tcga_rna_seq_v2_mrna_median_all_sample_Zscores","coadread_tcga_rppa","coadread_tcga_rppa_Zscores"],"heatmapProfileIds":["coadr … (4966 more chars) ▶ get_studyviewfilter_options { "studyId": "coadread_tcga_pan_can_atlas_2018", "geneSpecificQueries": [ { "hugoGeneSymbol": "IMPDH2", "profileType": "rna_seq_v2_mrna" } ] } ◀ result {"success":true,"message":"Successfully retrieved StudyView filter options","data":{"studyId":"coadread_tcga_pan_can_atlas_2018","geneSpecificCounts":[{"hugoGeneSymbol":"IMPDH2","profileType":"rna_seq_v2_mrna","bins":[{"end":4039.041534,"count":148},{"start":4039.041534,"end":4992.9871375,"count":148},{"start":4992.9871375,"end":6436.5223185,"count":148},{"start":6436.5223185,"count":148}]}]}} ▶ clickhouse_run_select_query { "query": " SELECT count() AS n_samples, round(min(toFloat64OrNull(alteration_value)),2) AS min_val, round(quantile(0.25)(toFloat64OrNull(alteration_value)),2) AS q25, round(median(toFloat64OrNull(alteration_value)),2) AS median_val, round(quantile(0.75)(toFloat64OrNull(alteration_value)),2) AS q75, round(max(toFloat64OrNull(alteration_value)),2) AS max_val FROM genetic_alteration_derived WHERE cancer_study_identifier = 'coadread_tcga_pan_can_atlas_2018' AND hugo_gene_symbol = 'IMPDH2' AND profile_type = 'rna_seq_v2_mrna' AND alteration_value NOT IN ('', 'NA') AND toFloat64OrNull(alteration_value) IS NOT NULL " } ◀ result {"rows":[{"n_samples":592,"min_val":1708.78,"q25":4039.99,"median_val":4992.99,"q75":6432.77,"max_val":20587.46}]} ▶ navigate_to_group_comparison { "studyIds": [ "coadread_tcga_pan_can_atlas_2018" ], "tab": "survival", "groups": [ { "name": "IMPDH2 High (≥ median)", "studyViewFilter": { "genomicDataFilters": [ { "hugoGeneSymbol": "IMPDH2", "profileType": "rna_seq_v2_mrna", "values": [ { "start": 4992.99 } ] } ] } }, { "name": "IMPDH2 Low (< median)", "studyViewFilter": { "genomicDataFilters": [ { "hugoGeneSymbol": "IMPDH2", "profileType": "rna_seq_v2_mrna", "values": [ { "end": 4992.99 } ] } ] } } ] } ◀ result {"success":true,"message":"Navigating to https://www.cbioportal.org/comparison/survival?comparisonId=6ab7f78ee497aad53593c5ae","url":"https://www.cbioportal.org/comparison/survival?comparisonId=6ab7f78ee497aad53593c5ae","data":{"description":"Group comparison (2 custom groups)","studies":["coadread_tcga_pan_can_atlas_2018"],"totalGroups":2,"groups":[{"name":"IMPDH2 High (≥ median)","sampleCount":296},{"name":"IMPDH2 Low (< median)","sampleCount":296}],"studyViewUrl":"https://www.cbioportal.org/study?id=coadread_tcga_pan_can_atlas_2018","groupUrls":[{"groupName":"IMPDH2 High (≥ median)","url":"https://www.cbioportal.org/study?id=coadread_tcga_pan_can_atlas_2018#filterJson=%7B%22genomicDataFilters%22%3A%5B%7B%22hugoGeneSymbol%22%3A%22IMPDH2%22%2C%22profileType%22%3A%22rna_seq_v2_mrna%22%2C%22values%22%3A%5B%7B%22start%22%3A4992.99%7D%5D%7D%5D%7D"},{"groupName":"IMPDH2 Low (< median)","url":"https://www.cbioportal.org/study?id=coadread_tcga_pan_can_atlas_2018#filterJson=%7B%22genomicDataFilters%22%3A%5B%7B%22hugoGeneSymbol%22%3A%22IMPDH2%22%2C%22profileType%22%3A%22rna_seq_v2_mrna%22%2C%22values%22%3A%5B%7B%22end%22%3A4992.99%7D%5D%7D%5D%7D"}],"pageDescription":"Kaplan-Meier survival analysis comparing IMPDH2 High (≥ median) (296) vs IMPDH2 Low (< median) (296)."}} ═ answer (success) ## Cohort: Colorectal Adenocarcinoma (TCGA, PanCancer Atlas) **Cohort:** [Colorectal Adenocarcinoma (TCGA, PanCancer Atlas)](https://www.cbioportal.org/study?id=coadread_tcga_pan_can_atlas_2018) — 594 samples total. **IMPDH2 expression (RNA-seq v2, RSEM):** 592 samples profiled. Distribution: min 1,708.78, Q1 4,039.99, median 4,992.99, Q3 6,432.77, max 20,587.46. I split patients at the cohort median into two groups (296 samples each) and generated the Kaplan-Meier overall survival comparison directly in cBioPortal, which computes the curves and log-rank test natively (this isn't something I can calculate myself): **[View IMPDH2 High vs. Low — Kaplan-Meier Survival Comparison](https://www.cbioportal.org/comparison/survival?comparisonId=6ab7f78ee497aad53593c5ae)** - **IMPDH2 High (≥ median):** 296 patients - **IMPDH2 Low (< median):** 296 patients On the linked Survival tab you'll see the KM curves for overall survival (and other endpoints available in this study, such as disease-free and progression-free survival, selectable in the tab), along with the log-rank p-value — none of which I can fabricate here. A few notes: - This is a **median split** of continuous expression into two groups; if you'd prefer a quartile-based comparison (e.g., top vs. bottom quartile only, excluding the middle 50%) or a different survival endpoint (DFS/PFS instead of OS), I can rebuild the groups accordingly. - If you intended a different colorectal cohort (e.g., the older "TCGA, Firehose Legacy" or "TCGA, Nature 2012" studies, which have different sample sets and some non-overlapping clinical annotations), let me know and I can rerun this on that cohort instead.