Q (sonnet):
What is the % of KRAS G12D across different tumor types? Use the MSK-IMPACT dataset.
In MSK-IMPACT (msk_impact_50k_2026), KRAS G12D by cancer type (samples profiled for KRAS):
- Pancreatic Cancer: 964 / 2,851 (33.8%)
- Colorectal Cancer: 674 / 5,277 (12.8%)
- Cancer of Unknown Primary: 100 / 1,581 (6.3%)
- Endometrial Cancer: 135 / 2,445 (5.5%)
- Non-Small Cell Lung Cancer: 285 / 7,867 (3.6%)
Continue this conversation: reply to the user's new message.
How about G12C?
▶ clickhouse_run_select_query
{
"query": "
SELECT
cd.attribute_value AS cancer_type,
countIf(m.mutation_type IS NOT NULL) AS g12c_count,
count(DISTINCT gp.sample_unique_id) AS profiled_count
FROM genetic_alteration_derived m
",
"max_rows": 5
}
◀ 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 `cd.attribute_value` in scope SELECT cd.attribute_value AS cancer_type, countIf(m.mutation_type IS NOT NULL) AS g12c_count, countDistinct(gp.sample_unique_id) AS profiled_count FROM genetic_alteration_derived AS m. (UNKNOWN_IDENTIFIER) (version 26.4.1.2359 (official build))\n"}
▶ 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)
▶ clickhouse_run_select_query
{
"query": "
WITH sample_cancer_type AS (
SELECT sample_unique_id, attribute_value AS cancer_type
FROM clinical_data_derived
WHERE cancer_study_identifier = 'msk_impact_50k_2026'
AND attribute_name = 'CANCER_TYPE'
),
altered AS (
SELECT sct.cancer_type,
COUNT(DISTINCT ged.sample_unique_id) AS altered_samples
FROM genomic_event_derived ged
JOIN sample_cancer_type sct USING (sample_unique_id)
WHERE ged.cancer_study_identifier = 'msk_impact_50k_2026'
AND ged.variant_type = 'mutation'
AND ged.mutation_status != 'UNCALLED'
AND ged.hugo_gene_symbol = 'KRAS'
AND ged.mutation_variant = 'G12C'
AND ged.off_panel = 0
GROUP BY sct.cancer_type
),
profiled_samples_for_gene AS (
SELECT sample_unique_id, cancer_study_identifier
FROM mutation_panel_gene_coverage
WHERE hugo_gene_symbol = 'KRAS'
AND cancer_study_identifier = 'msk_impact_50k_2026'
UNION ALL
SELECT sample_unique_id, cancer_study_identifier
FROM mutation_wes_coverage
WHERE cancer_study_identifier = 'msk_impact_50k_2026'
),
profiled AS (
SELECT sct.cancer_type,
COUNT(DISTINCT p.sample_unique_id) AS profiled_samples
FROM profiled_samples_for_gene p
JOIN sample_cancer_type sct USING (sample_unique_id)
GROUP BY sct.cancer_type
)
SELECT a.cancer_type,
a.altered_samples,
p.profiled_samples,
ROUND(a.altered_samples * 100.0 / NULLIF(p.profiled_samples, 0), 1) AS frequency_pct
FROM altered a
JOIN profiled p USING (cancer_type)
WHERE p.profiled_samples >= 50
ORDER BY frequency_pct DESC;
",
"max_rows": 30
}
◀ result
{"rows":[{"cancer_type":"Non-Small Cell Lung Cancer","altered_samples":922,"profiled_samples":7867,"frequency_pct":11.7},{"cancer_type":"Appendiceal Cancer","altered_samples":12,"profiled_samples":274,"frequency_pct":4.4},{"cancer_type":"Small Bowel Cancer","altered_samples":7,"profiled_samples":161,"frequency_pct":4.3},{"cancer_type":"Cancer of Unknown Primary","altered_samples":48,"profiled_samples":1581,"frequency_pct":3},{"cancer_type":"Colorectal Cancer","altered_samples":158,"profiled_samples":5277,"frequency_pct":3},{"cancer_type":"Ampullary Cancer","altered_samples":4,"profiled_samples":134,"frequency_pct":3},{"cancer_type":"Vaginal Cancer","altered_samples":1,"profiled_samples":57,"frequency_pct":1.8},{"cancer_type":"Small Cell Lung Cancer","altered_samples":8,"profiled_samples":466,"frequency_pct":1.7},{"cancer_type":"Anal Cancer","altered_samples":2,"profiled_samples":143,"frequency_pct":1.4},{"cancer_type":"Endometrial Cancer","altered_samples":30,"profiled_samples":2445,"frequency_pct":1.2},{"cancer_type":"Pancreatic Cancer","altered_samples":33,"profiled_samples":2851,"frequency_pct":1.2},{"cancer_type":"Hepatobiliary Cancer","altered_samples":10,"profiled_samples":1431,"frequency_pct":0.7},{"cancer_type":"Germ Cell Tumor","altered_samples":4,"profiled_samples":725,"frequency_pct":0.6},{"cancer_type":"Ovarian Cancer","altered_samples":13,"profiled_samples":2140,"frequency_pct":0.6},{"cancer_type":"Esophagogastric Cancer","altered_samples":8,"profiled_samples":1834,"frequency_pct":0.4},{"cancer_type":"Bladder Cancer","altered_samples":7,"profiled_samples":2526,"frequency_pct":0.3},{"cancer_type":"Thyroid Cancer","altered_samples":3,"profiled_samples":867,"frequency_pct":0.3},{"cancer_type":"Cervical Cancer","altered_samples":1,"profiled_samples":351,"frequency_pct":0.3},{"cancer_type":"Melanoma","altered_samples":3,"profiled_samples":1831,"frequency_pct":0.2},{"cancer_type":"Mesothelioma","altered_samples":1,"profiled_samples":408,"frequency_pct":0.2},{"cancer_type":"Head and Neck Cancer","altered_samples":1,"profiled_samples":657,"frequency_pct":0.2},{"cancer_type":"Peripheral Nervous System","altered_samples":1,"profiled_samples":411,"frequency_pct":0.2},{"cancer_type":"Breast Cancer","altered_samples":4,"profiled_samples":6807,"frequency_pct":0.1},{"cancer_type":"Soft Tissue Sarcoma","altered_samples":3,"profiled_samples":2307,"frequency_pct":0.1},{"cancer_type":"Glioma","altered_samples":2,"profiled_samples":2322,"frequency_pct":0.1}]}
═ answer (success)
In MSK-IMPACT (msk_impact_50k_2026), KRAS G12C by cancer type (samples profiled for KRAS), top hits:
- Non-Small Cell Lung Cancer: 922 / 7,867 (11.7%)
- Appendiceal Cancer: 12 / 274 (4.4%)
- Small Bowel Cancer: 7 / 161 (4.3%)
- Cancer of Unknown Primary: 48 / 1,581 (3.0%)
- Colorectal Cancer: 158 / 5,277 (3.0%)
- Ampullary Cancer: 4 / 134 (3.0%)
- Small Cell Lung Cancer: 8 / 466 (1.7%)
- Endometrial Cancer: 30 / 2,445 (1.2%)
- Pancreatic Cancer: 33 / 2,851 (1.2%)
Notably, this is the opposite pattern from G12D — G12C is strongly enriched in NSCLC (a smoking-associated transversion), whereas G12D dominates in pancreatic and colorectal cancer. Pancreatic cancer, which had the highest G12D rate (33.8%), shows a much lower G12C rate (1.2%).
You can explore this directly in the portal:
[KRAS G12C — Results View (MSK-IMPACT)](https://www.cbioportal.org/results/mutations?cancer_study_list=msk_impact_50k_2026&Z_SCORE_THRESHOLD=2.0&RPPA_SCORE_THRESHOLD=2.0&profileFilter=mutations&case_set_id=msk_impact_50k_2026_all&gene_list=KRAS%3A%20G12C&geneset_list=%20&tab_index=tab_visualize)