From 8e136ce3cb46e31612efeee59342942912804dfa Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Wed, 1 May 2024 14:06:51 +0100 Subject: [PATCH] Fix the PCA (#63) * Fix the PCA * fix up final assay --- R/pca.R | 4 ++-- exec/exploratory_plots.R | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/R/pca.R b/R/pca.R index 9538732..aff373f 100644 --- a/R/pca.R +++ b/R/pca.R @@ -279,9 +279,9 @@ runPCA <- function(matrix, do_log = TRUE) { compilePCAData <- function(matrix, ntop = NULL) { if (is.null(ntop)){ - select <- selectVariableGenes(matrix = matrix, ntop = ntop) - }else{ select <- 1:nrow(matrix) + }else{ + select <- selectVariableGenes(matrix = matrix, ntop = ntop) } # perform a PCA on the data in assay(x) for the selected genes diff --git a/exec/exploratory_plots.R b/exec/exploratory_plots.R index 42e6332..efd8e6d 100755 --- a/exec/exploratory_plots.R +++ b/exec/exploratory_plots.R @@ -164,6 +164,7 @@ assay_files <- prettify_names = FALSE ) + # Valid samples are those with values in the specified sample metadata field valid_samples <- Filter(function(x) !is.na(x) && x != '' && !is.null(x), sample_metadata[[opt$contrast_variable]]) @@ -185,7 +186,7 @@ assay_data <- lapply(assay_files, function(x) { # Check an indicated final assay is among what we have if (is.null(opt$final_assay)){ - final_assay <- length(assay_data) + final_assay <- names(assay_data)[length(assay_data)] }else{ final_assay <- opt$final_assay if (!final_assay %in% names(assay_data)) { @@ -272,7 +273,7 @@ dev.off() ################################################ print("Writing PCA plots...") -pca_data <- compilePCAData(assay_data[[final_assay]]) +pca_data <- compilePCAData(assay_data[[final_assay]], ntop = opt$n_genes) plotdata <- pca_data$coords plotdata$colorby <- factor(sample_metadata[[opt$contrast_variable]], levels = unique(sample_metadata[[opt$contrast_variable]]))