-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectDataForGDITh.R
More file actions
157 lines (115 loc) · 5.93 KB
/
CollectDataForGDITh.R
File metadata and controls
157 lines (115 loc) · 5.93 KB
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
library(Seurat)
seurat.clustering.COTAN.obj.creation <- function(raw.data,
outDir,
resolution = 0.5,dims = 20,
GEO,
sampleCondition,
sequencingMethod){
pbmc <- CreateSeuratObject(counts = raw.data, project = "temp", min.cells = 3, min.features = 100)
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
pbmc <- NormalizeData(pbmc)
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- FindNeighbors(pbmc, dims = 1:dims)
pbmc <- FindClusters(pbmc, resolution = resolution)
dataset <- automaticCOTANObjectCreation(raw = raw.data,
GEO = GEO,
sequencingMethod = sequencingMethod,
sampleCondition = sampleCondition,cores = 5,
outDir = outDir
)
dataset <- clean(dataset)
dataset <- addClusterization(dataset,clName = paste0("FromSeurat",resolution,dims),
clusters = pbmc$seurat_clusters)
return(dataset)
}
datasets <- c("Data/CD14Cleaned/CD14_Monocytes.cotan.RDS",
"Data/Yuzwa_MouseCortex/CorticalCells_GSM2861511_E135.cotan.RDS",
"Data/MouseCortexFromLoom/e15.5_ForebrainDorsal.cotan.RDS",
"Data/PBMC3/filtered/PBMC3.cotan.RDS")
outDir <- "Data/DataForGDITh/"
for (d in "Data/MouseCortexFromLoom/e15.0_ForebrainDorsal.cotan.RDS") {
data <- readRDS(d)
raw <- getRawData(data)
resolution = 1.5
dims = 20
GEO = getMetadataDataset(data)[1,2]
sampleCondition = getMetadataDataset(data)[3,2]
sequencingMethod = getMetadataDataset(data)[2,2]
rm(data)
obj <- seurat.clustering.COTAN.obj.creation(raw.data = raw,outDir = outDir,
resolution = resolution,
dims = dims,
GEO =GEO,
sampleCondition=sampleCondition,
sequencingMethod=sequencingMethod)
saveRDS(obj,paste0(outDir,sampleCondition,".COTAN.RDS"))
}
devtools::load_all("../COTAN/")
options(parallelly.fork.enable = TRUE)
file = "e15.0_ForebrainDorsal.cotan.RDS"
for (file in list.files("Data/DataForGDITh/", pattern = ".cotan.RDS")) {
obj <- readRDS(paste0(outDir,file))
cond <- getMetadataElement(obj, datasetTags()[["cond"]])
outDirCond <- file.path(outDir, cond)
if (!dir.exists(outDirCond)) {
dir.create(outDirCond)
}
clList <- toClustersList(getClusters(obj,clName = "FromSeurat1.520"))
for (cl in names(clList)) {
print(paste0("Cluster ", cl))
checkClusterUniformity(obj,clusterName = cl,cells = clList[[cl]],GDIThreshold = 1.37,
ratioAboveThreshold = 0.005,cores = 5,saveObj = TRUE,
outDir = outDirCond)
}
}
clusterSeurat <- function(raw.matrix, genesToKeep=rownames(raw.matrix), res=1){
raw.matrix <- raw.matrix[genesToKeep,]
pbmc <- CreateSeuratObject(counts = raw.matrix, project = "temp", min.cells = 3, min.features = 200)
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
pbmc <- NormalizeData(pbmc)
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- FindNeighbors(pbmc, dims = 1:20)
pbmc <- FindClusters(pbmc, resolution = res)
return(pbmc)
}
library(ggplot2)
plots.coex <- function(obj){
coex <- getGenesCoex(obj)
coex <- coex[lower.tri(coex, diag = FALSE)]
coex.array <- as.vector(coex)
coex.array <- as.data.frame(coex.array)
ggplot(coex.array, aes(coex.array)) + stat_ecdf(geom = "point")
}
cells <- names(getClusters(CD14_Monocytes.cotan)[getClusters(CD14_Monocytes.cotan)== 1])
cells <- names(getClusters(PBMC3.cotan)[getClusters(PBMC3.cotan)== 0])
obj_cl0_PBMC <- automaticCOTANObjectCreation(raw = getRawData(PBMC3.cotan)[,cells],
GEO = "",sequencingMethod = "" ,sampleCondition = "PBMC_Cl_0",
calcCoex = TRUE,cores = 5,saveObj = FALSE)
GDI_cl0_10 <- calculateGDI(obj_cl0_PBMC,rowsFraction = 0.1)
GDI_cl0_10$From <- "cl0_10_PBMC"
GDI_cl0_5 <- calculateGDI(obj_cl0_PBMC,rowsFraction = 0.05)
GDI_cl0_5$From <- "cl0_5_PBMC"
GDI <- rbind(GDI, GDI_cl0_10,GDI_cl0_5)
obj_cl0 <- automaticCOTANObjectCreation(raw = getRawData(CD14_Monocytes.cotan)[,cells],
GEO = "",sequencingMethod = "" ,sampleCondition = "CD14Cl_0",
calcCoex = TRUE,cores = 5,saveObj = FALSE)
obj_cl1 <- automaticCOTANObjectCreation(raw = getRawData(CD14_Monocytes.cotan)[,cells],
GEO = "",sequencingMethod = "" ,sampleCondition = "CD14Cl_1",
calcCoex = TRUE,cores = 5,saveObj = FALSE)
GDI_cl0_10 <- calculateGDI(obj_cl0,rowsFraction = 0.1)
GDI_cl0_10$From <- "cl0_10_CD14"
GDI_cl1_10 <- calculateGDI(obj_cl1,rowsFraction = 0.1)
GDI_cl1_10$From <- "cl1_10_CD14"
GDI_cl0_5 <- calculateGDI(obj_cl0,rowsFraction = 0.05)
GDI_cl0_5$From <- "cl0_5_CD14"
GDI_cl1_5 <- calculateGDI(obj_cl1,rowsFraction = 0.05)
GDI_cl1_5$From <- "cl1_5_CD14"
GDI <- rbind(GDI_cl0_10,GDI_cl0_5,GDI_cl1_10,GDI_cl1_5)
seurat.obj <- clusterSeurat(getRawData(obj),res = 0.7)
obj <- addClusterization(obj,clName = "FromSeurat_0.7",clusters = seurat.obj$seurat_clusters)