Connection to public API yields limited study availability

20 views
Skip to first unread message

Jason White

unread,
Mar 3, 2026, 8:12:12 AMMar 3
to cBioPortal for Cancer Genomics Discussion Group
Hello,
My case may be platform specific since I am connecting to the API via R Studio in Code Workspace from Palantir Foundry. After connecting and using command: all_studies <- available_studies() I only see 53 available public studies when there are many more than that when browsing online. Do you know why I have this discrepancy? 

Thanks,
Jason

Gaofei Zhao

unread,
Mar 3, 2026, 10:55:21 AMMar 3
to Jason White, cBioPortal for Cancer Genomics Discussion Group

Hi Jason,

I believe this may be an issue with the cbioportalR package. Could you try using the cBioPortalData package instead to see if that resolves it?

These two closed issues might be related and could provide some additional context:

Please let me know if that works on your end.

Best,
Gaofei


--
You received this message because you are subscribed to the Google Groups "cBioPortal for Cancer Genomics Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cbioportal+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cbioportal/469905c3-49e3-41be-a4a8-471c1a34c860n%40googlegroups.com.

Jason White

unread,
Mar 10, 2026, 6:38:22 PMMar 10
to cBioPortal for Cancer Genomics Discussion Group
Hi Gaofei, 
The links you provided seemed to help with the issue, I can now see 530 studies through our Foundry cbioportal API connection. The code I ended up using is pasted below. I can pull clinical data but I did come across another problem you may be able to address when trying to pull genomic data. I'm using the study ID "brca_tcga_pan_can_Atlas_2018" for my example in Foundry and when I request the available genomic data I can retrieve a dataset with the different molecular profiles available. However when I try to pull the mutation data, I am unable to view the "brca_tcga_pan_can_atlas_2018_mutations" molecularprofileID (seems to only try to return gistic and structural variants) and I get an error saying no mutation data is found. I've also pasted the code and error below.
******
#for clinical data
install.packages(c("httr", "jsonlite"), repos = "https://cran.r-project.org")
library(httr)
library(jsonlite)
# Base URL for cBioPortal API
cbio_base <- "https://www.cbioportal.org/api"

# Get all public studies
get_all_studies <- function() {
  url <- paste0(cbio_base, "/studies?projection=SUMMARY")
  res <- GET(url, add_headers(Accept = "application/json"))
  stop_for_status(res)
  studies <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  return(studies)
}

# Fetch studies and inspect
all_studies <- get_all_studies()
head(all_studies[, c("studyId", "name", "cancerTypeName")])

# Ensure data.frame
all_studies_df <- as.data.frame(all_studies)
str(all_studies_df)

# Drop any nested/list columns (Foundry tabular datasets require flat columns)
all_studies_flat <- dplyr::select(all_studies_df, where(~ !is.list(.)))
str(all_studies_flat)

# Write full studies table to Foundry dataset (simple alias; you can move/organize it in UI)
datasets.write_table(
  data = all_studies_flat,
  alias = "all_studies")

***********
#where study_id is "tcga_brca_pan_can_atlas_2018"
get_mutations_by_study <- function(study_id) {
  cbioportalR::set_cbioportal_db("public")
  genetics_list <- cbioportalR::get_genetics_by_study(study_id = study_id)
  muts <- genetics_list$mutation
  if (!is.null(muts) && nrow(muts) > 0) return(muts)
  # Fallback: fetch mutations via REST API (same profile IDs as in genomic_profiles_flat)
  mutation_profile_id <- paste0(study_id, "_mutations")
  sample_list_id      <- paste0(study_id, "_all")
  url <- paste0(
    cbio_base, "/molecular-profiles/", mutation_profile_id,
    "/mutations?sampleListId=", sample_list_id, "&projection=DETAILED"
  )
  res <- GET(url, add_headers(Accept = "application/json"))
  if (httr::status_code(res) != 200) {
    message("Mutation API returned ", httr::status_code(res), "; no mutation data.")
    return(data.frame())
  }
  out <- fromJSON(content(res, as = "text", encoding = "UTF-8"))
  as.data.frame(out) %>% dplyr::filter(.data$studyId == study_id)
}

cbioportalR::set_cbioportal_db("public")
brca_tcga_pan_can_atlas_muts <- get_mutations_by_study(study_id = study_id)

if (!is.null(brca_tcga_pan_can_atlas_muts) && nrow(brca_tcga_pan_can_atlas_muts) > 0) {
  brca_tcga_mutations_flat <- brca_tcga_pan_can_atlas_muts %>%
    as.data.frame() %>%
    dplyr::select(where(~ !is.list(.)))
  datasets.write_table(
    data  = brca_tcga_mutations_flat,
    alias = "brca_tcga_mutations"
  )
} else {
  message("No mutation data returned for study ", study_id, "; skipping Foundry write.")
}

*****
#error message

Returning all data for the "brca_tcga_pan_can_atlas_2018_gistic" molecular profile in the "brca_tcga_pan_can_atlas_2018" study Returning all data for the "brca_tcga_pan_can_atlas_2018_structural_variants" molecular profile in the "brca_tcga_pan_can_atlas_2018" study ! No "mutation" data returned. Error: In index: 1. Error in get_mutations_by_study(study_id = study_id) : object 'cbio_base' not found



>
Reply all
Reply to author
Forward
0 new messages