-
Notifications
You must be signed in to change notification settings - Fork 1
/
SCSeqFxs.R
1976 lines (1734 loc) · 94.3 KB
/
SCSeqFxs.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
# Functions for plotting and other single cell sequencing analysis
# SCSeqFxs.R
# get_obj_name
# plot_markers
# FindMarkersByConditionEachCluster
# FindMarkersByCondition
# compare_clusters
# plot_huang2021
# plot_filioDCMarkers
# Plot_TaylorMarkers
# doPseudotime
# doGSEA
# doAnalysis
# get the name of an object
get_obj_name <- function(x) {
print(as.character(substitute(x)))
}
# gets the current timestamp "hour_min_second" to add to folder names
get_folder_timestamp <- function() {
min_sec <- paste(as.character(as.POSIXlt(Sys.time())$min), as.character(round(as.POSIXlt(Sys.time())$sec)), sep = "_")
folder_timestamp <- paste(as.character(as.POSIXlt(Sys.time())$hour), min_sec, sep = "_")
return(folder_timestamp)
}
# General use function to make plots with whatever set of markers you want
# Works best with 4 or 6 markers, but can change ncol to fit others better.
# dataset is the seurat object
# objname is obj_name(dataset)
# marker_panel is the list of markers
# example function call:
# plot_markers(combined.DCs, get_obj_name(combined.DCs), c("Irf4", "Il12a", "Il15", "Cxcl12", "Cxcl16", "Ccl19", "Mki67", "Xcr1", "Eadem1"))
plot_markers <- function(dataset, objname, marker_panel) {
# create subdirectory to put the outputs into
foldername <- paste("PlotMarkers", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: plot_markers", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "RNA"
# Make plots
# plot UMAPs for context
pdf(paste(objname, "UMAP1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", label = TRUE, repel = TRUE, pt.size = 1.75, label.size = 6))
dev.off()
# split by orig.ident
pdf(paste(objname, "UMAP_byCondition1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE, pt.size = 1.75, label.size = 6))
dev.off()
# Violin plots
pdf("Violins.pdf", width = 16, height = 10)
plots <- VlnPlot(dataset, features = marker_panel, pt.size = 0)
print(wrap_plots(plots = plots))
dev.off()
# Feature plots
pdf("FeaturePlot.pdf", width = 12, height = 10)
print(FeaturePlot(dataset, features = marker_panel, ncol = 3))
dev.off()
# Violin plots split by condition
pdf("SplitViolins.pdf", width = 16, height = 10)
plots <- VlnPlot(dataset, features = marker_panel, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# For all clusters, find the DE genes between conditions
# Note: Now includes GSEA! Does this for each cluster.
# Example, what's different between tumor vs. egressed in cluster 3? (for each cluster)
# dataset is the seurat object
# objname is obj_name(dataset)
# example function call:
# FindMarkersByConditionEachCluster(combined.DCs, get_obj_name(combined.DCs))
FindMarkersByConditionEachCluster <- function(dataset, objname, runGsea = TRUE) {
# create subdirectory to put the outputs into
foldername <- paste("GSEA_DE_ByCondition", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: FindMarkersByConditionEachCluster", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "integrated"
# make a new metadata column "cluster_condition" and fill it with the cluster (Idents()) and condition info
# Idents() is the seurat cluster, orig.idents is conditions (ie tumor or egressed)
# examples: "0_egressed" or "0_tumor" or "1_egressed" or "1_tumor" etc...
#dataset$cluster_condition <- paste(Idents(dataset), dataset$Condition, sep = "_")
# make a new column called celltype to store the old cluster identities
#dataset$celltype <- Idents(dataset)
# Fill the identities column with the values in the new "cluster_condition" column
#Idents(dataset) <- "cluster_condition"
# now we can find the markers distinguishing the conditions within a cluster
# cycle through all clusters
# assumes cluster number starts at 0 and goes up as integers
# assumes clusters have not been renamed... could get around this by just using seurat clusters... Implemented below
ClusterList <- sort(c(unique(dataset$seurat_clusters)))-1
# assumes only 2 conditions
ConditionList <- c(unique(dataset$orig.ident))
# ClusterList <- sort(c(unique(Idents(dataset))))-1
# save a text file describing the conditions compared
write.table(ConditionList[1:2], sep="\t", file="Condition1vsCondition2.txt", quote = FALSE, row.names = TRUE)
# I'm gonna assume this is already installed since it's in the readme to do so.
## install organism library for GSEA
#if (runGsea == TRUE) {
# # SET THE DESIRED ORGANISM HERE
# # organism = "org.Mm.eg.db"
# BiocManager::install(organism, character.only = TRUE)
# library(organism, character.only = TRUE)
#}
for (ClusterID in ClusterList) {
#FindMarkersByCondition(subset(dataset, Idents(dataset)==ClusterID), obj_name(dataset), ClusterID)
# ^error, subset function doesn't really work programmatically at this point. Here's a workaround:
cells.use <- colnames(dataset)[which(dataset[[]]['seurat_clusters'] == ClusterID)]
cell_subset <- subset(dataset, cells = cells.use)
# make a new column called celltype to store the old cluster identities
cell_subset$celltype <- Idents(cell_subset)
# Fill the identities column with the values in the "Condition" column ("egressed" or "tumor")
Idents(cell_subset) <- "orig.ident"
# If the number of cells in a certain group is 3 or less, skip it and print a note.
# cells.cond1.use <- colnames(cell_subset)[which(cell_subset[[]]['Condition'] == "egressed")]
# cells.cond2.use <- colnames(cell_subset)[which(cell_subset[[]]['Condition'] == "tumor")]
# try using orig.ident instead:
cells.cond1.use <- colnames(cell_subset)[which(cell_subset[[]]['orig.ident'] == ConditionList[1])]
cells.cond2.use <- colnames(cell_subset)[which(cell_subset[[]]['orig.ident'] == ConditionList[2])]
if (length(cells.cond1.use) < 4 || length(cells.cond2.use) < 4) {
print('Number of cells in a condition group of cluster: ')
print(ClusterID)
print('is 3 or less. Skipping this cluster.')
next
}
# print('head(orig.ident)')
# print(head(dataset$orig.ident, 30))
# If we're running the doGSEA function, FindMarkersByCondition will be run anyway.
if (runGsea == FALSE) {
FindMarkersByCondition(cell_subset, objname, ClusterID)
}
# use a trycatch here since GSEA gives errors so often.
#doGSEA(cell_subset, objname, ClusterID)
tryGSEA(cell_subset, objname, ClusterID, comparison = "condition")
}
# Reset to original working directory and default array
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# For one cluster, find the DE genes between conditions
# Example, what's different between tumor vs. egressed in cluster 3?
# data should already be subset to only include the cluster of interest.
# Can define the number of genes to include in the "top" and "bot" comparisons
# If return_table is TRUE, it returns the results table, which can be used for GSEA and other things.
FindMarkersByCondition <- function(dataset, objname, ClusterID, num_genes = 100, return_table = FALSE) {
# create subdirectory to put the outputs into
clustername <- paste("Cluster", ClusterID, sep="") # Cluster0
foldername <- paste(clustername, get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: FindMarkersByCondition", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Cluster: ", ClusterID), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "integrated"
# make a list of the different conditions, or "orig.ident"s
cond_list <- unique(dataset$orig.ident)
# make a new column called celltype to store the old cluster identities
dataset$celltype <- Idents(dataset)
# Fill the identities column with the values in the "Condition" column ("egressed" or "tumor")
Idents(dataset) <- "orig.ident"
# find markers between the two conditions
markers <- FindMarkers(dataset, ident.1 = cond_list[1], ident.2 = cond_list[2], min.pct = 0.25, verbose = FALSE)
# save a text file describing the conditions compared
write.table(cond_list[1:2], sep="\t", file="Condition1vsCondition2.txt", quote = FALSE, row.names = TRUE)
# save the results to a text file
write.table(markers, sep="\t", file=paste(clustername, "MarkersByCondition.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(markers['avg_log2FC'], sep="\t", file=paste(clustername, "Markers&LFCByCondition.rnk", sep="_"), quote = FALSE, row.names = TRUE, col.names = FALSE)
# top 50 most up- and down- regulated genes
top_genes <- markers %>% top_n(n = num_genes, wt = avg_log2FC)
bot_genes <- markers %>% top_n(n = (-1)*num_genes, wt = avg_log2FC)
write.table(top_genes, sep="\t", file=paste(clustername, "UP_MarkersByCondition.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(bot_genes, sep="\t", file=paste(clustername, "DOWN_MarkersByCondition.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(row.names(top_genes), sep="\t", file=paste(clustername, "UP_Names_MarkersByCondition.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(row.names(bot_genes), sep="\t", file=paste(clustername, "DOWN_Names_MarkersByCondition.txt", sep="_"), quote = FALSE, row.names = TRUE)
# Heatmaps of the above markers
pdf(paste(clustername, "UP_MarkersByCondition.pdf", sep="_"), height = 12)
print(DoHeatmap(dataset, features = row.names(top_genes), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
pdf(paste(clustername, "DOWN_MarkersByCondition.pdf", sep="_"), height = 12)
print(DoHeatmap(dataset, features = row.names(bot_genes), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
# Reset to original working directory and default array
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
# Return the results table if return_table is TRUE
if (return_table == TRUE) {
return(markers)
}
}
# For a dataset, find the DE genes between one cluster and the rest of the dataset
# Example, what's transcriptionally different about Cluster0?
# Can define the number of genes to include in the "top" and "bot" comparisons
# If return_table is TRUE, it returns the results table, which can be used for GSEA and other things.
FindMarkersByCluster <- function(dataset, objname, ClusterID, num_genes = 100, return_table = FALSE) {
# create subdirectory to put the outputs into
clustername <- paste("Cluster", ClusterID, sep="") # Cluster0
foldername <- paste(clustername, get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: FindMarkersByCluster", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Cluster: ", ClusterID), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "integrated"
# If Idents have been renamed, we can't use ClusterID for the ident in the FindMarkers function
# So make a new column for the cluster names
dataset$ClusterNames <- Idents(dataset)
# set seurat_clusters as the idents
Idents(dataset) <- dataset$seurat_clusters
# find markers for that cluster
markers <- FindMarkers(dataset, ident.1 = ClusterID, min.pct = 0.25, verbose = FALSE)
# save the results to a text file
clustername <- paste("Cluster", ClusterID, sep="")
write.table(markers, sep="\t", file=paste(clustername, "Markers.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(markers['avg_log2FC'], sep="\t", file=paste(clustername, "Markers&LFC.rnk", sep="_"), quote = FALSE, row.names = TRUE, col.names = FALSE)
# top 50 most up- and down- regulated genes
top_genes <- markers %>% top_n(n = num_genes, wt = avg_log2FC)
bot_genes <- markers %>% top_n(n = (-1)*num_genes, wt = avg_log2FC)
write.table(top_genes, sep="\t", file=paste(clustername, "UP_MarkersByCluster.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(bot_genes, sep="\t", file=paste(clustername, "DOWN_MarkersByCluster.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(row.names(top_genes), sep="\t", file=paste(clustername, "UP_Names_MarkersByCluster.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(row.names(bot_genes), sep="\t", file=paste(clustername, "DOWN_Names_MarkersByCluster.txt", sep="_"), quote = FALSE, row.names = TRUE)
# Heatmaps of the above markers
pdf(paste(clustername, "UP_MarkersByCluster.pdf", sep="_"), height = 12)
print(DoHeatmap(dataset, features = row.names(top_genes), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
pdf(paste(clustername, "DOWN_MarkersByCluster.pdf", sep="_"), height = 12)
print(DoHeatmap(dataset, features = row.names(bot_genes), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
# Reset to original working directory and default array
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
# Return the results table if return_table is TRUE
if (return_table == TRUE) {
return(markers)
}
}
# Finds the DE genes between two clusters, outputs tables and heatmaps.
# Example, what's different between clusters 9 and 1?
# ClusterID1 and ClusterID2 should be strings containing the cluster IDs
# Example call:
# compare_clusters(combined.DCs, get_obj_name(combined.DCs), "0", "1")
compare_clusters <- function(dataset, objname, ClusterID1, ClusterID2) {
# create subdirectory to put the outputs into
comparison <- paste(ClusterID1, ClusterID2, sep="vs")
clustername <- paste("Cluster", comparison, sep="") # Cluster0vs2
foldername <- paste(clustername, get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: compare_clusters", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Cluster1: ", ClusterID1), file = run_log, append = TRUE, sep = "\n")
cat(paste("Cluster2: ", ClusterID2), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "integrated"
# find markers
markers <- FindMarkers(dataset, ident.1 = ClusterID1, ident.2 = ClusterID2, min.pct = 0.25, verbose = FALSE)
# save the results to a text file
write.table(markers, sep="\t", file=paste(clustername, "Markers.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(markers['avg_log2FC'], sep="\t", file=paste(clustername, "Markers&LFC.rnk", sep="_"), quote = FALSE, row.names = TRUE, col.names = FALSE)
# top 50 most up- and down- regulated genes
top50 <- markers %>% top_n(n = 50, wt = avg_log2FC)
bot50 <- markers %>% top_n(n = -50, wt = avg_log2FC)
write.table(top50, sep="\t", file=paste(clustername, "top50UP_Markers.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(bot50, sep="\t", file=paste(clustername, "top50DOWN_Markers.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(row.names(top50), sep="\t", file=paste(clustername, "Names_top50UP_Markers.txt", sep="_"), quote = FALSE, row.names = TRUE)
write.table(row.names(bot50), sep="\t", file=paste(clustername, "Names_top50DOWN_Markers.txt", sep="_"), quote = FALSE, row.names = TRUE)
cells_compared <- subset(dataset, seurat_clusters == ClusterID1 | seurat_clusters == ClusterID2)
# Heatmaps of the above markers
# show all clusters but only the DE genes between the two:
pdf(paste(clustername, "top50UP_Markers_AllClusters.pdf", sep="_"), height = 12)
print(DoHeatmap(dataset, features = row.names(top50), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
pdf(paste(clustername, "top50DOWN_Markers_AllClusters.pdf", sep="_"), height = 12)
print(DoHeatmap(dataset, features = row.names(bot50), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
# show only the two clusters compared
pdf(paste(clustername, "top50UP_Markers.pdf", sep="_"), height = 12)
print(DoHeatmap(cells_compared, features = row.names(top50), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
pdf(paste(clustername, "top50DOWN_Markers.pdf", sep="_"), height = 12)
print(DoHeatmap(cells_compared, features = row.names(bot50), size = 3) + NoLegend() + theme(axis.text.y = element_text(size = 5)))
dev.off()
# Reset to original working directory and default array
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# Markers from Huang et al 2021 - Innervated Lymph Nodes ------------------
plot_huang2021 <- function(dataset, objname) {
# create subdirectory to put the outputs into
foldername <- paste("Huang2021_Markers", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: plot_huang2021", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "RNA"
# plot UMAPs for context
pdf(paste(objname, "UMAP1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", label = TRUE, repel = TRUE, pt.size = 1.75))
dev.off()
# split by orig.ident
pdf(paste(objname, "UMAP_byCondition1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE, pt.size = 1.75))
dev.off()
# Neutrophil panel
neutrophil_panel1 <- c("Clec4d", "Csf3r", "Cxcr2", "Ngp", "Camp", "S100a9")
pdf(paste(objname, "Neutrophil_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = neutrophil_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Neutrophil_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = neutrophil_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Neutrophil_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = neutrophil_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# CD4+ Cell panel
CD4_panel1 <- c("Foxp3", "Ctla4", "Cd5", "Trbc2", "Cd4", "Lef1")
pdf(paste(objname, "CD4_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = CD4_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "CD4_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = CD4_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "CD4_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = CD4_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# NK Cell panel
NK_panel1 <- c("Tox", "Cd8a", "Nkg7", "Birc5", "Kif11", "Ncr1", "Klrb1c")
pdf(paste(objname, "NK_Panel_Violins1.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = NK_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "NK_Panel_FeaturePlot1.pdf", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = NK_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "NK_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = NK_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Mitotic Cell panel
Mitotic_panel1 <- c("Cenpe", "Tubb5", "Thy1", "Top2a", "Mki67", "", "")
pdf(paste(objname, "Mitotic_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = Mitotic_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Mitotic_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = Mitotic_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Mitotic_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Mitotic_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# "Tissue T" Cell panel
TissueTcells_panel1 <- c("Gata3", "Itgae", "Cxcr6", "Cd3d", "", "", "")
pdf(paste(objname, "TissueTcells_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = TissueTcells_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "TissueTcells_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = TissueTcells_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "TissueTcells_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = TissueTcells_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Mast Cell panel
Mast_panel1 <- c("Gata2", "Kit", "Tpsb2", "Ccl9", "Fcgr3", "Csf1r", "C1qb", "Irf8")
pdf(paste(objname, "Mast_Panel_Violins1.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = Mast_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Mast_Panel_FeaturePlot1.pdf", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = Mast_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Mast_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Mast_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# DC Cell panel
DC_panel4 <- c("Clec9a", "Tlr11", "Xcr1", "Ccr7", "Arc", "Il15ra", "Ccl22", "")
pdf(paste(objname, "DC_Panel_Violins1.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = DC_panel4, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "DC_Panel_FeaturePlot1.pdf", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = DC_panel4, ncol = 3))
dev.off()
pdf(paste(objname, "DC_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = DC_panel4, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Random Cell panel
Random_panel1 <- c("Ccr9", "Siglech", "Jchain", "Igkc", "Cd274", "", "", "")
pdf(paste(objname, "Random_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = Random_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Random_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = Random_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Random_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Random_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Langerhans Cell panel
Langerhans_panel1 <- c("Cd1d1", "Cd207", "Flt3l", "Batf3", "Irf8", "", "", "")
pdf(paste(objname, "Langerhans_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = Langerhans_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Langerhans_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = Langerhans_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Langerhans_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Langerhans_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# DC5 Cell panel
DC5_panel1 <- c("Axl", "Ptprc", "Csf1r", "", "", "", "", "")
pdf(paste(objname, "DC5_Panel_Violins1.pdf", sep="_"), width = 10, height = 10)
print(VlnPlot(dataset, features = DC5_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "DC5_Panel_FeaturePlot1.pdf", sep="_"), width = 10, height = 10)
print(FeaturePlot(dataset, features = DC5_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "DC5_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = DC5_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# ------------------------------------------------
# plot Filio's DC Markers
# dataset is the dataset, objname is the name of the seurat object
# DC & Monocyte Marker Subsets from Filio...
# pDCs: Lin- (Ter119-(Ly76), Cd3-(Cd3e), Cd19-, Nk1.1-(Klrb1c))
# Cd11c+(Itgax), Siglech+, CD45R/B220+(Ptprc),
plot_FilioDCMarkers <- function(dataset, objname) {
# create subdirectory to put the outputs into
foldername <- paste("FilioDCMarkers", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: plot_FilioDCMarkers", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "RNA"
# plot UMAPs for context
pdf(paste(objname, "DC_UMAP1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", label = TRUE, repel = TRUE, pt.size = 1.75))
dev.off()
# split by orig.ident
pdf(paste(objname, "DC_UMAP_byCondition1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE, pt.size = 1.75))
dev.off()
# Lineage Marker panel. Ter-119 is Ly76
Lin_panel1 <- c("Ter-119", "Cd3e", "Cd19", "Klrb1c", "", "", "", "")
pdf(paste(objname, "Lin_Panel_Violins1.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = Lin_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Lin_Panel_FeaturePlot1.pdf", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = Lin_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Lin_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Lin_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# pDC panel
pDC_panel1 <- c("Itgax", "Siglech", "Ptprc", "Bst2", "Batf3", "Irf8", "Flt3l", "Irf7")
pdf(paste(objname, "pDC_Panel_Violins1.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = pDC_panel1, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "pDC_Panel_FeaturePlot1.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = pDC_panel1, ncol = 3))
dev.off()
pdf(paste(objname, "pDC_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = pDC_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# classical DC panel (cDC1 and cDC2)
# cDC1:
# CD11c hi (Itgax), MHCII hi (H2-Ab1), Cd24+, Cd8a+, Cd370+ (Clec9a), Cd11b low (Itgam), Cd172a low (Sirpa)
# cDC2:
# CD11c hi (Itgax), MHCII hi (H2-Ab1), Cd24+, Cd8a low, Cd370 low (Clec9a), Cd11b+ (Itgam), Cd172a+ (Sirpa)
# Tissue Resident DC: 2types?
# one is: CD103+(Itgae), CD45+(Ptprc), CD11c high (Itgax), MHCII+ (H2-Ab)
# other is: CD11b+(Itgam), CD45+(Ptprc), CD11c high (Itgax), MHCII+ (H2-Ab)
cDC_panel1 <- c("Itgax", "H2-Ab1", "Cd24a", "Cd8a", "Clec9a", "Itgam", "Sirpa", "Itgae", "Ccr7")
pdf(paste(objname, "cDC_Panel_Violins1.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = cDC_panel1, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "cDC_Panel_FeaturePlot1.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = cDC_panel1, ncol = 3))
dev.off()
pdf(paste(objname, "cDC_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = cDC_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Neutrophil panel
# Ly6G+, CD11b+(Itgam)
Neutrophil_panel2 <- c("Ly6g", "Itgam", "Ly6c1", "Fcgr3", "", "", "", "")
pdf(paste(objname, "Neutrophil_Panel2_Violins1.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = Neutrophil_panel2, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Neutrophil_Panel2_FeaturePlot1.pdf", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = Neutrophil_panel2, ncol = 2))
dev.off()
pdf(paste(objname, "Neutrophil_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Neutrophil_panel2, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Monocyte panel
# 2 types: Ly6C hi and low
# Gr-1 low (Ly6g1), Cd115+(Csf1r), Cd11b+(Itgam), F4/80 int(Adgre1), Cxcr1+, Ccr2+, Cd43+(Spn)
Mono_panel1 <- c("Ly6c1", "Ly6g", "Csf1r", "Itgam", "Adgre1", "Cxcr1", "Ccr2", "Spn")
pdf(paste(objname, "Mono_Panel_Violins1.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = Mono_panel1, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "Mono_Panel_FeaturePlot1.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = Mono_panel1, ncol = 3))
dev.off()
pdf(paste(objname, "Mono_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Mono_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots, nrow = 3))
dev.off()
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# ------------------------------------------------
# plot Taylor's CD8 T-cell Markers
# Exploring and defining the CD8+ clusters ------------------------------------
# Taylor CD8+ T-cell subtype panels -------------------------------------------
# Vps37b, Icos, Tcf7, S1pr1, Cxcr6, Itgae, Jun, Fos, Nr4a3, Klf2, Ifng, Cd69
# Gzmb and Sell
# Eomes, Tbx21, Runx3, Id2, Id3, Tox, Il7r, Klrg1, Ccr7, Pdcd1, Havcr2, and Lag3
# dataset is the dataset, objname is the name of the seurat object
plot_TaylorCD8Markers <- function(dataset, objname) {
# create subdirectory to put the outputs into
foldername <- paste("TaylorCD8Markers", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: plot_TaylorCD8Markers", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "RNA"
# plot UMAPs for context
pdf(paste(objname, "UMAP1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", label = TRUE, repel = TRUE, pt.size = 1.75))
dev.off()
# split by orig.ident
pdf(paste(objname, "UMAP_byCondition1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE, pt.size = 1.75))
dev.off()
# Taylor panel1
Taylor_panel1 <- c("Vps37b", "Icos", "Tcf7", "S1pr1", "Cxcr6", "Cxcr4")
pdf(paste(objname, "Taylor_Panel_Violins1.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = Taylor_panel1, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Taylor_Panel_FeaturePlot1", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = Taylor_panel1, ncol = 2))
dev.off()
pdf(paste(objname, "Taylor_Panel_SplitViolins1.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Taylor_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Taylor panel2
Taylor_panel2 <- c("Jun", "Fos", "Nr4a3", "Klf2", "Ifng", "Cd69")
pdf(paste(objname, "Taylor_Panel_Violins2.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = Taylor_panel2, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_FeaturePlot2.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = Taylor_panel2, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_SplitViolins2.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Taylor_panel2, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Taylor panel3
Taylor_panel3 <- c("Gzmb", "Sell", "Eomes", "Tbx21", "Runx3", "Tox")
pdf(paste(objname, "Taylor_Panel_Violins3.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = Taylor_panel3, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_FeaturePlot3.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = Taylor_panel3, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_SplitViolins3.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Taylor_panel3, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Taylor panel4
Taylor_panel4 <- c("Id2", "Id3", "Il7r", "Klrg1", "Hsf1", "")
pdf(paste(objname, "Taylor_Panel_Violins4.pdf", sep="_"), width = 13, height = 10)
print(VlnPlot(dataset, features = Taylor_panel4, pt.size = 0, ncol = 2))
dev.off()
pdf(paste(objname, "Taylor_Panel_FeaturePlot4", sep="_"), width = 13, height = 10)
print(FeaturePlot(dataset, features = Taylor_panel4, ncol = 2))
dev.off()
pdf(paste(objname, "Taylor_Panel_SplitViolins4.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Taylor_panel4, split.by = "orig.ident",
group.by = "seurat_clusters", pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 2))
dev.off()
# Taylor panel5
Taylor_panel5 <- c("Ccr7", "Pdcd1", "Havcr2", "Lag3", "", "")
pdf(paste(objname, "Taylor_Panel_Violins5.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = Taylor_panel5, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_FeaturePlot5.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = Taylor_panel5, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_SplitViolins5.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Taylor_panel5, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 2))
dev.off()
# Taylor panel6
Taylor_panel6 <- c("Cd44", "Mki67", "Fosb", "Nr4a1", "Ccr7", "")
pdf(paste(objname, "Taylor_Panel_Violins6.pdf", sep="_"), width = 14, height = 12)
print(VlnPlot(dataset, features = Taylor_panel6, pt.size = 0, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_FeaturePlot6.pdf", sep="_"), width = 14, height = 12)
print(FeaturePlot(dataset, features = Taylor_panel6, ncol = 3))
dev.off()
pdf(paste(objname, "Taylor_Panel_SplitViolins6.pdf", sep="_"), width = 18, height = 14)
plots <- VlnPlot(dataset, features = Taylor_panel6, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 2))
dev.off()
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# ------------------------------------------------
# plot the Rgs (1-21) and Grk (1-7) genes
# These play a role in activating/deactivating CXCR4
# CXCR4 is a g-protein coupled receptor
# These can modify it from inside the cell and affect signaling,
# thereby altering cell egress via CXCR4 / CXCL12 activity.
plot_Rgs_Grk_Markers <- function(dataset, objname) {
# create subdirectory to put the outputs into
foldername <- paste("RgsGrk_Markers", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: plot_Rgs_Grk_Markers", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "RNA"
# plot UMAPs for context
pdf(paste(objname, "UMAP1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", label = TRUE, repel = TRUE, pt.size = 1.75, label.size = 6))
dev.off()
# split by orig.ident
pdf(paste(objname, "UMAP_byCondition1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE, pt.size = 1.75, label.size = 6))
dev.off()
# Define panels
Rgs_panel1 <- c("Rgs1", "Rgs2", "Rgs3", "Rgs4", "Rgs5", "Rgs6", "Rgs7", "Rgs8", "Rgs9")
Rgs_panel2 <- c("Rgs10", "Rgs11", "Rgs12", "Rgs13", "Rgs14", "Rgs15")
Rgs_panel3 <- c("Rgs16", "Rgs17", "Rgs18", "Rgs19", "Rgs20", "Rgs21")
Grk_panel <- c("Grk1", "Grk2", "Grk3", "Grk4", "Grk5", "Grk6", "Grk7")
# Rgs_panel1
# Violin plots
pdf(paste(objname, "Rgs_Violins1.pdf", sep=""), width = 12, height = 10)
print(VlnPlot(dataset, features = Rgs_panel1, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Rgs_FeaturePlot1.pdf", sep=""), width = 12, height = 10)
print(FeaturePlot(dataset, features = Rgs_panel1, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Rgs_SplitViolins1.pdf", sep=""), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Rgs_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Rgs_panel2
# Violin plots
pdf(paste(objname, "Rgs_Violins2.pdf", sep=""), width = 12, height = 10)
print(VlnPlot(dataset, features = Rgs_panel2, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Rgs_FeaturePlot2.pdf", sep=""), width = 12, height = 10)
print(FeaturePlot(dataset, features = Rgs_panel2, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Rgs_SplitViolins2.pdf", sep=""), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Rgs_panel2, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Rgs_panel3
# Violin plots
pdf(paste(objname, "Rgs_Violins3.pdf", sep=""), width = 12, height = 10)
print(VlnPlot(dataset, features = Rgs_panel3, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Rgs_FeaturePlot3.pdf", sep=""), width = 12, height = 10)
print(FeaturePlot(dataset, features = Rgs_panel3, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Rgs_SplitViolins3.pdf", sep=""), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Rgs_panel3, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Grk_panel
# Violin plots
pdf(paste(objname, "Grk_Violins1.pdf", sep=""), width = 12, height = 10)
print(VlnPlot(dataset, features = Grk_panel, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Grk_FeaturePlot1.pdf", sep=""), width = 12, height = 10)
print(FeaturePlot(dataset, features = Grk_panel, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Grk_SplitViolins1.pdf", sep=""), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Grk_panel, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
DefaultAssay(dataset) <- tempdftassay
setwd(oldwd)
}
# ------------------------------------------------
# explore Egress Markers for Maria's paper
# Exploring and defining the CD8+ clusters ------------------------------------
# CXCR4, its ligand CXCL12, the decoy receptor Ackr3
# Intracellular regulators of CXCR4, the Rgs genes
# Cell cycle/proliferation marker Mki67
# dataset is the dataset, objname is the name of the seurat object
explore_EgressMarkers <- function(dataset, objname) {
# create subdirectory to put the outputs into
foldername <- paste("exploreEgressMarkers", get_folder_timestamp(), sep = "_")
dir.create(file.path(foldername))
oldwd <- getwd()
setwd(file.path(foldername))
# Write some run info to a log
run_log <- paste(getwd(), paste(objname, "_log.txt"), sep = "/")
cat("Function: explore_EgressMarkers", file = run_log, append = TRUE, sep = "\n")
cat(paste("Dataset: ", objname), file = run_log, append = TRUE, sep = "\n")
cat(paste("Timestamp: ", Sys.time()), file = run_log, append = TRUE, sep = "\n")
# change default assay to RNA, but create a temporary variable to change it back at the end.
tempdftassay <- DefaultAssay(dataset)
DefaultAssay(dataset) <- "RNA"
# plot UMAPs for context
pdf(paste(objname, "UMAP1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", label = TRUE, repel = TRUE, pt.size = 1.75, label.size = 6))
dev.off()
# split by orig.ident
pdf(paste(objname, "UMAP_byCondition1.pdf", sep="_"), width=12, height = 12)
print(DimPlot(dataset, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE, pt.size = 1.75, label.size = 6))
dev.off()
# Define panels
Egress_panel1 <- c("Cxcr4", "Cxcl12", "Ackr3", "Rgs1", "Rgs2", "Rgs3", "Rgs10", "Rgs16")
Egress_panel2 <- c("Ccr7", "S1pr1", "Cd69", "", "", "", "", "")
Exhaustion_panel1 <- c("Pdcd1", "Havcr2", "Lag3", "Tox", "Mki67", "H2-Ab1")
# Thymic_Egress <- c("Sphk1", "Sphk2", "Spns2", "Sp1", "Lpp3", "LTBR", "MST1", "MST2", "Coro1a")
Thymic_Egress <- c("Sphk1", "Sphk2", "Spns2", "Sp1", "LPP3", "Ltbr", "Mst1", "Stk3", "Coro1a")
# Stk3 is Mst2
# Egress_modulators are from James, Jenkinson, and Anderson 2018, it's thymic egress but still checking
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6174998/
# Taylor CD8+ T-cell subtype panels -------------------------------------------
# Vps37b, Icos, Tcf7, S1pr1, Cxcr6, Itgae, Jun, Fos, Nr4a3, Klf2, Ifng, Cd69
# Gzmb and Sell
# Eomes, Tbx21, Runx3, Id2, Id3, Tox, Il7r, Klrg1, Ccr7, Pdcd1, Havcr2, and Lag3
# Egress Panel1
# Violin plots
pdf(paste(objname, "Egress_Violins1.pdf", sep="_"), width = 12, height = 10)
print(VlnPlot(dataset, features = Egress_panel1, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Egress_FeaturePlot1.pdf", sep="_"), width = 12, height = 10)
print(FeaturePlot(dataset, features = Egress_panel1, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Egress_SplitViolins1.pdf", sep="_"), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Egress_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Egress Panel1
# Violin plots
pdf(paste(objname, "Egress_Violins2.pdf", sep="_"), width = 12, height = 10)
print(VlnPlot(dataset, features = Egress_panel2, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Egress_FeaturePlot2.pdf", sep="_"), width = 12, height = 10)
print(FeaturePlot(dataset, features = Egress_panel2, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Egress_SplitViolins2.pdf", sep="_"), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Egress_panel2, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Exhaustion Panel1
# Violin plots
pdf(paste(objname, "Exhaustion_Violins1.pdf", sep="_"), width = 12, height = 10)
print(VlnPlot(dataset, features = Exhaustion_panel1, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "Exhaustion_FeaturePlot1.pdf", sep="_"), width = 12, height = 10)
print(FeaturePlot(dataset, features = Exhaustion_panel1, ncol = 3))
dev.off()
# Violin plots split by condition
pdf(paste(objname, "Exhaution_SplitViolins1.pdf", sep="_"), width = 20, height = 10)
plots <- VlnPlot(dataset, features = Exhaustion_panel1, split.by = "orig.ident",
pt.size = 0, combine = FALSE)
print(wrap_plots(plots = plots, nrow = 3))
dev.off()
# Thymic Egress Panel1
# Violin plots
pdf(paste(objname, "ThymicEgress_Violins1.pdf", sep="_"), width = 12, height = 10)
print(VlnPlot(dataset, features = Thymic_Egress, pt.size = 0, ncol = 3))
dev.off()
# Feature plots
pdf(paste(objname, "ThymicEgress_FeaturePlot1.pdf", sep="_"), width = 12, height = 10)
print(FeaturePlot(dataset, features = Thymic_Egress, ncol = 3))
dev.off()
# Violin plots split by condition