-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
192 lines (141 loc) · 4.55 KB
/
README.Rmd
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# SCOPfunctions
<!-- badges: start -->
<!-- badges: end -->
An R package of functions for single cell -omics analysis. Fits into Seurat workflow.
## Install
### Install using devtools:
```
devtools::install_github("CBMR-Single-Cell-Omics-Platform/SCOPfunctions")
```
### install manually
```
git clone https://www.github.com/CBMR-Single-Cell-Omics-Platform/SCOPfunctions.git
```
then from R:
```
install.packages("./SCOPfunctions", type="source", repos=NULL)
```
## Usage
```
library("SCOPfunctions")
library("Seurat")
```
Download the example data used in the Seurat hashing vignette at https://satijalab.org/seurat/archive/v3.1/hashing_vignette.html
Follow the initial steps of the hashing vignette up till and including the HTO normalization
### Preprocess
Generate an area plot showing how proportions of singlets, doublets and negatives vary with the positive quantile
```
p_quantile = SCOPfunctions::prep_HTO_q_area_plot(
seurat_obj=pbmc.hashtag,
vec_range_quantile=seq(0.8,0.99,0.01),
n_cores_max=Inf
)
```

infer intra-hash doublets
```
# First demultiplex hashtags
q = 0.98
pbmc.hashtag = Seurat::HTOdemux(pbmc.hashtag,assay = "HTO", positive.quantile = q)
# use inter-hash doublets to infer intra-hash doublets
pbmc.hashtag = SCOPfunctions::prep_intrahash_doub(
seurat_obj=pbmc.hashtag,
assay = "RNA",
npcs=20,
randomSeed = 12345
)
```
Do QC on RNA assay
```
pbmc.hashtag = prep_qc_rna(
seurat_obj=pbmc.hashtag,
assay = "RNA"
)
```
### Differential expression
```
# first find clusters (after normalizing the RNA, finding variable features and scaling the data - not shown)
pbmc.hashtag <- FindNeighbors(pbmc.hashtag, reduction = "pca", dims = 1:20)
pbmc.hashtag <- FindClusters(pbmc.hashtag, resolution = 10, verbose = FALSE)
# find DE genes for cluster 0
df_DE = SCOPfunctions::DE_MAST_RE_seurat(
object=pbmc.hashtag,
random_effect.vars="hash.ID",
test.use = "MAST",
ident.1 = "0",
group.by = "seurat_clusters"
)
```
find the activity values for a geneset
```
# as an example, just use the top DE genes for cluster 0
vec_geneWeights <- seq(from = 1, to = 0.1, by = -0.1)
vec_geneWeights <- vec_geneWeights/sum(vec_geneWeights)
names(vec_geneWeights) = head(rownames(df_DE), 10)
pbmc.hashtag$my_geneset_embeddings <- geneset_embed(
mat_datExpr = as.matrix(GetAssayData(pbmc.hashtag, slot="scale.data", assay="SCT")),
vec_geneWeights=vec_geneWeights,
min_feats_present = 5)
```
find the activity values for a list of genesets
```
pbmc.hashtag <- geneset_embed_list_seurat(
seurat_obj = pbmc.hashtag,
list_vec_geneWeights=list_vec_geneWeights,
slot="scale.data",
assay="SCT",
min_feats_present = 5,
n_cores_max = Inf)
```
### Plot results
plot the distribution of cell clusters in different samples
```
plot_barIdentGroup(seurat_obj=pbmc.hashtag,
var_ident="sample_ID",
var_group="cluster",
vec_group_colors=NULL,
f_color=colorRampPalette(brewer.pal(n=11, name="RdYlBu")),
do_plot = F)
```

plot a cluster * feature grid of gene expression violin plots
```
# Here we just use the top variable genes, but normally we would use cluster marker genes
plot_vlnGrid(seurat_obj,
slot="data",
var_group="cluster",
vec_features=head(VariableFeatures(seurat_obj),n=15),
vec_group_colors=NULL,
f_color = colorRampPalette(brewer.pal(n=11, name="RdYlBu")))
```

make a network plot of a set of co-expressed features
```
SCOPfunctions::plot_network(
mat_datExpr=as.matrix(GetAssayData(seurat_obj, slot="data")),
vec_geneImportance=vec_geneImportance,
vec_genes_highlight=c(),
n_max_genes=50,
igraph_algorithm = "drl",
fontface_labels="bold.italic",
color_edge = "grey70",
edge_thickness = 1)
```

## Contribute
Issues and pull requests are welcome!
All contributions should be in line with the [usethis code of conduct](https://usethis.r-lib.org/CODE_OF_CONDUCT.html).
This package uses the methods and R tools set out in [R packages](https://r-pkgs.org/intro.html).
All Pull Requests should follow the [tidyverse style guide](https://style.tidyverse.org/documentation.html).