From 3f6898eed8a60ba889c44a67a346f247f4073b96 Mon Sep 17 00:00:00 2001 From: leopoldguyot Date: Fri, 19 Jul 2024 09:30:24 +0200 Subject: [PATCH] [FIX] - log transform plot error fix --- DESCRIPTION | 3 ++- NAMESPACE | 1 + R/utils_global.R | 25 +++++++++++++++---------- man/sampleTable.Rd | 2 +- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index af32bfe..fcf1d7c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,8 @@ Imports: viridisLite, stats, SingleCellExperiment, - ggplot2 + ggplot2, + tidyr Depends: shinyBS, R (>= 4.3.0) diff --git a/NAMESPACE b/NAMESPACE index 42976d9..04fcc46 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -114,6 +114,7 @@ importFrom(shinydashboardPlus,boxSidebar) importFrom(shinydashboardPlus,dashboardHeader) importFrom(shinydashboardPlus,dashboardPage) importFrom(stats,as.formula) +importFrom(tidyr,pivot_longer) importFrom(utils,data) importFrom(utils,read.table) importFrom(viridisLite,viridis) diff --git a/R/utils_global.R b/R/utils_global.R index adc523f..7a47953 100644 --- a/R/utils_global.R +++ b/R/utils_global.R @@ -564,25 +564,30 @@ plotlyridges <- function( #' @rdname INTERNAL_summarize_assays_to_df #' @keywords internal #' @importFrom SummarizedExperiment assay colData rowData +#' @importFrom tidyr pivot_longer #' summarize_assays_to_df <- function(qfeatures, sample_column, feature_column = NULL) { + combined_df <- data.frame(PSM = character(), intensity = numeric(), sample = character()) for (assayName in names(qfeatures)) { - assayData <- assay(qfeatures[[assayName]]) + assayData <- as.data.frame(assay(qfeatures[[assayName]])) - PSM <- rownames(assayData) - intensities <- as.vector(assayData) - sampleNames <- rep(colnames(assayData), each = nrow(assayData)) + assayData <- pivot_longer(assayData, everything(), names_to = "sample", values_to = "intensity") + assayData$PSM <- rownames(assayData) + print(head(assayData)) + + matched_indices <- match(assayData$sample, rownames(colData(qfeatures))) + length(matched_indices) + assayData$sample_type <- colData(qfeatures)[matched_indices, sample_column] - assay_df <- data.frame(PSM = PSM, intensity = intensities, sample = sampleNames) - assay_df$sample_type <- colData(qfeatures)[assay_df$sample, sample_column] # Here I subset with a long vector that is compose of multiple time each sample - print(feature_column) + # assay_df$sample_type <- lapply(assay_df$sample, function(x) { + # colData(qfeatures)[x, sample_column] + # }) if (!is.null(feature_column)) { - assay_df$feature_type <- rowData(qfeatures[[assayName]])[assay_df$PSM, feature_column] + assayData$feature_type <- rowData(qfeatures[[assayName]])[assayData$PSM, feature_column] } - combined_df <- rbind(combined_df, assay_df) - print(head(combined_df)) + combined_df <- rbind(combined_df, assayData) } combined_df } diff --git a/man/sampleTable.Rd b/man/sampleTable.Rd index b61fedf..9c905d0 100644 --- a/man/sampleTable.Rd +++ b/man/sampleTable.Rd @@ -29,7 +29,7 @@ input files \code{batch.csv} and \code{annotation.csv} were downloaded from a \href{https://drive.google.com/drive/folders/1VzBfmNxziRYqayx3SP-cOe2gu129Obgx}{Google Drive repository}. The two files were loaded and the columns names were adapted for consistency with \code{mqScpData} table (see \code{?mqScpData}). The two -tables were filtered to contain only sets present in ``mqScpData\verb{. The tables were then merged based on the run ID, hence merging the sample annotation and the batch annotation. Finally, annotation for the blank run was added manually. The data is stored as a }data.frame`. +tables were filtered to contain only sets present in ``mqScpData\verb{. The tables were then merged based on the run ID, hence merging the sample annotation and the batch annotation. Finally, annotation for the blank run was added manually. The data is stored as a }data.frame`. } \seealso{ \code{\link[=readSCP]{readSCP()}} to see how this file is used.