-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-processing.R
167 lines (117 loc) · 6.82 KB
/
data-processing.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
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
library(Seurat)
setwd("~/Dropbox/ddesktop/lab-gehlenborg/")
# function to process 10x data --------------------------------------------
read_10x_data <- function(directory, data_name, min_cells, min_features){
#read in 10x count data
data_10x <- Read10X(data.dir=directory)
#create SeuratObject
data_seurat <- CreateSeuratObject(counts=data_10x, project=data_name, min.cells=min_cells, min.features=min_features)
#quality control: detect amount of mitochondrial DNA
data_seurat[["percent.mt"]] <- PercentageFeatureSet(data_seurat, pattern = "^MT-")
#print data dimensions
print("dataset dimensions (genes x cells):")
print(dim(data_seurat))
return(data_seurat)
}
# function to analyze data ------------------------------------------------
#data in SeuratObject form
analyze_data <- function(data){
#process data
data <- NormalizeData(data, normalization.method="LogNormalize", scale.factor=10000)
data <- FindVariableFeatures(data, selection.method="vst", nfeatures=2000)
all.genes <- rownames(data)
#data analysis
#PCA
data <- ScaleData(data, features=all.genes)
data <- RunPCA(data, features=VariableFeatures(object=data))
data <- FindNeighbors(data, dims=1:10)
data <- FindClusters(data, resolution=0.5)
#UMAP
data <- RunUMAP(data, dims=1:20, min.dist=0.75)
#t-SNE
data <- RunTSNE(data, dims=1:10, nthreads=4, max_iter=1000, k.seed=12345)
return(data)
}
# pbmc --------------------------------------------------------------------
#full dataset
data_pbmc_full <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/seurat/filtered_gene_bc_matrices/hg19",
data_name="pbmc",
min_cells=0,
min_features=0) #32738 x 2700
saveRDS(data_pbmc_full, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_pbmc_full.rds")
#filtered dataset
data_pbmc_filtered <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/seurat/filtered_gene_bc_matrices/hg19",
data_name="pbmc",
min_cells=100,
min_features=500) #4662 x 2482
data_pbmc_filtered <- subset(data_pbmc_filtered, subset=percent.mt<5)
dim(data_pbmc_filtered) #4662 x 2439
#analyze data for vitessce visualization
data_pbmc_results <- analyze_data(data_pbmc_filtered)
saveRDS(data_pbmc_results, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_pbmc_results.rds")
# t-cells CD8 -------------------------------------------------------------
#full dataset
data_tcellcd8_full <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/datasets/tcellcd8/filtered_matrices_mex/hg19",
data_name="tcellcd8",
min_cells=0,
min_features=0) #32738 x 10209
saveRDS(data_tcellcd8_full, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_tcellcd8_full.rds")
#filtered dataset
data_tcellcd8_filtered <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/datasets/tcellcd8/filtered_matrices_mex/hg19",
data_name="tcellcd8",
min_cells=100,
min_features=500) #6171 x 7856
data_tcellcd8_filtered <- subset(data_tcellcd8_filtered, subset=percent.mt<5)
dim(data_tcellcd8_filtered) #6171 x 7850
#analyze data for vitessce visualization
data_tcellcd8_results <- analyze_data(data_tcellcd8_filtered)
saveRDS(data_tcellcd8_results, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_tcellcd8_results.rds")
# t-cells CD4 -------------------------------------------------------------
#full dataset
data_tcellcd4_full <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/datasets/tcellcd4/filtered_matrices_mex/hg19",
data_name="tcellcd4",
min_cells=0,
min_features=0) #32738 x 11213
saveRDS(data_tcellcd4_full, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_tcellcd4_full.rds")
#filtered dataset
data_tcellcd4_filtered <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/datasets/tcellcd4/filtered_matrices_mex/hg19",
data_name="tcellcd4",
min_cells=100,
min_features=500) #5827 x 7279
data_tcellcd4_filtered <- subset(data_tcellcd4_filtered, subset=percent.mt<5)
dim(data_tcellcd4_filtered) #5827 x 7276
#analyze data for vitessce visualization
data_tcellcd4_results <- analyze_data(data_tcellcd4_filtered)
saveRDS(data_tcellcd4_results, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_tcellcd4_results.rds")
# lung -------------------------------------------------------------
#full dataset
load("~/Dropbox/ddesktop/lab-gehlenborg/datasets/lung/droplet_normal_lung_blood_seurat_ntiss10x.P1.anno.20191002.RC4.Robj")
data_lung_full <- UpdateSeuratObject(ntiss10x.P1.anno) #update "old seurat object" #26485 x 9744
saveRDS(data_lung_full, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_lung_full.rds")
#filtered dataset
data_lung_filtered <- CreateSeuratObject(counts=data_lung_full@assays$RNA@counts,
project="lung", min.cells=100, min.features=500) #12514 x 9744
#quality control: detect amount of mitochondrial DNA
data_lung_filtered[["percent.mt"]] <- PercentageFeatureSet(data_lung_filtered, pattern = "^MT-")
data_lung_filtered <- subset(data_lung_filtered, subset=percent.mt<5)
dim(data_lung_filtered) #12514 x 9744
#analyze data for vitessce visualization
data_lung_results <- analyze_data(data_lung_filtered)
saveRDS(data_lung_results, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_lung_results.rds")
# nsclc -------------------------------------------------------------
#full dataset
data_nsclc_full <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/datasets/nsclc/filtered_gene_bc_matrices/GRCh38",
data_name="nsclc",
min_cells=0,
min_features=0) #33694 x 7802
saveRDS(data_nsclc_full, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_nsclc_full.rds")
#filtered dataset
data_nsclc_filtered <- read_10x_data(directory="~/Dropbox/ddesktop/lab-gehlenborg/datasets/nsclc/filtered_gene_bc_matrices/GRCh38",
data_name="nsclc",
min_cells=100,
min_features=500) #12720 x 6782
data_nsclc_filtered <- subset(data_nsclc_filtered, subset=percent.mt<5)
dim(data_nsclc_filtered) #12720 x 5034
#analyze data for vitessce visualization
data_nsclc_results <- analyze_data(data_nsclc_filtered)
saveRDS(data_nsclc_results, file="~/Dropbox/ddesktop/lab-gehlenborg/data/data_nsclc_results.rds")