Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync error handling for gene variance and PCA to main #455

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions bin/post_process_sce.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,38 @@ if (alt_exp %in% altExpNames(processed_sce)) {

# Perform dimension reduction --------------------

# model gene variance using `scran:modelGeneVar()`
gene_variance <- scran::modelGeneVar(processed_sce)

# select the most variable genes
var_genes <- scran::getTopHVGs(gene_variance, n = opt$n_hvg)

# save the most variable genes to the metadata
metadata(processed_sce)$highly_variable_genes <- var_genes

# dimensionality reduction
# highly variable genes are used as input to PCA
processed_sce <- scater::runPCA(processed_sce,
ncomponents = opt$n_pcs,
subset_row = var_genes)
try({
# model gene variance using `scran:modelGeneVar()`
gene_variance <- scran::modelGeneVar(processed_sce)

# select the most variable genes
var_genes <- scran::getTopHVGs(gene_variance, n = opt$n_hvg)

# save the most variable genes to the metadata
metadata(processed_sce)$highly_variable_genes <- var_genes

# dimensionality reduction
# highly variable genes are used as input to PCA
processed_sce <- scater::runPCA(
processed_sce,
ncomponents = opt$n_pcs,
subset_row = var_genes
)
})

# calculate a UMAP matrix using the PCA results
try({
processed_sce <- scater::runUMAP(processed_sce,
dimred = "PCA")
# calculate a UMAP matrix using the PCA results
processed_sce <- scater::runUMAP(
processed_sce,
dimred = "PCA"
)
})

# print a warning if no embeddings present
if(length(reducedDimNames(processed_sce)) == 0){
warning("Reduced dimensions could not be calculated for this object.")
}

# Export --------------

# write out _original_ filtered SCE with additional filtering column
Expand Down