-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrateSCdata.R
1707 lines (1438 loc) · 64.7 KB
/
integrateSCdata.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# rmf 5.31.2023, last modified 12.19.2023
# script assumes the following directories exist:
# plots_analysis/ (for storing plots related to the analysis)
# integratedAnalysis/ (for storing data objects created during analysis)
#################
### FUNCTIONS ###
#################
readRSECfiles <- function(fileList_RSEC){
myFiles <- readLines(con = fileList_RSEC)
samples <- list()
counts_container <- list()
i <- 1
for (f in myFiles){
sample <- str_match(f, ".*/(.*?)_RSEC_MolsPerCell.csv")[[2]]
print(sample)
samples[[i]] <- sample
print("Reading RSEC file...")
counts <- read.table(f, sep = ",", comment.char = "#", header = T, row.names = 1, check.names = FALSE)
print("Transposing RSEC file...")
counts_transposed <- as.data.frame(t(counts))
counts_container[[i]] <- counts_transposed
i <- i+1
}
names(counts_container) <- samples
return(counts_container)
}
readSampleTagFiles <- function(fileList_SMK){
myTags <- readLines(con = fileList_SMK)
samples <- list()
tags_container <- list()
i <- 1
for (f in myTags){
sample <- str_match(f, ".*/(.*?)_Sample_Tag_Calls.csv")[[2]]
print(sample)
samples[[i]] <- sample
tags <- read.table(f, sep = ",", comment.char = "#", header = T, row.names = 1)
tags_container[[i]] <- tags
i <- i+1
}
names(tags_container) <- samples
return(tags_container)
}
plotViolinQC <- function(seurat_container, outbase){
for (name in names(seurat_container)){
x <- seurat_container[[name]]
plist <- VlnPlot(x, features = c("nCount_RNA", "nFeature_RNA", "percent_mito", "percent_ribo"),
combine = FALSE, pt.size = 0)
for(i in 1:length(plist)) {
print(i)
plist[[i]] <- plist[[i]] + NoLegend() +
theme(axis.title = element_blank(), axis.title.x = element_blank(),
axis.text.x=element_blank()) +
theme(plot.subtitle = element_text(size=8))
}
png(file = paste("plots_analysis/violinPlot_",outbase,"_",name,"_fresh.png", sep = ""), bg = "white")
p <- plot_grid(plotlist = plist, ncol = 2) + plot_annotation(title = name)
print(p)
dev.off()
pdf(file = paste("plots_analysis/violinPlot_",outbase,"_",name,"_fresh.pdf", sep = ""))
p <- plot_grid(plotlist = plist, ncol = 3) + plot_annotation(title = name)
print(p)
dev.off()
}
}
############
### MAIN ###
############
library(Seurat)
library(tidyverse)
library(patchwork)
library(cowplot)
library(clustree)
library(dittoSeq)
library(scProportionTest)
library(harmony)
# read input files
fileList_RSEC <- "fileList.RSEC_fresh_test.txt" # text file with name of each RSEC file on a separate line
fileList_SMK <- "fileList.sampleTag_fresh_test.txt" # text file with name of each sampleTag file on a separate line
metadataFile <- "metadata_fresh.txt"
patientMetadataFile <- "metadata_fresh_patientLevel.txt"
RSEC_container <- readRSECfiles(fileList_RSEC) # this takes a long time
names(RSEC_container)
names(RSEC_container) <- gsub("-", "_", names(RSEC_container))
names(RSEC_container)
#saveRDS(RSEC_container, file = "integratedAnalysis/data_RSECdataframes_fresh.RDS")
RSEC_container <- readRDS(file = "integratedAnalysis/data_RSECdataframes_fresh.RDS")
sampleTag_container <- readSampleTagFiles(fileList_SMK)
names(sampleTag_container)
names(sampleTag_container) <- gsub("-", "_", names(sampleTag_container))
names(sampleTag_container)
metadata <- read.table(metadataFile, comment.char = "")
colnames(metadata) <- gsub("#", "", metadata[1,])
metadata <- metadata[2:nrow(metadata),]
metadata$dataset <- gsub("-", "_", metadata$dataset)
patient_metadata <- read.table(patientMetadataFile, comment.char = "")
colnames(patient_metadata) <- patient_metadata[1,]
patient_metadata <- patient_metadata[2:nrow(patient_metadata),]
patient_metadata$Sample_Tag <- paste("SampleTag0", patient_metadata$SMK, "_hs", sep = "")
patient_metadata$Sample_Tag[patient_metadata$Sample_Tag == "SampleTag0Undetermined_hs"] <- "Undetermined"
patient_metadata$Sample_Tag[patient_metadata$Sample_Tag == "SampleTag0Multiplet_hs"] <- "Multiplet"
######################
### pre-processing ###
######################
# split out abseqs from experiments with abseq
abseq_container <- list()
rnaseq_container <- list()
abseq_names <- list()
i <- 1
for (RSEC in RSEC_container){
# if statement explanation: grep for "|", returns a logical vector the same length as the number of row names
# get unique values of the logical vector: if no abseqs, there will be one unique value (FALSE),
# if there are abseqs there will be two unique values (TRUE for abseq, FALSE for gene names)
# check the number of unique values with length()
# if there is more than one value, parse out abseqs
if (length(unique(grepl("|", row.names(RSEC_container[[i]]), fixed = TRUE))) > 1) {
name <- names(RSEC_container)[[i]]
print(name)
abseqs <- RSEC_container[[i]][grep("|", row.names(RSEC_container[[i]]), fixed = TRUE),]
rna <- RSEC_container[[i]][which(grepl("|", row.names(RSEC_container[[i]]), fixed = TRUE) == FALSE),]
j <- length(abseq_container) + 1
print(j)
abseq_container[[j]] <- abseqs
abseq_names[[j]] <- name
} else {
rna <- RSEC_container[[i]]
}
rnaseq_container[[i]] <- rna
i <- i + 1
}
names(rnaseq_container) <- names(RSEC_container)
names(abseq_container) <- abseq_names
rm(RSEC_container)
# create seurat objects with metadata
seurat_container <- list()
i <- 1
for (rna_df in rnaseq_container){
name <- names(rnaseq_container)[[i]]
meta <- metadata[(metadata$dataset == name),] # get metadata for this dataset
meta_expanded <- meta[rep(1,ncol(rna_df)),] # expand df to number of cells for this dataset
row.names(meta_expanded) <- colnames(rna_df) # set metadata row names as cell names from counts data
print("Creating Seurat object...")
obj <- CreateSeuratObject(counts = rna_df, project = name, meta.data = meta_expanded)
# add abseq info if available-- not all samples have abseq info
if (!(is.null(abseq_container[[name]]))) {
print("Adding abseq information...")
obj[["ADT"]] <- CreateAssayObject(counts = abseq_container[[name]])
}
### add sample tags ###
print("Adding sample tag information...")
sample_tag_df <- sampleTag_container[[name]] # there are two cols, they are redundant so take only the first
sample_tag_df$cellnames <- row.names(sample_tag_df)
# get patient-level metadata for just this dataset
patient_meta <- patient_metadata[patient_metadata$sample_group == name,]
# merge patient-level metadata by sample tag
sample_meta <- merge(sample_tag_df, patient_meta, by = "Sample_Tag")
row.names(sample_meta) <- sample_meta$cellnames
print(unique(sample_meta$Sample_Tag))
obj <- AddMetaData(obj, metadata = sample_meta)
# remove cells called Multiplet, and Undetermined if there are other actual SMKs
# if Undetermined is the only one, keep it bc it means SMKs were not added in the experimental workflow
# but the processing was run with the SMK reference file
samples <- unique([email protected]$Sample_Tag)
if (length(samples) != 1){
print(samples)
samples <- samples[!(samples == "Undetermined" | samples == "Multiplet")]
obj <- subset(x = obj, subset = Sample_Tag %in% samples)
} else {
print(samples)
samples <- samples[!(samples == "Multiplet")]
obj <- subset(x = obj, subset = Sample_Tag %in% samples)
}
# add %mitochondrial genes to metadata
obj$percent_mito <- PercentageFeatureSet(obj, pattern = "^MT-")
obj$percent_ribo <- PercentageFeatureSet(obj, pattern = "RP[L|S]")
seurat_container[[i]] <- obj
i <- i + 1
}
names(seurat_container) <- names(rnaseq_container)
#saveRDS(seurat_container, file = "integratedAnalysis/data_listOfSeuratObjects.RDS")
seurat_container <- readRDS("integratedAnalysis/data_listOfSeuratObjects.RDS")
#######################
### quality control ###
#######################
seurat_container <- readRDS("integratedAnalysis/data_listOfSeuratObjects.RDS")
# merge into one seurat object for QC plotting
obj <- merge(seurat_container[[1]], seurat_container[2:length(seurat_container)])
# plot the number of cells per dataset before filtering
bars <- c()
datasets <- c()
i <- 1
for (name in names(seurat_container)){
datasets[[i]] <- name
bars[[i]] <- nrow(seurat_container[[name]]@meta.data)
i <- i + 1
}
df <- data.frame(unlist(datasets), unlist(bars))
colnames(df) <- c("datasets", "bars")
df$datasets <- gsub("-large-input","",df$datasets,fixed=TRUE)
ggplot(df, aes(x=datasets, y=bars)) +
geom_bar(stat = "identity") +
ggtitle("Number of Cells per Dataset") +
geom_text(aes(label=bars), vjust=1.5, color="cyan", size=3.5) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) # rotate axis labels
ggsave(filename = "plots_analysis/barPlotCellCountPerDataset_fresh.pdf")
ggsave(filename = "plots_analysis/barPlotCellCountPerDataset_fresh.png", bg = "white")
# plot number of cells per sample tag for each dataset
for (name in names(seurat_container)) {
bars <- c()
tags <- c()
x <- seurat_container[[name]]
i <- 1
for (tag in unique(x$Sample_Tag)){
y <- subset(x, subset = Sample_Tag == tag)
bars[[i]] <- ncol(y)
tags[[i]] <- tag
i <- i +1
}
df <- data.frame(unlist(tags), unlist(bars))
colnames(df) <- c("tags","bars")
ggplot(df, aes(x=tags, y=bars)) +
geom_bar(stat = "identity") +
ggtitle(paste("Number of Cells per SMK",name,sep=": ")) +
geom_text(aes(label=bars), vjust=1.5, color="cyan", size=3.5) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) # rotate axis labels
ggsave(filename = paste("plots_analysis/barPlotCellCountPerSMK_",name,"_fresh.pdf",sep=""))
ggsave(filename = paste("plots_analysis/barPlotCellCountPerSMK_",name,"_fresh.png",sep=""), bg = "white")
}
# plot number of reads per cell in each dataset
plotViolinQC(seurat_container, "prefilter")
VlnPlot(object = obj, features = "nFeature_RNA", pt.size = 0) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()) +
geom_hline(yintercept = 200) +
geom_text(aes(0.8,200,label = '200', vjust = -0.5)) +
geom_hline(yintercept = 3000) +
geom_text(aes(0.8,3000,label = '3000', vjust = -0.5)) +
geom_hline(yintercept = 4000) +
geom_text(aes(0.8,4000,label = '4000', vjust = -0.5)) +
geom_hline(yintercept = 6000) +
geom_text(aes(0.8,6000,label = '6000', vjust = -0.5))
ggsave("plots_analysis/violinPlot_prefilter_allDatasets_nFeature_fresh.png", height = 5, width = 8, bg = "white")
ggsave("plots_analysis/violinPlot_prefilter_allDatasets_nFeature_fresh.pdf")
VlnPlot(object = obj, features = "percent_mito", pt.size = 0) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()) +
geom_hline(yintercept = 20) +
geom_text(aes(3.4,20,label = '20', vjust = -0.5)) +
geom_hline(yintercept = 15) +
geom_text(aes(3.4,15,label = '15', vjust = -0.5))
ggsave("plots_analysis/violinPlot_prefilter_allDatasets_percentMito_fresh.png", height = 5, width = 8, bg = "white")
ggsave("plots_analysis/violinPlot_prefilter_allDatasets_percentMito_fresh.pdf")
# by digest method-- CD45 pos
obj_pos <- merge(seurat_container[["DE1_CD45pos"]], seurat_container[["DE2_CD45pos"]])
unique(Idents(obj_pos))
Idents(obj_pos) <- "digest_method"
unique(Idents(obj_pos))
# explicitly set order of idents
[email protected] <- factor(x = [email protected], levels = c("Sequential","Simultaneous"))
unique(Idents(obj_pos))
feats = c("nCount_RNA","nFeature_RNA","percent_mito")
titles = c("Number of\nMolecules","Number of\nUnique Genes","Percent\nMitochondrial Genes")
plist <- list()
for (i in seq(1,length(feats))){
p <- VlnPlot(obj_pos, features = feats[[i]],
pt.size = 0, cols = c("Sequential"="coral","Simultaneous"="turquoise")) +
NoLegend() + ggtitle(titles[[i]]) + xlab("") +
theme(axis.text.x = element_blank())
plist[[i]] <- p
}
legend <- get_legend(VlnPlot(obj_pos, features = feats[[i]],
cols = c("Sequential"="coral","Simultaneous"="turquoise")))
blank_plot <- ggplot() + theme_void()
plist[[4]] <- blank_plot
plist[[5]] <- legend
plist[[6]] <- blank_plot
plot_grid(plotlist = plist, nrow = 2, rel_heights = c(6,1))
ggsave("plots_analysis/violin_QC_digestMethod_prefilter_pos.pdf",
units = "in", width = 8, height = 6)
# number of cells per digest method
[email protected] %>% group_by(digest_method) %>% summarise(n())
# by digest method-- CD45 neg
obj_neg <- seurat_container[["DE2_CD45neg"]]
unique(Idents(obj_neg))
Idents(obj_neg) <- "digest_method"
unique(Idents(obj_neg))
# explicitly set order of idents
[email protected] <- factor(x = [email protected], levels = c("Sequential","Simultaneous"))
unique(Idents(obj_neg))
feats = c("nCount_RNA","nFeature_RNA","percent_mito")
titles = c("Number of\nMolecules","Number of\nUnique Genes","Percent\nMitochondrial Genes")
plist <- list()
for (i in seq(1,length(feats))){
p <- VlnPlot(obj_neg, features = feats[[i]],
pt.size = 0, cols = c("Sequential"="coral","Simultaneous"="turquoise")) +
ggtitle(titles[[i]]) + xlab("") + NoLegend() +
theme(axis.text.x = element_blank())
plist[[i]] <- p
}
legend <- get_legend(VlnPlot(obj_neg, features = feats[[i]],
cols = c("Sequential"="coral","Simultaneous"="turquoise")))
blank_plot <- ggplot() + theme_void()
plist[[4]] <- blank_plot
plist[[5]] <- legend
plist[[6]] <- blank_plot
plot_grid(plotlist = plist, nrow = 2, rel_heights = c(6,1))
ggsave("plots_analysis/violin_QC_digestMethod_prefilter_neg.pdf",
units= "in", width = 8, height = 6)
# number of cells per digest method
[email protected] %>% group_by(digest_method) %>% summarise(n())
### quality control: filter cells and reads ###
filtered_seurat <- list()
names(seurat_container) # DOUBLE CHECK YOUR ORDER
filtered_seurat[["DE1_CD45pos"]] <- subset(seurat_container[["DE1_CD45pos"]], subset = nFeature_RNA > 200 & nFeature_RNA < 3000 & percent_mito < 25)
filtered_seurat[["DE2_CD45neg"]] <- subset(seurat_container[["DE2_CD45neg"]], subset = nFeature_RNA > 200 & nFeature_RNA < 6000 & percent_mito < 25)
filtered_seurat[["DE2_CD45pos"]] <- subset(seurat_container[["DE2_CD45pos"]], subset = nFeature_RNA > 200 & nFeature_RNA < 5000 & percent_mito < 25)
names(filtered_seurat) # check names
#saveRDS(filtered_seurat, file = "data_listOfSeuratObjects_filtered.RDS")
### post filtering plotting ###
# plot the number of cells per dataset after filtering
bars <- c()
datasets <- c()
i <- 1
for (name in names(filtered_seurat)){
datasets[[i]] <- name
bars[[i]] <- nrow(filtered_seurat[[name]]@meta.data)
i <- i + 1
}
df <- data.frame(unlist(datasets), unlist(bars))
colnames(df) <- c("datasets", "bars")
df$datasets <- gsub("-large-input","",df$datasets,fixed=TRUE)
ggplot(df, aes(x=datasets, y=bars)) +
geom_bar(stat = "identity") +
ggtitle("Number of Cells per Dataset, Filtered") +
geom_text(aes(label=bars), vjust=1.5, color="cyan", size=3.5) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) # rotate axis labels
ggsave(filename = "plots_analysis/barPlotCellCountPerDataset_fresh_filtered.pdf")
ggsave(filename = "plots_analysis/barPlotCellCountPerDataset_fresh_filtered.png", bg = "white")
# plot number of cells per sample tag for each dataset
for (name in names(filtered_seurat)) {
bars <- c()
tags <- c()
x <- filtered_seurat[[name]]
i <- 1
for (tag in unique(x$Sample_Tag)){
y <- subset(x, subset = Sample_Tag == tag)
bars[[i]] <- ncol(y)
tags[[i]] <- tag
i <- i +1
}
df <- data.frame(unlist(tags), unlist(bars))
colnames(df) <- c("tags","bars")
ggplot(df, aes(x=tags, y=bars)) +
geom_bar(stat = "identity") +
ggtitle(paste("Number of Cells per SMK ", name, ", filtered", sep = "")) +
geom_text(aes(label=bars), vjust=1.5, color="cyan", size=3.5) +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) # rotate axis labels
ggsave(filename = paste("plots_analysis/barPlotCellCountPerSMK_",name,"_fresh_filtered.pdf",sep=""))
ggsave(filename = paste("plots_analysis/barPlotCellCountPerSMK_",name,"_fresh_filtered.png",sep=""), bg = "white")
}
# plot number of reads per cell in each dataset after filtering
obj_filtered <- merge(filtered_seurat[[1]], filtered_seurat[2:length(filtered_seurat)])
plotViolinQC(filtered_seurat, "postfilter")
VlnPlot(object = obj_filtered, features = "nFeature_RNA", pt.size = 0) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
ggsave("plots_analysis/violinPlot_postfilter_allDatasets_nFeature_fresh.png", bg = "white")
ggsave("plots_analysis/violinPlot_postfilter_allDatasets_nFeature_fresh.pdf")
VlnPlot(object = obj_filtered, features = "percent_mito", pt.size = 0) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
ggsave("plots_analysis/violinPlot_postfilter_allDatasets_percentMito_fresh.png", bg = "white")
ggsave("plots_analysis/violinPlot_postfilter_allDatasets_percentMito_fresh.pdf")
##########################################
### CD45 pos: integration and analysis ###
##########################################
filtered_seurat <- readRDS(file = "integratedAnalysis/data_listOfSeuratObjects_filtered.RDS")
# get just CD45 positive datasets
pos <- list()
pos[["DE1_CD45pos"]] <- filtered_seurat[["DE1_CD45pos"]]
pos[["DE2_CD45pos"]] <- filtered_seurat[["DE2_CD45pos"]]
### RNA integration ###
# normalize and find variable features for each seurat object in the list
norm_list <- lapply(X = pos, FUN = function(x) {
x <- NormalizeData(x)
x <- FindVariableFeatures(x, selection.method = "vst", nfeatures = 2000)
})
# standard integration
features <- SelectIntegrationFeatures(object.list = norm_list)
anchors <- FindIntegrationAnchors(object.list = norm_list, anchor.features = features)
pos <- IntegrateData(anchorset = anchors)
#saveRDS(pos, file = "integratedAnalysis/data_pos_integrated.RDS")
pos <- readRDS(file = "integratedAnalysis/data_pos_integrated.RDS")
### standard integrated analysis for CD45 positive ###
DefaultAssay(pos) <- "integrated"
pos <- ScaleData(pos)
pos <- RunPCA(pos)
ElbowPlot(pos, ndims = 20)
pos <- RunUMAP(pos, dims = 1:10, reduction = "pca")
pos <- FindNeighbors(pos, reduction = "pca", dims = 1:10)
res_range <- c(seq(0.1,1.0,0.1), seq(1.2,2.0,0.2))
res_range
pos <- FindClusters(pos, resolution = res_range)
# use clustree to find best resolution
head(pos[[]])
clustree(pos, prefix = "integrated_snn_res.", show_axis = TRUE) +
theme(legend.position="none")
ggsave("plots_analysis/clustree_prebatch_fresh_pos.png", bg = "white", width = 7, height = 12, units = "in")
ggsave("plots_analysis/clustree_prebatch_fresh_pos.pdf", width = 7, height = 12, units = "in")
# set optimal resolution
Idents(pos) <- pos$integrated_snn_res.0.2
#saveRDS(pos, file = "integratedAnalysis/data_pos_analyzed.RDS")
pos <- readRDS(file = "integratedAnalysis/data_pos_analyzed.RDS")
dittoDimPlot(pos, var = Idents(pos), reduction.use = "umap") +
ggtitle("CD45+ Pre-batch correction")
ggsave("plots_analysis/dimPlot_seurat_clusters_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_seurat_clusters_fresh_pos.pdf")
dittoDimPlot(pos, var = Idents(pos), split.by = "dataset") +
ggtitle("CD45+ Pre-batch correction: dataset")
ggsave("plots_analysis/dimPlot_seurat_clusters_splitDataset_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_seurat_clusters_splitDataset_fresh_pos.pdf")
dittoDimPlot(pos, var = "dataset", order = "increasing") +
ggtitle("CD45+ Pre-batch correction: dataset, increasing")
ggsave("plots_analysis/dimPlot_dataset_incr_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_dataset_incr_fresh_pos.pdf")
dittoDimPlot(pos, var = "dataset", order = "decreasing") +
ggtitle("CD45+ Pre-batch correction: dataset, decreasing")
ggsave("plots_analysis/dimPlot_dataset_decr_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_dataset_decr_fresh_pos.pdf")
# visualize other metadata to see if batch correction is needed
dittoDimPlot(pos, var = "digest_method") +
ggtitle("CD45+ Pre-batch correction: digestion method")
ggsave("plots_analysis/dimPlot_digest_method_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_digest_method_fresh_pos.pdf")
dittoDimPlot(pos, var = "digest_method", split.by = "digest_method") +
theme(legend.position = "none") +
ggtitle("CD45+ Pre-batch correction: digestion method")
ggsave("plots_analysis/dimPlot_splitDigestMethod_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_splitDigestMethod_fresh_pos.pdf")
dittoDimPlot(pos, var = "patientID") +
ggtitle("CD45+ Pre-batch correction: patient ID")
ggsave("plots_analysis/dimPlot_patientID_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_patientID_fresh_pos.pdf")
dittoDimPlot(pos, var = "patientID", split.by = "patientID") +
ggtitle("CD45+ Pre-batch correction: patient ID") +
theme(legend.position = "none")
ggsave("plots_analysis/dimPlot_splitPatientID_fresh_pos.png", bg = "white")
ggsave("plots_analysis/dimPlot_splitPatientID_fresh_pos.pdf")
# normalize ADT assay
DefaultAssay(pos) <- "ADT"
pos <- NormalizeData(pos, normalization.method = "CLR", margin = 2)
#saveRDS(pos, file = "integratedAnalysis/data_pos_analyzed_ADT.RDS")
pos <- readRDS(file = "integratedAnalysis/data_pos_analyzed_ADT.RDS")
# check out a few markers for visualization
row.names(pos@assays$ADT)
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD3:SK7-CD3E-AHS0033-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD3 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD3E") + ggtitle("CD3 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD19:SJ25C1-CD19-AHS0030-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD19 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD19") + ggtitle("CD19 RNA")
p1 | p2
####################################
### CD45 pos: cluster annotation ###
####################################
pos <- readRDS(file = "integratedAnalysis/data_pos_analyzed_ADT.RDS")
### use AbSeq data to help annotate clusters ###
row.names(pos@assays$ADT)
# T cells
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD3:SK7-CD3E-AHS0033-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD3 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD3E") + ggtitle("CD3 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD8:SK1-CD8A-AHS0228-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD8 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD8A") + ggtitle("CD8 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD4:RPA-T4-CD4-AHS0227-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD4 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD4") + ggtitle("CD4 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD279:MIH4-PDCD1-AHS0190-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD279 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "PDCD1") + ggtitle("CD279 RNA")
p1 | p2
# B cells
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD19:SJ25C1-CD19-AHS0030-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD19 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD19") + ggtitle("CD19 RNA")
p1 | p2
FeaturePlot(pos, features = "MS4A1")
# myeloid cells
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD15-FUT4-AHS0196-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD15 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "FUT4") + ggtitle("CD15 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD14:M5E2-CD14-AHS0173-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD14 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD14") + ggtitle("CD14 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD16:3G8-FCGR3A-AHS0053-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD16 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "FCGR3A") + ggtitle("CD16 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD11b:M1-70-ITGAM-AHS0005-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD11b protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "ITGAM") + ggtitle("CD11b RNA")
p1 | p2
DefaultAssay(pos) <- "ADT" # DCs
p1 <- FeaturePlot(pos, "CD11c:B-LY6-ITGAX-AHS0056-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD11c protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "ITGAX") + ggtitle("CD11c RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD206-MRC1-AHS0072-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD206 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "MRC1") + ggtitle("CD206 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD80-CD80-AHS0046-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD80 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD80") + ggtitle("CD80 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD86:2331-CD86-AHS0057-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD86 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD86") + ggtitle("CD86 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "HLA-DR-CD74-AHS0035-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD74 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD74") + ggtitle("CD74 RNA")
p1 | p2
FeaturePlot(pos, features = "LYZ")
FeaturePlot(pos, features = "HLA-DRA")
FeaturePlot(pos, features = "HLA-DPA1")
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD56:B159-NCAM1-AHS0257-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD56 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "NCAM1") + ggtitle("CD56 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "Tim3-HAVCR2-AHS0016-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("Tim3 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "HAVCR2") + ggtitle("Tim3 RNA")
p1 | p2
# CD1a Langerhans cells
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD1a-CD1A-AHS0067-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD1a protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD1A") + ggtitle("CD1a RNA")
p1 | p2
FeaturePlot(pos, features = "CD207")
# DCs
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD11c:B-LY6-ITGAX-AHS0056-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD11c protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "ITGAX") + ggtitle("CD11c RNA")
p1 | p2
# mast cells and basophils
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD117:104D2-KIT-AHS0165-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD117 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "KIT") + ggtitle("CD117 RNA")
p1 | p2
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD69-CD69-AHS0010-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD69 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CD69") + ggtitle("CD69 RNA")
p1 | p2
FeaturePlot(pos, features = "CPA3")
FeaturePlot(pos, features = "FCGR2A")
FeaturePlot(pos, features = "FCER1A")
FeaturePlot(pos, features = "IL13")
# mast cells
FeaturePlot(pos, features = "TPSAB1")
FeaturePlot(pos, features = "CMA1")
FeaturePlot(pos, features = "MITF")
# basophils
FeaturePlot(pos, features = "ENPP3") # CD203c
FeaturePlot(pos, features = "CD63")
FeaturePlot(pos, features = "IL3RA") # CD123
FeaturePlot(pos, features = "CCR3")
FeaturePlot(pos, features = "IL4")
FeaturePlot(pos, features = "CEBPA")
# fibroblasts
FeaturePlot(pos, features = "CD34")
FeaturePlot(pos, features = "COL1A1")
FeaturePlot(pos, features = "LOXL1")
FeaturePlot(pos, features = "LUM")
FeaturePlot(pos, features = "FBLN1")
FeaturePlot(pos, features = "FBLN2")
# immune cells (CD45+)
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD45RA:HI100-PTPRC-AHS0009-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD45RA protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "PTPRC") + ggtitle("CD45 RNA")
p1 | p2
ggsave("plots_analysis/featurePlot_CD45RA_RNA_ADT.png")
ggsave("plots_analysis/featurePlot_CD45RA_RNA_ADT.pdf")
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD45RO-PTPRC-AHS0036-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD45RO protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "PTPRC") + ggtitle("CD45 RNA")
p1 | p2
ggsave("plots_analysis/featurePlot_CD45RO_RNA_ADT.png")
ggsave("plots_analysis/featurePlot_CD45RO_RNA_ADT.pdf")
# CD193 basophils, eosinophils, Th1 & Th2 T cells
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD193-CCR3-AHS0159-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD193 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "CCR3") + ggtitle("CD193 RNA")
p1 | p2
# CD138 plasma cells
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD138-SDC1-AHS0121-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD138 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "SDC1") + ggtitle("CD138 RNA")
p1 | p2
FeaturePlot(pos, features = "CD27")
FeaturePlot(pos, features = "SLAMF7")
# CD161 Th17 cells (should be mixed with T cells at this clustering resolution)
DefaultAssay(pos) <- "ADT"
p1 <- FeaturePlot(pos, "CD161:HP-3G10-KLRB1-AHS0205-pAbO", cols = c("lightgrey", "darkgreen")) + ggtitle("CD161 protein")
DefaultAssay(pos) <- "RNA"
p2 <- FeaturePlot(pos, "KLRB1") + ggtitle("CD161 RNA")
p1 | p2
FeaturePlot(pos, features = "RORC")
# endothelial cells
FeaturePlot(pos, features = "CD34")
FeaturePlot(pos, features = "PECAM1")
FeaturePlot(pos, features = "CDH5")
FeaturePlot(pos, features = "KDR")
# vascular smooth muscle cells
FeaturePlot(pos, features = "ACTA2")
FeaturePlot(pos, features = "CNN1")
FeaturePlot(pos, features = "TAGLN")
FeaturePlot(pos, features = "MYH11")
### find DE markers between mast cell clusters ###
mastDEmarkers <- FindMarkers(pos, ident.1 = "4", ident.2 = "10")
# Positive LFC = feature more highly expressed in the FIRST group.
head(mastDEmarkers, n = 10)
# get significant only
sigMastDEmarkers <- mastDEmarkers[mastDEmarkers$p_val_adj <= 0.05,]
# ascending order
sigMastDEmarkers %>%
arrange(avg_log2FC) %>%
slice(1:10)
# descending order
sigMastDEmarkers %>%
arrange(-avg_log2FC) %>%
slice(1:10)
### run find markers ###
DefaultAssay(pos) <- "RNA"
markers <- FindAllMarkers(pos, assay = "RNA")
#saveRDS(markers, file = "integratedAnalysis/data_pos_markers.RDS")
markers <- readRDS("integratedAnalysis/data_pos_markers.RDS")
# view top genes by cluster number
head(markers[markers$cluster == "10",], n = 10)
unique(pos$seurat_clusters)
pos$seurat_clusters <- Idents(pos)
unique(pos$seurat_clusters)
pos <- RenameIdents(pos,
`0` = "T cells",
`1` = "Myeloid cells",
`2` = "Myeloid cells",
`3` = "Fibroblasts",
`4` = "Mast cells",
`5` = "Myeloid cells",
`6` = "Endothelial cells",
`7` = "Plasma cells",
`8` = "B cells",
`9` = "Vascular smooth muscle cells",
`10` = "Antigen-presenting mast cells")
pos$annot_clusters <- Idents(pos)
unique(pos$annot_clusters)
#saveRDS(pos, file = "integratedAnalysis/data_pos_annotated_sepMastClusters.RDS")
### visualize ###
DefaultAssay(pos) <- "RNA"
cluster_markers <- c("PTPRC","CD3E","CD8A",
"CD14","ITGAX","MRC1",
"CD86","CD74","LYZ","HLA-DRA",
"COL1A1","FBLN1","LUM",
"KIT","CD69","CMA1","TPSAB1",
"PECAM1","CDH5","KDR","CD34",
"SDC1","CD27","SLAMF7",
"CD19","MS4A1",
"ACTA2","CNN1","TAGLN","MYH11")
legend <- get_legend(DotPlot(pos, features = cluster_markers) +
theme(legend.title=element_text(size=10)))
p <- DotPlot(pos, features = cluster_markers) +
RotatedAxis() +
ggtitle("CD45+ Marker Gene Expression") +
theme(legend.position = "",
axis.title.y = element_blank())
plot_grid(p, legend, nrow = 1, ncol = 2, rel_widths = c(6,1))
ggsave("plots_analysis/dotplot_pos_RNA_sepMastClusters.png", bg = "white", units = "in", width = 10, height = 5)
ggsave("plots_analysis/dotplot_pos_RNA_sepMastClusters.pdf", units = "in", width = 10, height = 5)
DefaultAssay(pos) <- "ADT"
row.names(pos@assays$ADT)
cluster_markers_ADT <- c("CD45RA:HI100-PTPRC-AHS0009-pAbO",
"CD45RO-PTPRC-AHS0036-pAbO",
"CD3:SK7-CD3E-AHS0033-pAbO",
"CD4:RPA-T4-CD4-AHS0227-pAbO",
"CD8:SK1-CD8A-AHS0228-pAbO",
"CD14:M5E2-CD14-AHS0173-pAbO",
"CD16:3G8-FCGR3A-AHS0053-pAbO",
"CD11b:M1-70-ITGAM-AHS0005-pAbO",
"CD11c:B-LY6-ITGAX-AHS0056-pAbO",
"CD1c-CD1C-AHS0088-pAbO",
"CD80-CD80-AHS0046-pAbO",
"CD86:2331-CD86-AHS0057-pAbO",
"HLA-DR-CD74-AHS0035-pAbO",
"CD117:104D2-KIT-AHS0165-pAbO",
"CD69-CD69-AHS0010-pAbO",
"CD138-SDC1-AHS0121-pAbO",
"CD19:SJ25C1-CD19-AHS0030-pAbO")
labels <- gsub(":.*","",cluster_markers_ADT)
labels <- gsub("HLA-DR-CD74-AHS0035-pAbO","CD74",labels)
labels <- gsub("CD80-CD80-AHS0046-pAbO","CD80",labels)
labels <- gsub("CD69-CD69-AHS0010-pAbO","CD69",labels)
labels <- gsub("CD138-SDC1-AHS0121-pAbO","CD138",labels)
labels <- gsub("CD45RO-PTPRC-AHS0036-pAbO","CD45RO",labels)
labels <- gsub("CD1c-CD1C-AHS0088-pAbO", "CD1c",labels)
labels
DotPlot(pos, features = cluster_markers_ADT, cols = c("lightgrey", "darkgreen")) +
scale_x_discrete(labels = labels) +
RotatedAxis() + ylab("") + xlab("") +
ggtitle("CD45+ Marker Protein Expression")
ggsave("plots_analysis/dotplot_pos_ADT_sepMastClusters.png", bg = "white")
ggsave("plots_analysis/dotplot_pos_ADT_sepMastClusters.pdf", units = "in",
width = 8, height = 5)
DefaultAssay(pos) <- "RNA"
dittoDimPlot(pos, var = "annot_clusters") +
ggtitle("scRNA-seq of CD45+ cells") +
theme(plot.title = element_text(hjust = 0.5),
legend.text=element_text(size = 11),
legend.position = "bottom") +
guides(color=guide_legend(ncol=2, override.aes = list(size=5)))
ggsave("plots_analysis/dimPlot_pos_annot_sepMastClusters.png", bg = "white",
units = "in", width = 5, height = 6)
ggsave("plots_analysis/dimPlot_pos_annot_sepMastClusters.pdf")
dittoDimPlot(pos, var = "annot_clusters", split.by = "digest_method") +
ggtitle("CD45+ cells split by digestion method") +
theme(plot.title = element_text(hjust = 0.5, size = 16)) +
theme(rect = element_rect(fill = "transparent"),
legend.position = "bottom",
legend.text=element_text(size=10)) +
guides(color=guide_legend(ncol=3, override.aes = list(size=5)))
ggsave("plots_analysis/dimPlot_pos_annot_splitDigest_sepMastClusters.png", units = "in", width = 5, height = 5)
ggsave("plots_analysis/dimPlot_pos_annot_splitDigest_sepMastClusters.pdf")
#####################################
### CD45 pos: prop test all cells ###
#####################################
pos <- readRDS(file = "integratedAnalysis/data_pos_annotated_sepMastClusters.RDS")
# first visualize percentage of cells in each cluster
unique(pos$annot_clusters)
dittoBarPlot(pos, var = "annot_clusters", group.by = "digest_method",
var.labels.reorder = c(8,6,4,5,3,7,2,9,1), x.labels.rotate = FALSE) +
ggtitle("CD45+ cell type proportions") +
theme(plot.title = element_text(hjust = 0.5),
axis.title.y = element_text(size = 14),
axis.text.x = element_text(size = 12),
legend.text=element_text(size = 10)) +
xlab("") +
RotatedAxis()
ggsave("plots_analysis/barplot_proportions_pos_mastSep.png")
ggsave("plots_analysis/barplot_proportions_pos_mastSep.pdf")
# create the analysis object
prop_test <- sc_utils(pos)
# run testing and bootstrapping-- sample1 ctrl, sample2 treatment
prop_test <- permutation_test(
prop_test, cluster_identity = "annot_clusters",
sample_1 = "Simultaneous", sample_2 = "Sequential",
sample_identity = "digest_method"
)
saveRDS(prop_test, file = "data_pos_prop_test_results_sepMastClusters.RDS")
write.table(prop_test@results, quote = FALSE, sep = "\t", file = "integratedAnalysis/prop_test_results_sepMastClusters.txt")
head(prop_test@results)
### visualize results ###
# significantly up is higher in sequential
# significantly down is lower in sequential
permutation_plot(prop_test) +
ggtitle("CD45+ Sequential vs. Simultaneous\n") +
ylab("log2FD") +
theme(plot.title = element_text(hjust = 0.5, size = 16),
legend.position = "bottom",
legend.title = element_blank(),
legend.text = element_text(size = 12),
axis.title.y = element_blank(),
axis.text.y = element_text(size = 14),
axis.title.x = element_text(size = 14))
ggsave("plots_analysis/prop_plot_pos_sepMastClusters.png", bg = "white")
ggsave("plots_analysis/prop_plot_pos_sepMastClusters.pdf")
######################################
### analysis CD45 negative dataset ###
######################################
filtered_seurat <- readRDS(file = "integratedAnalysis/data_listOfSeuratObjects_filtered.RDS")
# get just CD45 negative dataset
neg <- filtered_seurat[["DE2_CD45neg"]]
#saveRDS(neg, file = "integratedAnalysis/data_neg.RDS")
neg <- readRDS(file = "integratedAnalysis/data_neg.RDS")
### standard analysis ###
neg <- NormalizeData(neg)
neg <- FindVariableFeatures(neg, selection.method = "vst", nfeatures = 2000)
neg <- ScaleData(neg)
neg <- RunPCA(neg)
ElbowPlot(neg, ndims = 20)
neg <- RunUMAP(neg, dims = 1:8, reduction = "pca")
neg <- FindNeighbors(neg, dims = 1:8)
res_range <- c(seq(0.1,1.0,0.1), seq(1.2,2.0,0.2))
res_range
neg <- FindClusters(neg, resolution = res_range)
head(neg[[]])
clustree(neg, prefix = "RNA_snn_res.", show_axis = TRUE) +
theme(legend.position="none")
ggsave("plots_analysis/clustree_prebatch_fresh_neg.png", bg = "white", width = 7, height = 12, units = "in")
ggsave("plots_analysis/clustree_prebatch_fresh_neg.pdf", width = 7, height = 12, units = "in")
# set optimal resolution
Idents(neg) <- neg$RNA_snn_res.0.1
#saveRDS(neg, file = "integratedAnalysis/data_neg_analyzed.RDS")
neg <- readRDS(file = "integratedAnalysis/data_neg_analyzed.RDS")
dittoDimPlot(neg, var = Idents(neg), reduction.use = "umap") +
ggtitle("CD45- Pre-batch correction")
ggsave("plots_analysis/dimPlot_seurat_clusters_fresh_neg.png", bg = "white")
ggsave("plots_analysis/dimPlot_seurat_clusters_fresh_neg.pdf")
# visualize metadata to see if batch correction is needed
dittoDimPlot(neg, var = "digest_method") +
ggtitle("CD45- Pre-batch correction: digestion method")
ggsave("plots_analysis/dimPlot_digest_method_fresh_neg.png", bg = "white")
ggsave("plots_analysis/dimPlot_digest_method_fresh_neg.pdf")
dittoDimPlot(neg, var = "digest_method", split.by = "digest_method") +