Skip to content

Commit

Permalink
Add genomes
Browse files Browse the repository at this point in the history
  • Loading branch information
TuomasBorman committed Feb 5, 2024
1 parent 58b71f4 commit 91082bb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 22 deletions.
9 changes: 5 additions & 4 deletions R/doQuery.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' Search MGnify database for studies, samples, runs, analyses, biomes, and
#' assemblies.
#' Search MGnify database for studies, samples, runs, analyses, biomes,
#' assemblies, and genomes.
#'
#' @details
#' \code{doQuery} is a flexible query function, harnessing the "full"
#' power of the JSONAPI MGnify search filters. Search results may be filtered
#' by metadata value, associated study/sample/analyese etc. Details of the
#' by metadata value, associated study/sample/analyse etc. Details of the
#' capabilities may be found
#' \href{https://emg-docs.readthedocs.io/en/latest/api.html#customising-queries}{here}.
#' Currently, the following filters are available (based on examination of the
Expand Down Expand Up @@ -103,7 +103,8 @@ NULL
#' @export
setMethod("doQuery", signature = c(x = "MgnifyClient"), function(
x, type = c(
"studies", "samples", "runs", "analyses", "biomes", "assemblies"),
"studies", "samples", "runs", "analyses", "biomes", "assemblies",
"genomes"),
accession = NULL, as.df = TRUE, max.hits = 200, ...){
############################### INPUT CHECK ################################
if( !(.is_non_empty_string(type)) ){
Expand Down
11 changes: 7 additions & 4 deletions R/getMetadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ setMethod("getMetadata", signature = c(x = "MgnifyClient"), function(
max.hits = max.hits, ...)
# If metadata was not found, return the NULL value
if(is.null(dat)){
warning("Failed to find study metadata for ", accession, call. = FALSE)
warning(
"\nFailed to find study metadata for ", accession, call. = FALSE)
return(dat)
}

Expand All @@ -116,15 +117,17 @@ setMethod("getMetadata", signature = c(x = "MgnifyClient"), function(
sample_df <- .mgnify_attr_list_to_df_row(
sample_met[[1]], metadata_key = "sample-metadata")
} else{
warning("Failed to find sample metadata for ", accession, call. = FALSE)
warning(
"\nFailed to find sample metadata for ", accession, call. = FALSE)
sample_df <- data.frame(accession=NA)
}
# It turns out that a sample might not be part of a study - if it's been
# harvested...
if(!is.null(study_met)){
study_df <- .mgnify_attr_list_to_df_row(study_met[[1]])
} else{
warning("Failed to find study metadata for ", accession, call. = FALSE)
warning(
"\nFailed to find study metadata for ", accession, call. = FALSE)
study_df <- data.frame(accession=NA)
}
# Add colnames to sample, study and analysis tables
Expand All @@ -150,7 +153,7 @@ setMethod("getMetadata", signature = c(x = "MgnifyClient"), function(
if( !is.null(sample_met[[1]]$relationships$biome$data$id) ){
full_df$biome_string <- sample_met[[1]]$relationships$biome$data$id
} else {
warning("Failed to find biome entry for ", accession, call = FALSE)
warning("\nFailed to find biome entry for ", accession, call = FALSE)
}
return(full_df)
}
21 changes: 11 additions & 10 deletions R/getResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
}
} else{
warning(
"No taxonomy data was found for the dataset.",
"\nNo taxonomy data was found for the dataset.",
call. = FALSE)
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
}
}
} else{
warning("No functional data found for the dataset.", call. = FALSE)
warning("\nNo functional data found for the dataset.", call. = FALSE)
}
}
return(result)
Expand Down Expand Up @@ -421,7 +421,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# Check if any biom files was found
if( is.null(available_biom_files) || length(available_biom_files) == 0 ){
warning(
"No BIOM data found for accession '", accession, "'.",
"\nNo BIOM data found for accession '", accession, "'.",
call. = FALSE)
return(NULL)
}
Expand All @@ -432,7 +432,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
if( sum(biom_position) == 0 ){
if( show.warnings ){
warning(
"Unable to locate requested taxonomy type ", taxa.su, ". ",
"\nUnable to locate requested taxonomy type ", taxa.su, ". ",
"This is likely due to the current analysis having been ",
"performed on an older version of the MGnify pipeline. ",
"The available BIOM file will be used instead.",
Expand Down Expand Up @@ -470,7 +470,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# If the file was not successfully downloaded
if( res$status_code != 200 ){
warning(
biom_url, ": ", content(res, ...)$errors[[1]]$detail,
"\n", biom_url, ": ", content(res, ...)$errors[[1]]$detail,
" A biom listed in 'accession' is missing from the ",
"output.", call. = FALSE)
# Remove the downloaded file, it includes only info on errors
Expand Down Expand Up @@ -528,7 +528,8 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# If the file was not successfully downloaded
if( res$status_code != 200 ){
warning(
tree_url, ": ", content(res, ...)$errors[[1]]$detail,
"\n", tree_url, ": ",
content(res, ...)$errors[[1]]$detail,
" A phylogenetic tree listed in 'accession' is ",
"missing from the output.", call. = FALSE)
}
Expand Down Expand Up @@ -802,7 +803,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# If the file was not successfully downloaded
if( res$status_code != 200 ){
warning(
data_url, ": ", content(res, ...)$errors[[1]]$detail,
"\n", data_url, ": ", content(res, ...)$errors[[1]]$detail,
" Could not load the file from database. The data ",
"from the file is not included in the output.",
call. = FALSE)
Expand Down Expand Up @@ -833,7 +834,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# with missing downloads, we have to check if we
# actually got a valid file:
if( ncol(tmp_df) < 3 ){
warning("Invalid download for ", accession, call. = FALSE)
warning("\nInvalid download for ", accession, call. = FALSE)
return(NULL)
}

Expand All @@ -856,15 +857,15 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
}else if( "run_accession" %in% colnames(metadata_df) ){
accession <- metadata_df$run_accession[[1]]
} else{
warning("Failed to data on ", accession, call. = FALSE)
warning("\nFailed to data on ", accession, call. = FALSE)
return(NULL)
}

# Get the correct sample and subset the data so that it includes only
# the sample and info columns
column_position <- match(accession, colnames(tmp_df))
if( (is.na(column_position) || length(column_position) != 1) ){
warning("Failed to find column ", accession, call. = FALSE)
warning("\nFailed to find column ", accession, call. = FALSE)
return(NULL)
}
# Ensure that the counts are numeric
Expand Down
7 changes: 4 additions & 3 deletions R/searchAnalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ setMethod("searchAnalysis", signature = c(x = "MgnifyClient"), function(
res <- lapply(jsondat, function(x) x$id)
} else {
res <- accurl
warning("Analyses not found for studies ", x, call. = FALSE)
warning("\nAnalyses not found for studies ", x, call. = FALSE)
}
return(res)
}, .progress=show.messages)
Expand Down Expand Up @@ -159,7 +159,7 @@ setMethod("searchAnalysis", signature = c(x = "MgnifyClient"), function(
runurl <- .mgnify_get_x_for_y(
client, x, "samples","runs", use.cache = use.cache, ...)
if(is.null(runurl)){
warning("Analyses not found for samples ", x, call. = FALSE)
warning("\nAnalyses not found for samples ", x, call. = FALSE)
return(runurl)
}
# If found, get data for runs
Expand Down Expand Up @@ -207,7 +207,8 @@ setMethod("searchAnalysis", signature = c(x = "MgnifyClient"), function(
# If we've got to this point, I give up - just return an empty
# list...
warning(
"Failed to find an analysis for sample ", x, call. = FALSE)
"\nFailed to find an analysis for sample ", x,
call. = FALSE)
}
}
# Get analyses IDs
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
}
# Give warning if data is not found.
if( is.null(final_data) ){
warning(warning_msg, call. = FALSE)
warning("\n", warning_msg, call. = FALSE)
}
return(final_data)
}
Expand Down
Binary file modified inst/extdata/vignette_MGnifyR_long
Binary file not shown.

0 comments on commit 91082bb

Please sign in to comment.