Q (haiku): How many patients have an EGFR amplification in the TCGA Lung Adenocarcinoma study? ▶ read_guide { "uri": "cbioportal://sample-filtering-guide" } ◀ result # Sample and Study Filtering Guide ## Overview Proper filtering is essential for meaningful cBioPortal analysis. This guide covers filtering by studies, sample types, and other criteria. ## Study-Level Filtering ### 1. Always Filter by Study Every query should specify a study to ensure consistent results: ```sql -- Always include study filtering SELECT * FROM your_table WHERE cancer_study_identifier = 'your_study_id' -- Additional filters... ``` ### 2. Find Available Studies ```sql -- Discover available studies SELECT cancer_study_identifier, name, description, type_of_cancer_id FROM cancer_study ORDER BY cancer_study_identifier; ``` ### 3. Study Information ```sql -- Get detailed study information SELECT cs.cancer_study_identifier, cs.name as study_name, cs.description, cs.sample_count, COUNT(DISTINCT p.internal_id) as patient_count FROM cancer_study cs LEFT JOIN patient p ON cs.cancer_study_id = p.cancer_study_id WHERE cs.cancer_study_identifier = 'your_study_id' GROUP BY cs.cancer_study_identifier, cs.name, cs.description, cs.sample_count; ``` ### 4. Find Studies by Available Data Types Use this when the user asks *"which studies have mutation and copy-number data for X"*, *"studies with expression for Y"*, *"is there any imaging data"*, or any *"studies with Z data"* question. `cancer_study` has one precomputed sample count per data type — filter on them. No join and no schema exploration needed. These are the same counts as the portal's study list and its "Data type" filter. **Canonical query — studies with ALL requested data types for a cancer type:** ```sql SELECT cancer_study_identifier, name, sample_count, mutation_sample_count, cna_sample_count FROM cancer_study WHERE type_of_cancer_id = 'luad' -- ← OncoTree code from search_oncotree AND mutation_sample_count > 0 -- ← one condition per required data type AND cna_sample_count > 0 ORDER BY sample_count DESC; ``` **Data type → column** (a count of 0 means the study doesn't have that data): | Data type in the user's question | Column (portal "Data type" filter label) | |---|---| | samples in the study | `sample_count` | | mutation / mutations | `mutation_sample_count` ("Mutations") | | copy-number / CNA / amplification / deletion | `cna_sample_count` ("CNA") | | structural variant / fusion | `structural_variant_sample_count` | | RNA / mRNA / gene expression (any platform) | `mrna_expression_sample_count` — use this for "which studies have expression data" | | specifically the portal's "RNA-Seq" filter | `rna_seq_sample_count` ("RNA-Seq") — counts only the `_rna_seq_v2_mrna` list; 0 for many GDC and iAtlas studies that do have RNA-Seq | | specifically the portal's "RNA (microarray)" filter | `mrna_microarray_sample_count` ("RNA (microarray)") — counts only the `_mrna` list | | microRNA | `mirna_sample_count` ("miRNA") | | protein / RPPA | `rppa_sample_count` ("RPPA") | | mas … (7083 more chars) ▶ resolve_and_route { "studyKeywords": [ "TCGA", "lung", "adenocarcinoma" ] } ◀ result {"success":true,"message":"Found 4 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":4,"studiesWithMetadata":[{"studyId":"luad_tcga","name":"Lung Adenocarcinoma (TCGA, Firehose Legacy)","sampleCount":586,"studyViewUrl":"https://www.cbioportal.org/study?id=luad_tcga","metadata":{"clinicalAttributeIds":["AGE","AJCC_CLINICAL_TUMOR_STAGE","AJCC_METASTASIS_CLINICAL_CM","AJCC_METASTASIS_PATHOLOGIC_PM","AJCC_NODES_CLINICAL_CN","AJCC_NODES_CLINICAL_CT","AJCC_NODES_PATHOLOGIC_PN","AJCC_PATHOLOGIC_TUMOR_STAGE","AJCC_STAGING_EDITION","AJCC_TUMOR_PATHOLOGIC_PT","ALK_ANALYSIS_TYPE","ALK_TRANSLOCATION_STATUS","ALK_TRANSLOCATION_VARIANT","CANCER_TYPE","CANCER_TYPE_DETAILED","CARBON_MONOXIDE_DIFFUSION_DLCO","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","ECOG_SCORE","ETHNICITY","EXTRANODAL_INVOLVEMENT","FEV1_FVC_RATIO_POSTBRONCHOLIATOR","FEV1_FVC_RATIO_PREBRONCHOLIATOR","FEV1_PERCENT_REF_POSTBRONCHOLIATOR","FEV1_PERCENT_REF_PREBRONCHOLIATOR","FORM_COMPLETION_DATE","FRACTION_GENOME_ALTERED","HISTOLOGICAL_DIAGNOSIS","HISTORY_IMMUNOLOGICAL_DISEASE","HISTORY_IMMUNOLOGICAL_DISEASE_OTHER","HISTORY_NEOADJUVANT_TRTYN","HISTORY_OTHER_MALIGNANCY","HISTORY_RELEVANT_INFECTIOUS_DX","HIV_STATUS","ICD_10","ICD_O_3_HISTOLOGY","ICD_O_3_SITE","INFORMED_CONSENT_VERIFIED","INITIAL_PATHOLOGIC_DX_YEAR","IS_FFPE","KARNOFSKY_PERFORMANCE_SCORE","KRAS_GENE_ANALYSIS_INDICATOR","KRAS_MUTATION","KRAS_MUTATION_IDENTIFIED_TYPE","LATERALITY","LOCATION_LUNG_PARENCHYMA","LONGEST_DIMENSION","METHOD_OF_INITIAL_SAMPLE_PROCUREMENT","METHOD_OF_INITIAL_SAMPLE_PROCUREMENT_OTHER","METHOD_OF_SAMPLE_PROCUREMENT","MUTATION_COUNT","MUTATION_STATUS","MUTATION_TYPE","NEW_TUMOR_EVENT_AFTER_INITIAL_TREATMENT","NUMBER_OF_LYMPHNODES_POSITIVE_BY_IHC","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","PERFORMANCE_STATUS_TIMING","PHARMACEUTICAL_TX_ADJUVANT","POS_LYMPH_NODE_LOCATION","PRIMARY_SITE_OTHER","PRIMARY_SITE_PATIENT","PROJECT_CODE","PROSPECTIVE_COLLECTION","PULMONARY_FUNCTION_TEST_INDICATOR","RACE","RADIATION_TREATMENT_ADJUVANT","RESIDUAL_TUMOR","RETROSPECTIVE_COLLECTION","SAMPLE_COUNT","SAMPLE_INITIAL_WEIGHT","SAMPLE_TYPE","SAMPLE_TYPE_ID","SEX","SHORTEST_DIMENSION","SMOKING_PACK_YEARS","SMOKING_YEAR_STARTED","SMOKING_YEAR_STOPPED","SOMATIC_STATUS","SPECIMEN_CURRENT_WEIGHT","SPECIMEN_FREEZING_METHOD","SPECIMEN_SECOND_LONGEST_DIMENSION","STAGE_OTHER","TARGETED_MOLECULAR_THERAPY","TIME_BETWEEN_CLAMPING_AND_FREEZING","TIME_BETWEEN_EXCISION_AND_FREEZING","TISSUE_SOURCE_SITE","TMB_NONSYNONYMOUS","TOBACCO_SMOKING_HISTORY_INDICATOR","TREATMENT_OUTCOME_FIRST_COURS … (6466 more chars) ▶ clickhouse_run_select_query { "query": " SELECT COUNT(DISTINCT patient_unique_id) as patient_count, COUNT(DISTINCT sample_unique_id) as sample_count FROM genomic_event_derived WHERE cancer_study_identifier = 'luad_tcga_pan_can_atlas_2018' AND hugo_gene_symbol = 'EGFR' AND alteration_type = 'cna' AND alteration_sub_type = 'AMP' ", "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 `alteration_type` in scope SELECT COUNTDistinct(patient_unique_id) AS patient_count, COUNTDistinct(sample_unique_id) AS sample_count FROM genomic_event_derived WHERE (cancer_study_identifier = 'luad_tcga_pan_can_atlas_2018') AND (hugo_gene_symbol = 'EGFR') AND (alteration_type = 'cna') AND (alteration_sub_type = 'AMP'). Maybe you meant: ['mutation_type']. (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."}]} ▶ clickhouse_run_select_query { "query": " SELECT COUNT(DISTINCT patient_unique_id) as patient_count, COUNT(DISTINCT sample_unique_id) as sample_count FROM genomic_event_derived WHERE cancer_study_identifier = 'luad_tcga_pan_can_atlas_2018' AND hugo_gene_symbol = 'EGFR' AND variant_type = 'cna' AND cna_alteration = 2 ", "max_rows": 100 } ◀ result {"rows":[{"patient_count":26,"sample_count":26}]} ▶ navigate_to_results_view { "studyIds": [ "luad_tcga_pan_can_atlas_2018" ], "genes": [ "EGFR" ], "tab": "oncoprint" } ◀ result {"success":true,"message":"Navigating to https://www.cbioportal.org/results/oncoprint?cancer_study_list=luad_tcga_pan_can_atlas_2018&gene_list=EGFR&case_set_id=luad_tcga_pan_can_atlas_2018_all","url":"https://www.cbioportal.org/results/oncoprint?cancer_study_list=luad_tcga_pan_can_atlas_2018&gene_list=EGFR&case_set_id=luad_tcga_pan_can_atlas_2018_all","data":{"studyIds":["luad_tcga_pan_can_atlas_2018"],"studies":[{"studyId":"luad_tcga_pan_can_atlas_2018","name":"Lung Adenocarcinoma (TCGA, PanCancer Atlas)","sampleCount":566}],"genes":["EGFR"],"caseSetId":"luad_tcga_pan_can_atlas_2018_all","pageDescription":"Visual summary of alterations in queried genes across samples."}} ═ answer (success) ## Answer **26 patients** have an EGFR amplification in the TCGA Lung Adenocarcinoma study (PanCancer Atlas version), represented across 26 samples. ### Study Details - **Study:** Lung Adenocarcinoma (TCGA, PanCancer Atlas) - **Total samples:** 566 - **EGFR-amplified patients:** 26 (4.6%) - **EGFR-amplified samples:** 26 ### View the Data [View EGFR alterations in OncoPrint](https://www.cbioportal.org/results/oncoprint?cancer_study_list=luad_tcga_pan_can_atlas_2018&gene_list=EGFR&case_set_id=luad_tcga_pan_can_atlas_2018_all) This link shows the OncoPrint visualization of all EGFR alterations (including amplifications, mutations, and other variants) in this cohort.