Skip to content

Commit

Permalink
Fix the PCA (#63)
Browse files Browse the repository at this point in the history
* Fix the PCA

* fix up final assay
  • Loading branch information
pinin4fjords authored May 1, 2024
1 parent 42cd674 commit 8e136ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions exec/exploratory_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand All @@ -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)) {
Expand Down Expand Up @@ -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]]))
Expand Down

0 comments on commit 8e136ce

Please sign in to comment.