-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca20bc4
commit cb7eda8
Showing
8 changed files
with
332 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
library(tidyverse) | ||
library(SingleCellExperiment) | ||
library(scater) | ||
library(annotables) | ||
library(patchwork) | ||
library(Matrix) | ||
set.seed(1) | ||
|
||
sces <- lapply(snakemake@input$mat, readRDS) | ||
sce <- do.call('cbind', sces) | ||
|
||
sce$CellType <- str_split_fixed(colnames(sce), "_", 2)[,1] | ||
|
||
## More QC | ||
grch38 <- select(grch38, symbol, chr) |> | ||
filter(!grepl("GL|KI|CHR_", chr)) |> | ||
filter(symbol %in% rownames(sce)) |> | ||
distinct() |> | ||
group_by(symbol) |> | ||
slice_head(n = 1) | ||
|
||
gene_metadata <- tibble(symbol = rownames(sce)) |> | ||
left_join(grch38) | ||
|
||
if(!all(gene_metadata$symbol == rownames(sce))){ | ||
stop("Error: gene order is not the same") | ||
} | ||
|
||
rowData(sce)$chr <- gene_metadata$chr | ||
|
||
sce <- logNormCounts(sce) | ||
|
||
head(rownames(sce)) | ||
mt_genes <- which(rowData(sce)$chr == "MT") | ||
ribo_genes <- grepl("^RP[LS]", rownames(sce)) | ||
feature_ctrls <- list(mito = rownames(sce)[mt_genes], | ||
ribo = rownames(sce)[ribo_genes]) | ||
lapply(feature_ctrls, head) | ||
|
||
sce <- addPerCellQC(sce, subsets = feature_ctrls) | ||
|
||
pdf(snakemake@output$detected) | ||
plotColData(sce, y = "subsets_mito_percent") | ||
dev.off() | ||
|
||
|
||
# run PCA and UMAP | ||
sce <- runPCA(sce, n_dimred = 20) | ||
sce <- runUMAP(sce, n_dimred = 20, ncomponents = 2) | ||
|
||
dim_reductions <- (plotReducedDim(sce, dimred = 'UMAP', colour_by = "detected") | | ||
plotReducedDim(sce, dimred = 'UMAP', colour_by = 'CellType')) / | ||
(plotReducedDim(sce, dimred = 'PCA', colour_by = 'detected') | | ||
plotReducedDim(sce, dimred = 'PCA', colour_by = 'CellType')) | ||
|
||
png(snakemake@output$dim_red, width = 1500, height = 1500, res = 150) | ||
dim_reductions | ||
dev.off() | ||
|
||
saveRDS(sce, snakemake@output$sce) |
76 changes: 0 additions & 76 deletions
76
pipeline/process-data/determine-dataset-dimensionality.Rmd
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
library(DropletUtils) | ||
library(Matrix) | ||
library(tidyverse) | ||
library(scater) | ||
library(annotables) | ||
library(SingleCellExperiment) | ||
|
||
matrix <- readMM(snakemake@input$mat) | ||
barcodes <- read_tsv(snakemake@input$barcodes, col_names = FALSE) | ||
features <- read_tsv(snakemake@input$features, col_names = FALSE) | ||
|
||
rownames(matrix) <- features$X1 | ||
colnames(matrix) <- barcodes$X1 | ||
|
||
grch38_filtered <- grch38 |> | ||
filter(!grepl("GL|KI|CHR_", chr) & biotype == "protein_coding") |> | ||
filter(!grepl("^RP[L|S]|^MALAT1|^HSP|^FOS|^JUN", symbol)) | ||
gene_map <- select(grch38_filtered, ensgene, symbol) |> deframe() | ||
|
||
# Remove any genes that don't have a hugo name | ||
matrix <- matrix[rownames(matrix) %in% names(gene_map), ] | ||
|
||
# change rownames to hugo | ||
rownames(matrix) <- gene_map[rownames(matrix)] | ||
|
||
sel_cells <- grepl(snakemake@wildcards$cell_line, colnames(matrix)) | ||
subset_mat <- matrix[, sel_cells] | ||
|
||
subset_mat <- as.matrix(subset_mat) |> | ||
as.data.frame() |> | ||
rownames_to_column("gene") |> | ||
pivot_longer(-gene, names_to = "cell_id", values_to = "counts") | ||
|
||
subset_mat <- subset_mat |> | ||
group_by(gene, cell_id) %>% | ||
summarise(counts = sum(counts)) |> | ||
ungroup() | ||
|
||
subset_mat <- pivot_wider(subset_mat, values_from = "counts", names_from = "cell_id") |> | ||
as.data.frame() |> | ||
column_to_rownames("gene") |> | ||
t() | ||
|
||
subset_mat <- as(subset_mat, "sparseMatrix") | ||
|
||
sce <- SingleCellExperiment(assays = list(counts = t(subset_mat))) | ||
|
||
saveRDS(sce, snakemake@output$sce) | ||
|
Oops, something went wrong.