From b9fe28358c4bfc85221f42ec54d5cb5f24e2b005 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Mon, 4 Mar 2024 18:40:56 +0200 Subject: [PATCH] getResult bugfix: do not fail constructing of MAE if samples do not match between experiments --- DESCRIPTION | 2 +- NEWS | 4 ++++ R/getResult.R | 27 +++++++++++++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f9e1b0e..8751bbd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "tuomas.v.borman@utu.fi", diff --git a/NEWS b/NEWS index 444e623..82ef026 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/R/getResult.R b/R/getResult.R index 2dc2b53..1fa557c 100644 --- a/R/getResult.R +++ b/R/getResult.R @@ -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 @@ -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]] @@ -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]] @@ -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