girke-lab / signatureSearch

R/Bioconductor package including the Gene Expression Signature Search (GESS), Function Enrichment Analysis (FEA) methods and supporting drug-target network construction for visualization
17 stars 4 forks source link

Unknown error when running gess method #13

Closed aadamk closed 1 year ago

aadamk commented 1 year ago

Hello, I am facing an error when running gess_lincs or gess_cor. The code below is embedded in a function where I select either "LINCS" or "Cor" based methods and assemble the appropriate data structure for each respective method. For "LINCS", I take two character vectors of Entrez Gene IDs (upset, downset) and put in a qSig object. For "Cor", I produce a one-column matrix with log2FC as the score and entrez gene IDs as the rownames.

Both methods result in the following error: Error in d$value$value : $ operator is invalid for atomic vectors I am unsure where the subsetting issue arises as I am passing a qsig object to the functions as directed in the documentation.

Below is my code for reference.

eh <- ExperimentHub()
lincs <- eh[["EH7297"]]

 if(method == "LINCS"){

    # map to ENTREZ identifiers
    upset = mapIds(org.Hs.eg.db, keys = cluster_upset$genes, column = "ENTREZID", keytype = "SYMBOL")
    downset = mapIds(org.Hs.eg.db, keys = cluster_downset$genes, column = "ENTREZID", keytype = "SYMBOL")

    # LINCS-based similarity metric
    qSig_output <- qSig(query = list(upset = upset, downset = downset), gess_method = "LINCS", refdb = lincs)
    qSig_output <- gess_lincs(qSig = qSig_output, sortby = "NCS", tau = T, workers = 4)
    qSig_output <- result(qSig_output)

    # filter drugs
    qSig_output <- qSig_output %>%
      filter(trend == trend_val & WTCS_FDR < wtcs_fdr_cutoff)
    drugs <- unique(qSig_output$pert)

  } else if(method == "Cor"){

    # correlation-based similarity
    query_mat <- cluster_upset %>%
      plyr::rbind.fill(cluster_downset) %>% 
      mutate(id = mapIds(org.Hs.eg.db, keys = geneSymbol, column = "ENTREZID", keytype = "SYMBOL")) %>% 
      arrange(id) %>% 
      filter(!is.na(id)) %>%
      column_to_rownames('id') %>%
      dplyr::select(score) %>% as.matrix()

    qSig_output <- qSig(query = query_mat, gess_method = "Cor", refdb = lincs)
    qSig_output <- gess_cor(qSig = qSig_output, method = "spearman", workers = 4)
    qSig_output <- result(qSig_output)
brendangongol commented 1 year ago

Thank you for the inquiry and for sending me your sample code. Since I don't have access to the contents of several of the objects in your code, I commented out several sections and ran the core signatureSearch functions on a test signature.

devtools::install_github("girke-lab/signatureSearch")

db_path <- system.file("extdata", "sample_db.h5", package = "signatureSearch") library(SummarizedExperiment); library(HDF5Array) library(signatureSearch); library(ExperimentHub) sample_db <- SummarizedExperiment(HDF5Array(db_path, name="assay")) rownames(sample_db) <- HDF5Array(db_path, name="rownames") colnames(sample_db) <- HDF5Array(db_path, name="colnames") query_mat <- as.matrix(assay(sample_db[,"vorinostatSKBtrt_cp"])) query <- as.numeric(query_mat); names(query) <- rownames(query_mat) upset <- head(names(query[order(-query)]), 150) head(upset) downset <- tail(names(query[order(-query)]), 150) head(downset)

eh <- ExperimentHub() lincs <- eh[["EH7297"]] %# if(method == "LINCS"){ % # # map to ENTREZ identifiers % # upset = mapIds(org.Hs.eg.db, keys = cluster_upset$genes, column = "ENTREZID", keytype = "SYMBOL") % # downset = mapIds(org.Hs.eg.db, keys = cluster_downset$genes, column = "ENTREZID", keytype = "SYMBOL") % # LINCS-based similarity metric qSig_output <- qSig(query = list(upset = upset, downset = downset), gess_method = "LINCS", refdb = lincs) qSig_output <- gess_lincs(qSig = qSig_output, sortby = "NCS", tau = T, workers = 4) qSig_output <- result(qSig_output) % # filter drugs % # qSig_output <- qSig_output %>% % # filter(trend == trend_val & WTCS_FDR < wtcs_fdr_cutoff) % # drugs <- unique(qSig_output$pert) % # } else if(method == "Cor"){ % # # correlation-based similarity % # query_mat <- cluster_upset %>% % # plyr::rbind.fill(cluster_downset) %>% % # mutate(id = mapIds(org.Hs.eg.db, keys = geneSymbol, column = "ENTREZID", keytype = "SYMBOL")) %>% % # arrange(id) %>% % # filter(!is.na(id)) %>% % # column_to_rownames('id') %>% % # dplyr::select(score) %>% as.matrix() qSig_output <- qSig(query = query_mat, gess_method = "Cor", refdb = lincs) qSig_output <- gess_cor(qSig = qSig_output, method = "spearman", workers = 4) qSig_output <- result(qSig_output) % # }

This code executes on my computer.

Can you install the signatureSearch package from github which contains the most recent updates and let me know if the problem persists? devtools::install_github("girke-lab/signatureSearch")

Regards, Brendan

aadamk commented 1 year ago

Hello Brendan. Thank you for your reply. I believe this issue may have arisen due to the environment that I had loaded at runtime. I terminated my R session and re-ran with the minimally required set of packages loaded and the code executes successfully. Closing.