This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
forked from adamjamesreid/Plasmodium-single-cell-RNA-seq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PbM_analysis.R
76 lines (57 loc) · 2.15 KB
/
PbM_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
library(scater, quietly = TRUE)
options(stringsAsFactors = FALSE)
setwd("~/Work/Writing/Papers/scPlasmodium/eLife/Supplementary Data/")
# Read in data
molecules <- read.table("PbM_counts.txt", sep = "\t", header = TRUE, row.names=1)
anno <- read.table("PbM_meta.txt", sep = "\t", header=TRUE)
genes <- read.table("berg.desc", header=FALSE, row.names=1, quote = "", sep="\t")
# Set up objects
pheno_data <- new("AnnotatedDataFrame", anno)
rownames(pheno_data) <- pheno_data$sample_id
PbM <- scater::newSCESet(
countData = molecules,
phenoData = pheno_data
)
# Filter genes with no counts
keep_feature <- rowSums(counts(PbM) > 0) > 0
PbM <- PbM[keep_feature, ]
# calculateQCMetrics
PbM <- scater::calculateQCMetrics(PbM)
# Filter cells with low counts
filter_by_total_counts <- (PbM$total_counts > 25000)
table(filter_by_total_counts)
# Filter cells with low numbers of features detected
filter_by_expr_features <- (PbM$total_features > 1000)
table(filter_by_expr_features)
# filter out control samples
PbM$is_control <- anno$is_control
filter_by_control <- (PbM$is_control == TRUE)
table(filter_by_control)
# Filter data
PbM$use <- (
# sufficient features (genes)
filter_by_expr_features &
# sufficient molecules counted
filter_by_total_counts &
# controls shouldn't be used in downstream analysis
!PbM$is_control
)
table(PbM$use)
# Gene filtering
# e.g. greater than 10 reads in at least 5 cells
filter_genes <- apply(counts(PbM[ , pData(PbM)$use]), 1, function(x) length(x[x >= 10]) >= 5)
table(filter_genes)
fData(PbM)$use <- filter_genes
dim(PbM[fData(PbM)$use, pData(PbM)$use])
# Create new object with filtered dataset
PbM.qc <- PbM[fData(PbM)$use, pData(PbM)$use]
# Perform SCRAN normalisation
qclust <- scran::quickCluster(PbM.qc, min.size = 30)
PbM.qc <- scran::computeSumFactors(PbM.qc, sizes = 20, clusters = qclust, positive=TRUE)
PbM.qc <- scater::normalize(PbM.qc)
scater::plotPCA(PbM.qc,
colour_by = "consensus",
size_by = "total_features",
exprs_values = "exprs")
# PLot expression of p25 female marker on PCA
plotPCA(PbM.qc, colour_by="PBANKA_0515000", exprs_values = "exprs", ncomponents=2)