Skip to content

Commit f28a224

Browse files
committed
continuing cherry pick
1 parent 58ce9a2 commit f28a224

3 files changed

Lines changed: 125 additions & 2 deletions

File tree

config/templates/params.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ min.count,500
44
max.count,60000
55
min.features,200
66
max.features,2000
7-
percent.mt,30
7+
max.percent.mt,30
8+
min.percent.mt,0
89
dims,20
910
res,0.6
1011

scripts/create_multimodal.R

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# !/usr/bin/env Rscript
2+
3+
library(Seurat)
4+
library(dplyr)
5+
library(future)
6+
7+
plan(multicore)
8+
options(future.globals.maxSize = 2000 * 1024^2)
9+
10+
load("./tmp/base_image.RData")
11+
12+
for (i in 1:nrow(samples)) {
13+
x <- Read10X( # pulling data with no filter
14+
data.dir = samples$dir[i]
15+
)
16+
17+
str_section_head("Raw Object") # logging
18+
19+
raw <- x
20+
rna <- raw[[1]]
21+
adt <- raw[[2]]
22+
23+
x <- CreateSeuratObject( # certain data will gen null matrix sans filters
24+
counts = rna,
25+
project = samples$project[i]
26+
# min.cells = params["min.cells", ],
27+
# min.features = params["min.features", ]
28+
)
29+
30+
x[["ADT"]] <- CreateAssayObject(
31+
counts = adt
32+
)
33+
34+
x[["percent.mt"]] <- PercentageFeatureSet(
35+
x,
36+
pattern = "(?i)^MT-"
37+
)
38+
39+
str_section_head("Base Seurat Object") # logging
40+
41+
x <- subset(
42+
x,
43+
nCount_RNA > params["min.count", ] &
44+
nCount_RNA < params["max.count", ] &
45+
percent.mt < params["max.percent.mt", ] &
46+
percent.mt > params["min.percent.mt", ]
47+
)
48+
49+
x <- NormalizeData(x)
50+
x <- NormalizeData( # TODO determine validity of margin param
51+
x,
52+
normalization.method = "CLR",
53+
assay = "ADT"
54+
)
55+
56+
str_section_head("Subset, Normalized") # logging
57+
58+
genes <- rownames(x)
59+
60+
x <- ScaleData(
61+
x,
62+
verbose = F,
63+
features = genes
64+
)
65+
66+
x <- ScaleData(
67+
x,
68+
assay = "ADT"
69+
)
70+
71+
x <- FindVariableFeatures(
72+
x,
73+
selection.method = "vst",
74+
nfeatures = params["max.features", ]
75+
)
76+
77+
x@meta.data$object <- samples$name[i]
78+
x@meta.data$group <- samples$group[i]
79+
80+
assign( # giving names to objects
81+
samples$name[i],
82+
x
83+
)
84+
str_section_head("Scaled") # logging
85+
}
86+
87+
# create and save list of seurat objects
88+
objects <- list()
89+
for (i in samples$name) {
90+
objects <- c(
91+
objects,
92+
get(i) # need get() to call object instead of string
93+
)
94+
}
95+
96+
# run check for single sample
97+
if (length(samples$name) == 1) {
98+
message("Single sample detected - skipping integration")
99+
saveRDS(x, file = "./tmp/tmp_object.RDS")
100+
saveRDS(objects, file = paste0(out_path, "individual.RDS"))
101+
} else {
102+
d <- params["dims", ]
103+
saveRDS(objects, file = paste0(out_path, "individual.RDS"))
104+
105+
x <- FindIntegrationAnchors(
106+
object.list = objects,
107+
dims = 1:d
108+
)
109+
110+
x <- IntegrateData(
111+
anchorset = x,
112+
dims = 1:d
113+
)
114+
115+
DefaultAssay(x) <- "integrated"
116+
saveRDS(x, file = "./tmp/tmp_object.RDS")
117+
118+
str_section_noloop("Integrated") # logging
119+
}
120+
121+
print("End of create_object.R")

scripts/create_object.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ for (i in 1:nrow(samples)) {
2929
x,
3030
nCount_RNA > params["min.count", ] &
3131
nCount_RNA < params["max.count", ] &
32-
percent.mt < params["percent.mt", ]
32+
percent.mt < params["max.percent.mt", ] &
33+
percent.mt > params["min.percent.mt", ]
3334
)
3435
x <- NormalizeData(x)
3536
str_section_head("Subset, Normalized") # logging

0 commit comments

Comments
 (0)