Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cBioPortalData() variable recognition failure within wrapper/mapply functions #77

Open
krlong68 opened this issue Aug 29, 2024 · 0 comments

Comments

@krlong68
Copy link

I noticed an issue when trying to wrap the cBioPortalData() function within another function or the mapply() function. It seems that when multiple arguments to cBioPortalData() are being passed in by temporary variables, the function fails to recognize the second variable, throwing the error, Error in FUN(X[[i]], ...): object 'y' not found.

# Load required packages
suppressPackageStartupMessages({
    library(cBioPortalData)
    library(dplyr)  
})

# Set up cBioPortal API
cbio_api <- cBioPortal()

# Create named list of sample IDs according to study ID
sample_list <- list(coadread_mskcc = c("EV-001-M", "EV-023-M", "EV-049-P",
                                       "EV-012-P", "EV-027-M"),
                    mel_mskimpact_2020 = c("P-0040090-T01-IM6",
                                           "P-0004349-T01-IM5",
                                           "P-0015881-T03-IM6",
                                           "P-0005118-T01-IM5",
                                           "P-0010005-T01-IM5"),
                    uvm_tcga = c("TCGA-V4-A9F7-01", "TCGA-WC-A881-01",
                                 "TCGA-VD-A8KJ-01", "TCGA-V4-A9EX-01",
                                 "TCGA-VD-A8KL-01"))

# Select 1st study for individual test
study_a <- names(sample_list)[1]
study_a_samples <- sample_list[[1]]
# Basic application of cBioPortalData(), no issues
study_a_data <- cBioPortalData(api = cbio_api,
                               by = "hugoGeneSymbol",
                               studyId = study_a,
                               sampleIds = study_a_samples,
                               genePanelId = "IMPACT341")
#> harmonizing input:
#>   removing 64 colData rownames not in sampleMap 'primary'
# Create simple wrapper function for cBioPortalData()
wrap_cBPD <- function(x, y) {
    results <- cBioPortalData(api = cbio_api,
                              by = "hugoGeneSymbol",
                              studyId = x,
                              sampleIds = y,
                              genePanelId = "IMPACT341")
    return(results)
}

# Test wrapper function with same data, throws error:
test_data <- wrap_cBPD(study_a, study_a_samples)
#> Error in FUN(X[[i]], ...): object 'y' not found
# Test cBioPortalData() within for loop, no issues
results_list <- list()
for (study in names(sample_list)) {
    study_samples <- sample_list[[study]]
    results <- cBioPortalData(api = cbio_api,
                              by = "hugoGeneSymbol",
                              studyId = study,
                              sampleIds = study_samples,
                              genePanelId = "IMPACT341")
    results_list[[study]] <- results
}
#> harmonizing input:
#>   removing 64 colData rownames not in sampleMap 'primary'
#> harmonizing input:
#>   removing 691 colData rownames not in sampleMap 'primary'
#> harmonizing input:
#>   removing 75 colData rownames not in sampleMap 'primary'
# Test cBioPortalData() within mapply(), throws error:
mapply_test <- mapply(function(x, y) {
    cBioPortalData(api = cbio_api,
                   by = "hugoGeneSymbol",
                   studyId = x,
                   sampleIds = y,
                   genePanelId = "IMPACT341")
}, names(sample_list), sample_list, SIMPLIFY = FALSE)
#> Error in FUN(X[[i]], ...): object 'y' not found

Created on 2024-08-29 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant