[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7357T5SHQ1QCGYFP8PH1MMH":3,"skill-same:01M7357T5SHQ1QCGYFP8PH1MMH":54},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":6,"ownerHtmlUrl":31,"ownerBlogUrl":32,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7357T5SHQ1QCGYFP8PH1MMH","alterlab-cbioportal",null,"Query cBioPortal for cancer genomics data including somatic mutations, copy number alterations, gene expression, and survival data across hundreds of cancer studies. Essential for cancer target validation, oncogene\u002Ftumor suppressor analysis, and patient-level genomic profiling. Part of the AlterLab Academic Skills suite.","roohe\u002Fagentic-super-skills","roohe","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F99054084?v=4","01M734WCDFP6RZVT5CNM00QR26","01M734WCE4BD0T4NZS5PCV9V5F",10,"LGPL-3.0","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Falterlab-cbioportal\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: alterlab-cbioportal\ndescription: Query cBioPortal for cancer genomics data including somatic mutations, copy number alterations, gene expression, and survival data across hundreds of cancer studies. Essential for cancer target validation, oncogene\u002Ftumor suppressor analysis, and patient-level genomic profiling. Part of the AlterLab Academic Skills suite.\nlicense: LGPL-3.0\nmetadata:\n    skill-author: AlterLab\n    version: \"1.0.0\"\n---\n\n# cBioPortal Database\n\n## Overview\n\ncBioPortal for Cancer Genomics (https:\u002F\u002Fwww.cbioportal.org\u002F) is an open-access resource for exploring, visualizing, and analyzing multidimensional cancer genomics data. It hosts data from The Cancer Genome Atlas (TCGA), AACR Project GENIE, MSK-IMPACT, and hundreds of other cancer studies — covering mutations, copy number alterations (CNA), structural variants, mRNA\u002Fprotein expression, methylation, and clinical data for thousands of cancer samples.\n\n**Key resources:**\n- cBioPortal website: https:\u002F\u002Fwww.cbioportal.org\u002F\n- REST API: https:\u002F\u002Fwww.cbioportal.org\u002Fapi\u002Fswagger-ui\u002Findex.html\n- API docs (Swagger): https:\u002F\u002Fwww.cbioportal.org\u002Fapi\u002Fswagger-ui\u002Findex.html\n- Python client: `bravado` or `requests`\n- GitHub: https:\u002F\u002Fgithub.com\u002FcBioPortal\u002Fcbioportal\n\n## When to Use This Skill\n\nUse cBioPortal when:\n\n- **Mutation landscape**: What fraction of a cancer type has mutations in a specific gene?\n- **Oncogene\u002FTSG validation**: Is a gene frequently mutated, amplified, or deleted in cancer?\n- **Co-mutation patterns**: Are mutations in gene A and gene B mutually exclusive or co-occurring?\n- **Survival analysis**: Do mutations in a gene associate with better or worse patient outcomes?\n- **Alteration profiles**: What types of alterations (missense, truncating, amplification, deletion) affect a gene?\n- **Pan-cancer analysis**: Compare alteration frequencies across cancer types\n- **Clinical associations**: Link genomic alterations to clinical variables (stage, grade, treatment response)\n- **TCGA\u002FGENIE exploration**: Systematic access to TCGA and clinical sequencing datasets\n\n## Core Capabilities\n\n### 1. cBioPortal REST API\n\nBase URL: `https:\u002F\u002Fwww.cbioportal.org\u002Fapi`\n\nThe API is RESTful, returns JSON, and requires no API key for public data.\n\n```python\nimport requests\n\nBASE_URL = \"https:\u002F\u002Fwww.cbioportal.org\u002Fapi\"\nHEADERS = {\"Accept\": \"application\u002Fjson\", \"Content-Type\": \"application\u002Fjson\"}\n\ndef cbioportal_get(endpoint, params=None):\n    url = f\"{BASE_URL}\u002F{endpoint}\"\n    response = requests.get(url, params=params, headers=HEADERS)\n    response.raise_for_status()\n    return response.json()\n\ndef cbioportal_post(endpoint, body):\n    url = f\"{BASE_URL}\u002F{endpoint}\"\n    response = requests.post(url, json=body, headers=HEADERS)\n    response.raise_for_status()\n    return response.json()\n```\n\n### 2. Browse Studies\n\n```python\ndef get_all_studies():\n    \"\"\"List all available cancer studies.\"\"\"\n    return cbioportal_get(\"studies\", {\"pageSize\": 500})\n\n# Each study has:\n# studyId: unique identifier (e.g., \"brca_tcga\")\n# name: human-readable name\n# description: dataset description\n# cancerTypeId: cancer type abbreviation\n# referenceGenome: GRCh37 or GRCh38\n# pmid: associated publication\n\nstudies = get_all_studies()\nprint(f\"Total studies: {len(studies)}\")\n\n# Common TCGA study IDs:\n# brca_tcga, luad_tcga, coadread_tcga, gbm_tcga, prad_tcga,\n# skcm_tcga, blca_tcga, hnsc_tcga, lihc_tcga, stad_tcga\n\n# Filter for TCGA studies\ntcga_studies = [s for s in studies if \"tcga\" in s[\"studyId\"]]\nprint([s[\"studyId\"] for s in tcga_studies[:10]])\n```\n\n### 3. Molecular Profiles\n\nEach study has multiple molecular profiles (mutation, CNA, expression, etc.):\n\n```python\ndef get_molecular_profiles(study_id):\n    \"\"\"Get all molecular profiles for a study.\"\"\"\n    return cbioportal_get(f\"studies\u002F{study_id}\u002Fmolecular-profiles\")\n\nprofiles = get_molecular_profiles(\"brca_tcga\")\nfor p in profiles:\n    print(f\"  {p['molecularProfileId']}: {p['name']} ({p['molecularAlterationType']})\")\n\n# Alteration types:\n# MUTATION_EXTENDED — somatic mutations\n# COPY_NUMBER_ALTERATION — CNA (GISTIC)\n# MRNA_EXPRESSION — mRNA expression\n# PROTEIN_LEVEL — RPPA protein expression\n# STRUCTURAL_VARIANT — fusions\u002Frearrangements\n```\n\n### 4. Mutation Data\n\n```python\ndef get_mutations(molecular_profile_id, entrez_gene_ids, sample_list_id=None):\n    \"\"\"Get mutations for specified genes in a molecular profile.\"\"\"\n    body = {\n        \"entrezGeneIds\": entrez_gene_ids,\n        \"sampleListId\": sample_list_id or molecular_profile_id.replace(\"_mutations\", \"_all\")\n    }\n    return cbioportal_post(\n        f\"molecular-profiles\u002F{molecular_profile_id}\u002Fmutations\u002Ffetch\",\n        body\n    )\n\n# BRCA1 Entrez ID is 672, TP53 is 7157, PTEN is 5728\nmutations = get_mutations(\"brca_tcga_mutations\", entrez_gene_ids=[7157])  # TP53\n\n# Each mutation record contains:\n# patientId, sampleId, entrezGeneId, gene.hugoGeneSymbol\n# mutationType (Missense_Mutation, Nonsense_Mutation, Frame_Shift_Del, etc.)\n# proteinChange (e.g., \"R175H\")\n# variantClassification, variantType\n# ncbiBuild, chr, startPosition, endPosition, referenceAllele, variantAllele\n# mutationStatus (Somatic\u002FGermline)\n# alleleFreqT (tumor VAF)\n\nimport pandas as pd\ndf = pd.DataFrame(mutations)\nprint(df[[\"patientId\", \"mutationType\", \"proteinChange\", \"alleleFreqT\"]].head())\nprint(f\"\\nMutation types:\\n{df['mutationType'].value_counts()}\")\n```\n\n### 5. Copy Number Alteration Data\n\n```python\ndef get_cna(molecular_profile_id, entrez_gene_ids):\n    \"\"\"Get discrete CNA data (GISTIC: -2, -1, 0, 1, 2).\"\"\"\n    body = {\n        \"entrezGeneIds\": entrez_gene_ids,\n        \"sampleListId\": molecular_profile_id.replace(\"_gistic\", \"_all\").replace(\"_cna\", \"_all\")\n    }\n    return cbioportal_post(\n        f\"molecular-profiles\u002F{molecular_profile_id}\u002Fdiscrete-copy-number\u002Ffetch\",\n        body\n    )\n\n# GISTIC values:\n# -2 = Deep deletion (homozygous loss)\n# -1 = Shallow deletion (heterozygous loss)\n#  0 = Diploid (neutral)\n#  1 = Low-level gain\n#  2 = High-level amplification\n\ncna_data = get_cna(\"brca_tcga_gistic\", entrez_gene_ids=[1956])  # EGFR\ndf_cna = pd.DataFrame(cna_data)\nprint(df_cna[\"value\"].value_counts())\n```\n\n### 6. Alteration Frequency (OncoPrint-style)\n\n```python\ndef get_alteration_frequency(study_id, gene_symbols, alteration_types=None):\n    \"\"\"Compute alteration frequencies for genes across a cancer study.\"\"\"\n    import requests, pandas as pd\n\n    # Get sample list\n    samples = requests.get(\n        f\"{BASE_URL}\u002Fstudies\u002F{study_id}\u002Fsample-lists\",\n        headers=HEADERS\n    ).json()\n    all_samples_id = next(\n        (s[\"sampleListId\"] for s in samples if s[\"category\"] == \"all_cases_in_study\"), None\n    )\n    total_samples = len(requests.get(\n        f\"{BASE_URL}\u002Fsample-lists\u002F{all_samples_id}\u002Fsample-ids\",\n        headers=HEADERS\n    ).json())\n\n    # Get gene Entrez IDs\n    gene_data = requests.post(\n        f\"{BASE_URL}\u002Fgenes\u002Ffetch\",\n        json=[{\"hugoGeneSymbol\": g} for g in gene_symbols],\n        headers=HEADERS\n    ).json()\n    entrez_ids = [g[\"entrezGeneId\"] for g in gene_data]\n\n    # Get mutations\n    mutation_profile = f\"{study_id}_mutations\"\n    mutations = get_mutations(mutation_profile, entrez_ids, all_samples_id)\n\n    freq = {}\n    for g_symbol, e_id in zip(gene_symbols, entrez_ids):\n        mutated = len(set(m[\"patientId\"] for m in mutations if m[\"entrezGeneId\"] == e_id))\n        freq[g_symbol] = mutated \u002F total_samples * 100\n\n    return freq\n\n# Example\nfreq = get_alteration_frequency(\"brca_tcga\", [\"TP53\", \"PIK3CA\", \"BRCA1\", \"BRCA2\"])\nfor gene, pct in sorted(freq.items(), key=lambda x: -x[1]):\n    print(f\"  {gene}: {pct:.1f}%\")\n```\n\n### 7. Clinical Data\n\n```python\ndef get_clinical_data(study_id, attribute_ids=None):\n    \"\"\"Get patient-level clinical data.\"\"\"\n    params = {\"studyId\": study_id}\n    all_clinical = cbioportal_get(\n        \"clinical-data\u002Ffetch\",\n        params\n    )\n    # Returns list of {patientId, studyId, clinicalAttributeId, value}\n\n# Clinical attributes include:\n# OS_STATUS, OS_MONTHS, DFS_STATUS, DFS_MONTHS (survival)\n# TUMOR_STAGE, GRADE, AGE, SEX, RACE\n# Study-specific attributes vary\n\ndef get_clinical_attributes(study_id):\n    \"\"\"List all available clinical attributes for a study.\"\"\"\n    return cbioportal_get(f\"studies\u002F{study_id}\u002Fclinical-attributes\")\n```\n\n## Query Workflows\n\n### Workflow 1: Gene Alteration Profile in a Cancer Type\n\n```python\nimport requests, pandas as pd\n\ndef alteration_profile(study_id, gene_symbol):\n    \"\"\"Full alteration profile for a gene in a cancer study.\"\"\"\n\n    # 1. Get gene Entrez ID\n    gene_info = requests.post(\n        f\"{BASE_URL}\u002Fgenes\u002Ffetch\",\n        json=[{\"hugoGeneSymbol\": gene_symbol}],\n        headers=HEADERS\n    ).json()[0]\n    entrez_id = gene_info[\"entrezGeneId\"]\n\n    # 2. Get mutations\n    mutations = get_mutations(f\"{study_id}_mutations\", [entrez_id])\n    mut_df = pd.DataFrame(mutations) if mutations else pd.DataFrame()\n\n    # 3. Get CNAs\n    cna = get_cna(f\"{study_id}_gistic\", [entrez_id])\n    cna_df = pd.DataFrame(cna) if cna else pd.DataFrame()\n\n    # 4. Summary\n    n_mut = len(set(mut_df[\"patientId\"])) if not mut_df.empty else 0\n    n_amp = len(cna_df[cna_df[\"value\"] == 2]) if not cna_df.empty else 0\n    n_del = len(cna_df[cna_df[\"value\"] == -2]) if not cna_df.empty else 0\n\n    return {\"mutations\": n_mut, \"amplifications\": n_amp, \"deep_deletions\": n_del}\n\nresult = alteration_profile(\"brca_tcga\", \"PIK3CA\")\nprint(result)\n```\n\n### Workflow 2: Pan-Cancer Gene Mutation Frequency\n\n```python\nimport requests, pandas as pd\n\ndef pan_cancer_mutation_freq(gene_symbol, cancer_study_ids=None):\n    \"\"\"Mutation frequency of a gene across multiple cancer types.\"\"\"\n    studies = get_all_studies()\n    if cancer_study_ids:\n        studies = [s for s in studies if s[\"studyId\"] in cancer_study_ids]\n\n    results = []\n    for study in studies[:20]:  # Limit for demo\n        try:\n            freq = get_alteration_frequency(study[\"studyId\"], [gene_symbol])\n            results.append({\n                \"study\": study[\"studyId\"],\n                \"cancer\": study.get(\"cancerTypeId\", \"\"),\n                \"mutation_pct\": freq.get(gene_symbol, 0)\n            })\n        except Exception:\n            pass\n\n    df = pd.DataFrame(results).sort_values(\"mutation_pct\", ascending=False)\n    return df\n```\n\n### Workflow 3: Survival Analysis by Mutation Status\n\n```python\nimport requests, pandas as pd\n\ndef survival_by_mutation(study_id, gene_symbol):\n    \"\"\"Get survival data split by mutation status.\"\"\"\n    # This workflow fetches clinical and mutation data for downstream analysis\n\n    gene_info = requests.post(\n        f\"{BASE_URL}\u002Fgenes\u002Ffetch\",\n        json=[{\"hugoGeneSymbol\": gene_symbol}],\n        headers=HEADERS\n    ).json()[0]\n    entrez_id = gene_info[\"entrezGeneId\"]\n\n    mutations = get_mutations(f\"{study_id}_mutations\", [entrez_id])\n    mutated_patients = set(m[\"patientId\"] for m in mutations)\n\n    clinical = cbioportal_get(\"clinical-data\u002Ffetch\", {\"studyId\": study_id})\n    clinical_df = pd.DataFrame(clinical)\n\n    os_data = clinical_df[clinical_df[\"clinicalAttributeId\"].isin([\"OS_MONTHS\", \"OS_STATUS\"])]\n    os_wide = os_data.pivot(index=\"patientId\", columns=\"clinicalAttributeId\", values=\"value\")\n    os_wide[\"mutated\"] = os_wide.index.isin(mutated_patients)\n\n    return os_wide\n```\n\n## Key API Endpoints Summary\n\n| Endpoint | Description |\n|----------|-------------|\n| `GET \u002Fstudies` | List all studies |\n| `GET \u002Fstudies\u002F{studyId}\u002Fmolecular-profiles` | Molecular profiles for a study |\n| `POST \u002Fmolecular-profiles\u002F{profileId}\u002Fmutations\u002Ffetch` | Get mutation data |\n| `POST \u002Fmolecular-profiles\u002F{profileId}\u002Fdiscrete-copy-number\u002Ffetch` | Get CNA data |\n| `POST \u002Fmolecular-profiles\u002F{profileId}\u002Fmolecular-data\u002Ffetch` | Get expression data |\n| `GET \u002Fstudies\u002F{studyId}\u002Fclinical-attributes` | Available clinical variables |\n| `GET \u002Fclinical-data\u002Ffetch` | Clinical data |\n| `POST \u002Fgenes\u002Ffetch` | Gene metadata by symbol or Entrez ID |\n| `GET \u002Fstudies\u002F{studyId}\u002Fsample-lists` | Sample lists |\n\n## Best Practices\n\n- **Know your study IDs**: Use the Swagger UI or `GET \u002Fstudies` to find the correct study ID\n- **Use sample lists**: Each study has an `all` sample list and subsets; always specify the appropriate one\n- **TCGA vs. GENIE**: TCGA data is comprehensive but older; GENIE has more recent clinical sequencing data\n- **Entrez gene IDs**: The API uses Entrez IDs — use `\u002Fgenes\u002Ffetch` to convert from symbols\n- **Handle 404s**: Some molecular profiles may not exist for all studies\n- **Rate limiting**: Add delays for bulk queries; consider downloading data files for large-scale analyses\n\n## Data Downloads\n\nFor large-scale analyses, download study data directly:\n```bash\n# Download TCGA BRCA data\nwget https:\u002F\u002Fcbioportal-datahub.s3.amazonaws.com\u002Fbrca_tcga.tar.gz\n```\n\n## Additional Resources\n\n- **cBioPortal website**: https:\u002F\u002Fwww.cbioportal.org\u002F\n- **API Swagger UI**: https:\u002F\u002Fwww.cbioportal.org\u002Fapi\u002Fswagger-ui\u002Findex.html\n- **Documentation**: https:\u002F\u002Fdocs.cbioportal.org\u002F\n- **GitHub**: https:\u002F\u002Fgithub.com\u002FcBioPortal\u002Fcbioportal\n- **Data hub**: https:\u002F\u002Fwww.cbioportal.org\u002Fdatasets\n- **Citation**: Cerami E et al. (2012) Cancer Discovery. PMID: 22588877\n- **API clients**: https:\u002F\u002Fdocs.cbioportal.org\u002Fweb-api-and-clients\u002F\n","# cBioPortal Database\n\n## Overview\n\ncBioPortal for Cancer Genomics (https:\u002F\u002Fwww.cbioportal.org\u002F) is an open-access resource for exploring, visualizing, and analyzing multidimensional cancer genomics data. It hosts data from The Cancer Genome Atlas (TCGA), AACR Project GENIE, MSK-IMPACT, and hundreds of other cancer studies — covering mutations, copy number alterations (CNA), structural variants, mRNA\u002Fprotein expression, methylation, and clinical data for thousands of cancer samples.\n\n**Key resources:**\n- cBioPortal website: https:\u002F\u002Fwww.cbioportal.org\u002F\n- REST API: https:\u002F\u002Fwww.cbioportal.org\u002Fapi\u002Fswagger-ui\u002Findex.html\n- API docs (Swagger): https:\u002F\u002Fwww.cbioportal.org\u002Fapi\u002Fswagger-ui\u002Findex.html\n- Python client: `bravado` or `requests`\n- GitHub: https:\u002F\u002Fgithub.com\u002FcBioPortal\u002Fcbioportal\n\n## When to Use This Skill\n\nUse cBioPortal when:\n\n- **Mutation landscape**: What fraction of a cancer type has mutations in a specific gene?\n- **Oncogene\u002FTSG validation**: Is a gene frequently mutated, amplified, or deleted in cancer?\n- **Co-mutation patterns**: Are mutations in gene A and gene B mutually exclusive or co-occurring?\n- **Survival analysis**: Do mutations in a gene associate with better or worse patient outcomes?\n- **Alteration profiles**: What types of alterations (missense, truncating, amplification, deletion) affect a gene?\n- **Pan-cancer analysis**: Compare alteration frequencies across cancer types\n- **Clinical associations**: Link genomic alterations to clinical variables (stage, grade, treatment response)\n- **TCGA\u002FGENIE exploration**: Systematic access to TCGA and clinical sequencing datasets\n\n## Core Capabilities\n\n### 1. cBioPortal REST API\n\nBase URL: `https:\u002F\u002Fwww.cbioportal.org\u002Fapi`\n\nThe API is RESTful, returns JSON, and requires no API key for public data.\n\n```python\nimport requests\n\nBASE_URL = \"https:\u002F\u002Fwww.cbioportal.org\u002Fapi\"\nHEADERS = {\"Accept\": \"application\u002Fjson\", \"Content-Type\": \"application\u002Fjson\"}\n\ndef cbioportal_get(endpoint, params=None):\n    url = f\"{BASE_URL}\u002F{endpoint}\"\n    response = requests.get(url, params=params, headers=HEADERS)\n    response.raise_for_status()\n    return response.json()\n\ndef cbioportal_post(endpoint, body):\n    url = f\"{BASE_URL}\u002F{endpoint}\"\n    response = requests.post(url, json=body, headers=HEADERS)\n    response.raise_for_status()\n    return response.json()\n```\n\n### 2. Browse Studies\n\n```python\ndef get_all_studies():\n    \"\"\"List all available cancer studies.\"\"\"\n    return cbioportal_get(\"studies\", {\"pageSize\": 500})\n\n# Each study has:\n# studyId: unique identifier (e.g., \"brca_tcga\")\n# name: human-readable name\n# description: dataset description\n# cancerTypeId: cancer type abbreviation\n# referenceGenome: GRCh37 or GRCh38\n# pmid: associated publication\n\nstudies = get_all_studies()\nprint(f\"Total studies: {len(studies)}\")\n\n# Common TCGA study IDs:\n# brca_tcga, luad_tcga, coadread_tcga, gbm_tcga, prad_tcga,\n# skcm_tcga, blca_tcga, hnsc_tcga, lihc_tcga, stad_tcga\n\n# Filter for TCGA studies\ntcga_studies = [s for s in studies if \"tcga\" in s[\"studyId\"]]\nprint([s[\"studyId\"] for s in tcga_studies[:10]])\n```\n\n### 3. Molecular Profiles\n\nEach study has multiple molecular profiles (mutation, CNA, expression, etc.):\n\n```python\ndef get_molecular_profiles(study_id):\n    \"\"\"Get all molecular profiles for a study.\"\"\"\n    return cbioportal_get(f\"studies\u002F{study_id}\u002Fmolecular-profiles\")\n\nprofiles = get_molecular_profiles(\"brca_tcga\")\nfor p in profiles:\n    print(f\"  {p['molecularProfileId']}: {p['name']} ({p['molecularAlterationType']})\")\n\n# Alteration types:\n# MUTATION_EXTENDED — somatic mutations\n# COPY_NUMBER_ALTERATION — CNA (GISTIC)\n# MRNA_EXPRESSION — mRNA expression\n# PROTEIN_LEVEL — RPPA protein expression\n# STRUCTURAL_VARIANT — fusions\u002Frearrangements\n```\n\n### 4. Mutation Data\n\n```python\ndef get_mutations(molecular_profile_id, entrez_gene_ids, sample_list_id=None):\n    \"\"\"Get mutations for specified genes in a molecular profile.\"\"\"\n    body = {\n        \"entrezGeneIds\": entrez_gene_ids,\n        \"sampleListId\": sample_list_id or molecular_profile_id.replace(\"_mutations\", \"_all\")\n    }\n    return cbioportal_post(\n        f\"molecular-profiles\u002F{molecular_profile_id}\u002Fmutations\u002Ffetch\",\n        body\n    )\n\n# BRCA1 Entrez ID is 672, TP53 is 7157, PTEN is 5728\nmutations = get_mutations(\"brca_tcga_mutations\", entrez_gene_ids=[7157])  # TP53\n\n# Each mutation record contains:\n# patientId, sampleId, entrezGeneId, gene.hugoGeneSymbol\n# mutationType (Missense_Mutation, Nonsense_Mutation, Frame_Shift_Del, etc.)\n# proteinChange (e.g., \"R175H\")\n# variantClassification, variantType\n# ncbiBuild, chr, startPosition, endPosition, referenceAllele, variantAllele\n# mutationStatus (Somatic\u002FGermline)\n# alleleFreqT (tumor VAF)\n\nimport pandas as pd\ndf = pd.DataFrame(mutations)\nprint(df[[\"patientId\", \"mutationType\", \"proteinChange\", \"alleleFreqT\"]].head())\nprint(f\"\\nMutation types:\\n{df['mutationType'].value_counts()}\")\n```\n\n### 5. Copy Number Alteration Data\n\n```python\ndef get_cna(molecular_profile_id, entrez_gene_ids):\n    \"\"\"Get discrete CNA data (GISTIC: -2, -1, 0, 1, 2).\"\"\"\n    body = {\n        \"entrezGeneIds\": entrez_gene_ids,\n        \"sampleListId\": molecular_profile_id.replace(\"_gistic\", \"_all\").replace(\"_cna\", \"_all\")\n    }\n    return cbioportal_post(\n        f\"molecular-profiles\u002F{molecular_profile_id}\u002Fdiscrete-copy-number\u002Ffetch\",\n        body\n    )\n\n# GISTIC values:\n# -2 = Deep deletion (homozygous loss)\n# -1 = Shallow deletion (heterozygous loss)\n#  0 = Diploid (neutral)\n#  1 = Low-level gain\n#  2 = High-level amplification\n\ncna_data = get_cna(\"brca_tcga_gistic\", entrez_gene_ids=[1956])  # EGFR\ndf_cna = pd.DataFrame(cna_data)\nprint(df_cna[\"value\"].value_counts())\n```\n\n### 6. Alteration Frequency (OncoPrint-style)\n\n```python\ndef get_alteration_frequency(study_id, gene_symbols, alteration_types=None):\n    \"\"\"Compute alteration frequencies for genes across a cancer study.\"\"\"\n    import requests, pandas as pd\n\n    # Get sample list\n    samples = requests.get(\n        f\"{BASE_URL}\u002Fstudies\u002F{study_id}\u002Fsample-lists\",\n        headers=HEADERS\n    ).json()\n    all_samples_id = next(\n        (s[\"sampleListId\"] for s in samples if s[\"category\"] == \"all_cases_in_study\"), None\n    )\n    total_samples = len(requests.get(\n        f\"{BASE_URL}\u002Fsample-lists\u002F{all_samples_id}\u002Fsample-ids\",\n        headers=HEADERS\n    ).json())\n\n    # Get gene Entrez IDs\n    gene_data = requests.post(\n        f\"{BASE_URL}\u002Fgenes\u002Ffetch\",\n        json=[{\"hugoGeneSymbol\": g} for g in gene_symbols],\n        headers=HEADERS\n    ).json()\n    entrez_ids = [g[\"entrezGeneId\"] for g in gene_data]\n\n    # Get mutations\n    mutation_profile = f\"{study_id}_mutations\"\n    mutations = get_mutations(mutation_profile, entrez_ids, all_samples_id)\n\n    freq = {}\n    for g_symbol, e_id in zip(gene_symbols, entrez_ids):\n        mutated = len(set(m[\"patientId\"] for m in mutations if m[\"entrezGeneId\"] == e_id))\n        freq[g_symbol] = mutated \u002F total_samples * 100\n\n    return freq\n\n# Example\nfreq = get_alteration_frequency(\"brca_tcga\", [\"TP53\", \"PIK3CA\", \"BRCA1\", \"BRCA2\"])\nfor gene, pct in sorted(freq.items(), key=lambda x: -x[1]):\n    print(f\"  {gene}: {pct:.1f}%\")\n```\n\n### 7. Clinical Data\n\n```python\ndef get_clinical_data(study_id, attribute_ids=None):\n    \"\"\"Get patient-level clinical data.\"\"\"\n    params = {\"studyId\": study_id}\n    all_clinical = cbioportal_get(\n        \"clinical-data\u002Ffetch\",\n        params\n    )\n    # Returns list of {patientId, studyId, clinicalAttributeId, value}\n\n# Clinical attributes include:\n# OS_STATUS, OS_MONTHS, DFS_STATUS, DFS_MONTHS (survival)\n# TUMOR_STAGE, GRADE, AGE, SEX, RACE\n# Study-specific attributes vary\n\ndef get_clinical_attributes(study_id):\n    \"\"\"List all available clinical attributes for a study.\"\"\"\n    return cbioportal_get(f\"studies\u002F{study_id}\u002Fclinical-attributes\")\n```\n\n## Query Workflows\n\n### Workflow 1: Gene Alteration Profile in a Cancer Type\n\n```python\nimport requests, pandas as pd\n\ndef alteration_profile(study_id, gene_symbol):\n    \"\"\"Full alteration profile for a gene in a cancer study.\"\"\"\n\n    # 1. Get gene Entrez ID\n    gene_info = requests.post(\n        f\"{BASE_URL}\u002Fgenes\u002Ffetch\",\n        json=[{\"hugoGeneSymbol\": gene_symbol}],\n        headers=HEADERS\n    ).json()[0]\n    entrez_id = gene_info[\"entrezGeneId\"]\n\n    # 2. Get mutations\n    mutations = get_mutations(f\"{study_id}_mutations\", [entrez_id])\n    mut_df = pd.DataFrame(mutations) if mutations else pd.DataFrame()\n\n    # 3. Get CNAs\n    cna = get_cna(f\"{study_id}_gistic\", [entrez_id])\n    cna_df = pd.DataFrame(cna) if cna else pd.DataFrame()\n\n    # 4. Summary\n    n_mut = len(set(mut_df[\"patientId\"])) if not mut_df.empty else 0\n    n_amp = len(cna_df[cna_df[\"value\"] == 2]) if not cna_df.empty else 0\n    n_del = len(cna_df[cna_df[\"value\"] == -2]) if not cna_df.empty else 0\n\n    return {\"mutations\": n_mut, \"amplifications\": n_amp, \"deep_deletions\": n_del}\n\nresult = alteration_profile(\"brca_tcga\", \"PIK3CA\")\nprint(result)\n```\n\n### Workflow 2: Pan-Cancer Gene Mutation Frequency\n\n```python\nimport requests, pandas as pd\n\ndef pan_cancer_mutation_freq(gene_symbol, cancer_study_ids=None):\n    \"\"\"Mutation frequency of a gene across multiple cancer types.\"\"\"\n    studies = get_all_studies()\n    if cancer_study_ids:\n        studies = [s for s in studies if s[\"studyId\"] in cancer_study_ids]\n\n    results = []\n    for study in studies[:20]:  # Limit for demo\n        try:\n            freq = get_alteration_frequency(study[\"studyId\"], [gene_symbol])\n            results.append({\n                \"study\": study[\"studyId\"],\n                \"cancer\": study.get(\"cancerTypeId\", \"\"),\n                \"mutation_pct\": freq.get(gene_symbol, 0)\n            })\n        except Exception:\n            pass\n\n    df = pd.DataFrame(results).sort_values(\"mutation_pct\", ascending=False)\n    return df\n```\n\n### Workflow 3: Survival Analysis by Mutation Status\n\n```python\nimport requests, pandas as pd\n\ndef survival_by_mutation(study_id, gene_symbol):\n    \"\"\"Get survival data split by mutation status.\"\"\"\n    # This workflow fetches clinical and mutation data for downstream analysis\n\n    gene_info = requests.post(\n        f\"{BASE_URL}\u002Fgenes\u002Ffetch\",\n        json=[{\"hugoGeneSymbol\": gene_symbol}],\n        headers=HEADERS\n    ).json()[0]\n    entrez_id = gene_info[\"entrezGeneId\"]\n\n    mutations = get_mutations(f\"{study_id}_mutations\", [entrez_id])\n    mutated_patients = set(m[\"patientId\"] for m in mutations)\n\n    clinical = cbioportal_get(\"clinical-data\u002Ffetch\", {\"studyId\": study_id})\n    clinical_df = pd.DataFrame(clinical)\n\n    os_data = clinical_df[clinical_df[\"clinicalAttributeId\"].isin([\"OS_MONTHS\", \"OS_STATUS\"])]\n    os_wide = os_data.pivot(index=\"patientId\", columns=\"clinicalAttributeId\", values=\"value\")\n    os_wide[\"mutated\"] = os_wide.index.isin(mutated_patients)\n\n    return os_wide\n```\n\n## Key API Endpoints Summary\n\n| Endpoint | Description |\n|----------|-------------|\n| `GET \u002Fstudies` | List all studies |\n| `GET \u002Fstudies\u002F{studyId}\u002Fmolecular-profiles` | Molecular profiles for a study |\n| `POST \u002Fmolecular-profiles\u002F{profileId}\u002Fmutations\u002Ffetch` | Get mutation data |\n| `POST \u002Fmolecular-profiles\u002F{profileId}\u002Fdiscrete-copy-number\u002Ffetch` | Get CNA data |\n| `POST \u002Fmolecular-profiles\u002F{profileId}\u002Fmolecular-data\u002Ffetch` | Get expression data |\n| `GET \u002Fstudies\u002F{studyId}\u002Fclinical-attributes` | Available clinical variables |\n| `GET \u002Fclinical-data\u002Ffetch` | Clinical data |\n| `POST \u002Fgenes\u002Ffetch` | Gene metadata by symbol or Entrez ID |\n| `GET \u002Fstudies\u002F{studyId}\u002Fsample-lists` | Sample lists |\n\n## Best Practices\n\n- **Know your study IDs**: Use the Swagger UI or `GET \u002Fstudies` to find the correct study ID\n- **Use sample lists**: Each study has an `all` sample list and subsets; always specify the appropriate one\n- **TCGA vs. GENIE**: TCGA data is comprehensive but older; GENIE has more recent clinical sequencing data\n- **Entrez gene IDs**: The API uses Entrez IDs — use `\u002Fgenes\u002Ffetch` to convert from symbols\n- **Handle 404s**: Some molecular profiles may not exist for all studies\n- **Rate limiting**: Add delays for bulk queries; consider downloading data files for large-scale analyses\n\n## Data Downloads\n\nFor large-scale analyses, download study data directly:\n```bash\n# Download TCGA BRCA data\nwget https:\u002F\u002Fcbioportal-datahub.s3.amazonaws.com\u002Fbrca_tcga.tar.gz\n```\n\n## Additional Resources\n\n- **cBioPortal website**: https:\u002F\u002Fwww.cbioportal.org\u002F\n- **API Swagger UI**: https:\u002F\u002Fwww.cbioportal.org\u002Fapi\u002Fswagger-ui\u002Findex.html\n- **Documentation**: https:\u002F\u002Fdocs.cbioportal.org\u002F\n- **GitHub**: https:\u002F\u002Fgithub.com\u002FcBioPortal\u002Fcbioportal\n- **Data hub**: https:\u002F\u002Fwww.cbioportal.org\u002Fdatasets\n- **Citation**: Cerami E et al. (2012) Cancer Discovery. PMID: 22588877\n- **API clients**: https:\u002F\u002Fdocs.cbioportal.org\u002Fweb-api-and-clients\u002F\n",{"name":5,"license":14,"metadata":23,"description":7},{"version":24,"skill-author":25},"1.0.0","AlterLab","master","f483e54f3ad5f202a77d45f2e57f8d970b71195f","skills_library\u002Falterlab-cbioportal",2,"https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills","https:\u002F\u002Fgithub.com\u002Froohe","yoou.link","2026-05-19 15:56:07",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add roohe\u002Fagentic-super-skills --skill alterlab-cbioportal",{"tool":40,"command":41},"bunx","bunx skills add roohe\u002Fagentic-super-skills --skill alterlab-cbioportal",{"tool":43,"command":44},"pnpm","pnpm dlx skills add roohe\u002Fagentic-super-skills --skill alterlab-cbioportal","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Falterlab-cbioportal\u002FSKILL.md",true,[48],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":52,"sourceHtmlUrl":53},"references\u002Fstudy_exploration.md","REFERENCE","参考文档",4411,"https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Falterlab-cbioportal\u002Freferences\u002Fstudy_exploration.md",[55,63,70,77,84,91],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":59,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":18},"01M73D865CZME2FCMKA4PQM348","zarr-python","Chunked N-D arrays for cloud storage. Compressed arrays, parallel I\u002FO, S3\u002FGCS integration, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","MIT","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":59,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":18},"01M73D7Z64J4ABWZJD7P44XBBF","youtube-downloader","Download and process YouTube content for research. Use when: downloading competitor videos for analysis; extracting audio for podcasts; getting transcripts for content repurposing; archiving webinars; research content curation","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fyoutube-downloader\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":59,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":18},"01M73D7K8778TGZV3GJFR3703D","yc-pitch-deck","Create a compelling startup pitch deck that follows the structure proven to raise billions from top investors. Master the YC and Sequoia formats that get founders funded. Use when: **Fundraising** to create investor pitch decks; **YC application** to structure your narrative; **Demo Day prep** to craft your 2-minute pitch; **Angel investors** to communicate your opportunity; **Partnership pitches** to structure compelling asks","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fyc-pitch-deck\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":59,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":18},"01M73D70KJSE0E8Z28YMNNRT04","x-twitter-scraper","Use when the user needs X (Twitter) data or confirmation-gated X actions through Xquik: tweet search, user lookup, follower extraction, media download, monitoring, webhooks, MCP, SDKs, posting, likes, DMs, and profile updates. Requires a Xquik API key. Never ask for X login material.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fx-twitter-scraper\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":59,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":18},"01M73D6ED01GV077R7K4NZNFZJ","write-vignette","Create R package vignettes using R Markdown or Quarto. Covers vignette setup, YAML configuration, code chunk options, building and testing, and CRAN requirements for vignettes. Use when adding a Getting Started tutorial, documenting complex workflows spanning multiple functions, creating domain-specific guides, or when CRAN submission requires user-facing documentation beyond function help pages.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fwrite-vignette\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":59,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":18},"01M73D69YJR0BK3NFHE0CYG3EF","write-validation-documentation","Write IQ\u002FOQ\u002FPQ validation documentation for computerized systems in regulated environments. Covers protocols, reports, test scripts, deviation handling, and approval workflows. Use when validating R or other software for regulated use, preparing for a regulatory audit, documenting qualification of computing environments, or creating and updating validation protocols and reports for new or re-qualified systems.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fwrite-validation-documentation\u002FSKILL.md",[],[]]