Skip to content

Commit

Permalink
getResult bugfix: do not fail constructing of MAE if samples do not m…
Browse files Browse the repository at this point in the history
…atch between experiments
  • Loading branch information
TuomasBorman committed Mar 4, 2024
1 parent d861f82 commit b9fe283
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MGnifyR
Type: Package
Version: 0.99.22
Version: 0.99.23
Authors@R:
c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"),
email = "[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version: 0.99.23
Date: 2024-03-04
+ getReturn fix: failed constructing MAE if samples in experiments did not match

Version: 0.99.20
Date: 2024-02-26
+ searchAnalysis returns now a named vector where names are accession IDs that was fed as input
Expand Down
27 changes: 19 additions & 8 deletions R/getResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,12 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# Get colData from microbial profiling data TreeSE,
# if it is included
args <- list()
# If taxa data is included
# If taxa data is included get all the data. Otherwise, get only
# functional annotations.
if( !is.null(result) ){
col_data <- colData(result)
# Create a MAE
result <- list(microbiota = result)
exp_list <- append(result, func_res)
args$colData <- col_data
exp_list <- c(result, func_res)
} else {
exp_list <- func_res
col_data <- NULL
Expand All @@ -244,8 +243,17 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# If there are more than 1 experiments, create MAE
if( length(exp_list) > 1 ){
exp_list <- ExperimentList(exp_list)
args$experiments <- exp_list
result <- do.call(MultiAssayExperiment, args)
result <- MultiAssayExperiment(exp_list)
# If sample metadata is not empty
if( !is.null(col_data) ){
# Ensure that colData has all samples present in dataset
all_samples <- unique(unlist(colnames(result)))
col_data <- col_data[match(
all_samples, rownames(col_data)), ]
rownames(col_data) <- all_samples
# And then add to mae
colData(result) <- col_data
}
} else{
# If there are only 1 experiment, give it as it is
result <- exp_list[[1]]
Expand All @@ -254,7 +262,7 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# If user wants output as a phyloseq, give a list of one
# phyloseq object and functional data
result <- list(microbiota = result)
result <- append(result, func_res)
result <- c(result, func_res)
# If there are only one experiment, take it out from the list
if( length(result) == 1 ){
result <- result[[1]]
Expand Down Expand Up @@ -311,8 +319,11 @@ setMethod("getResult", signature = c(x = "MgnifyClient"), function(
# Get sample metadata
if( !is.null(tse_microbiota) ){
col_data <- colData(tse_microbiota)
# Order coldata
# Order coldata.
col_data <- col_data[match(colnames(assay), rownames(col_data)), ]
# Add colnames to ensure that all rows have name (if some samples
# were missing from the col_data)
rownames(col_data) <- colnames(assay)
args$colData <- col_data
}
# Create TreeSE
Expand Down

0 comments on commit b9fe283

Please sign in to comment.