@@ -543,7 +543,7 @@ if (organism %in% c("athaliana")) {
543543 probe_ids <- unique(norm_data$genes$ProbeName)
544544
545545 # DEBUG:START
546- if ( is.integer(params$DEBUG_limit_biomart_query) ) {
546+ if ( is.integer(params$DEBUG_limit_biomart_query) && params$DEBUG_limit_biomart_query > 0 && params$DEBUG_limit_biomart_query < length(probe_ids) ) {
547547 warning(paste("DEBUG MODE: Limiting query to", params$DEBUG_limit_biomart_query, "entries"))
548548 message(paste("DEBUG MODE: Limiting query to", params$DEBUG_limit_biomart_query, "entries"))
549549 probe_ids <- probe_ids[1:params$DEBUG_limit_biomart_query]
@@ -553,7 +553,7 @@ if (organism %in% c("athaliana")) {
553553 # Create probe map
554554 # Run Biomart Queries in chunks to prevent request timeouts
555555 # Note: If timeout is occurring (possibly due to larger load on biomart), reduce chunk size
556- CHUNK_SIZE= 1500
556+ CHUNK_SIZE= 500
557557 probe_id_chunks <- split(probe_ids, ceiling(seq_along(probe_ids) / CHUNK_SIZE))
558558 df_mapping <- data.frame()
559559 for (i in seq_along(probe_id_chunks)) {
@@ -592,27 +592,37 @@ if (organism %in% c("athaliana")) {
592592 warning("Need to provide both local_annotation_dir and annotation_config_path to use custom annotation.")
593593 }
594594 if (annot_type == 'agilent') {
595- message(glue::glue("Using Agilent Ensembl transcript annotation to retrieve Ensembl Gene IDs from BioMart"))
596595 print(ensembl)
597596
598597 # read in AllAnnotations file and strip version off of Ensembl Transcript ID
599598 agilent_table <- read.delim(
600599 file.path(local_annotation_dir, annot_config$annot_filename[[1]]),
601600 header = TRUE, na.strings = c('NA', '')
602- )[c('ProbeID', 'EnsemblID')] %>%
601+ )[c('ProbeID', 'EnsemblID')] %>% dplyr::filter(!is.na(EnsemblID)) %>%
603602 dplyr::mutate(EnsemblID = stringr::str_split_i(EnsemblID, "\\.", 1))
604603
605604 stopifnot(nrow(agilent_table) == length(unique(agilent_table$ProbeID)))
606605
606+ # DEBUG:START
607+ if ( is.integer(params$DEBUG_limit_biomart_query) && params$DEBUG_limit_biomart_query > 0 && params$DEBUG_limit_biomart_query < nrow(agilent_table) ) {
608+ warning(paste("DEBUG MODE: Limiting query to", params$DEBUG_limit_biomart_query, "entries"))
609+ message(paste("DEBUG MODE: Limiting query to", params$DEBUG_limit_biomart_query, "entries"))
610+ transcript_ids <- agilent_table$EnsemblID[1:params$DEBUG_limit_biomart_query]
611+ } else {
612+ transcript_ids <- agilent_table$EnsemblID
613+ }
614+ # DEBUG:END
615+
607616 # Map Ensembl Transcript IDs to Ensembl Gene IDs using BioMart
608617 # Run BioMart Queries in chunks to prevent request timeouts
609618 # Note: If timeout is occurring (possibly due to larger load on BioMart), reduce chunk size
610- CHUNK_SIZE= 1500
611- transcript_id_chunks <- split(agilent_table$EnsemblID , ceiling(seq_along(agilent_table$EnsemblID ) / CHUNK_SIZE))
619+ CHUNK_SIZE= 500
620+ transcript_id_chunks <- split(transcript_ids , ceiling(seq_along(transcript_ids ) / CHUNK_SIZE))
612621 id_map <- data.frame()
613622 for (i in seq_along(transcript_id_chunks)) {
614623 transcript_id_chunk <- transcript_id_chunks[[i]]
615624 print(glue::glue("Running BioMart query chunk {i} of {length(transcript_id_chunks)}. Total transcript IDS in query ({length(transcript_id_chunk)})"))
625+ message(glue::glue("Running BioMart query chunk {i} of {length(transcript_id_chunks)}. Total transcript IDS in query ({length(transcript_id_chunk)})"))
616626 chunk_results <- biomaRt::getBM(
617627 attributes = c(
618628 "ensembl_transcript_id",
@@ -625,7 +635,6 @@ if (organism %in% c("athaliana")) {
625635 if (nrow(chunk_results) > 0) {
626636 id_map <- id_map %>% dplyr::bind_rows(chunk_results)
627637 }
628-
629638 Sys.sleep(10) # Slight break between requests to prevent back-to-back requests
630639 }
631640
0 commit comments