Skip to content

Commit a548894

Browse files
WT: Plot updates
1 parent e320985 commit a548894

6 files changed

Lines changed: 26 additions & 26 deletions

File tree

R/map_cell_type_from_reference.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,12 @@ MapCellTypes_RNA <- function(sc_obj, reference, reference_cell_type_attribute =
406406
sample_count <- length(unique(sc_obj$sample))
407407
cell_count <- length(sc_obj$cell_name)
408408
# Plot by majority vote cell type
409-
current_title <- paste0("RNA Data Integration \n (By Majority Vote Cell Type) \n (", sample_count, " Samples, ", cell_count, " Cells)")
409+
current_title <- paste0("RNA Data Integration\n(By Majority Vote Cell Type)\n(", sample_count, " Samples, ", cell_count, " Cells)")
410410
print_UMAP_RNA(sc_obj, file_name = "Final_RNA_UMAP_by_Majority_Vote_Cell_Type.png",
411411
group_by_category = "predicted_celltype_majority_vote", output_dir = output_dir, title = current_title,
412412
log_flag = log_flag)
413413
# Plot by raw predicted cell type
414-
current_title <- paste0("RNA Data Integration \n (By Raw Predicted Cell Type) \n (", sample_count, " Samples, ", cell_count, " Cells)")
414+
current_title <- paste0("RNA Data Integration\n(By Raw Predicted Cell Type)\n(", sample_count, " Samples, ", cell_count, " Cells)")
415415
print_UMAP_RNA(sc_obj, file_name = "Final_RNA_UMAP_by_Raw_Predicted_Cell_Type.png",
416416
group_by_category = "predicted.id", output_dir = output_dir, title = current_title,
417417
log_flag = log_flag)
@@ -503,15 +503,15 @@ MapCellTypes_ATAC <- function(proj, reference, reference_cell_type_attribute = "
503503
}
504504
pal <- paletteDiscrete(values = proj$predictedGroup)
505505
p1 <- plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "predictedGroup", embedding = "UMAP", pal = pal, force = TRUE, keepAxis = TRUE) +
506-
ggplot2::ggtitle(paste0("ATAC Data After Integration (By Raw Predicted Cell Type) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
506+
ggplot2::ggtitle(paste0("ATAC Data Integration\n(By Raw Predicted Cell Type)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
507507
ggplot2::ggsave(filename = paste0(output_dir, "Final_ATAC_UMAP_by_Raw_Predicted_Cell_Type.png"), plot = p1, device = "png", width = 8, height = 8, units = "in")
508508
ArchR::plotPDF(p1, name = "Final_ATAC_UMAP_by_Raw_Predicted_Cell_Type", ArchRProj = proj, addDOC = FALSE, width = 5, height = 5)
509509
# We have to perform majority voting with a different cluster attribute if Harmony was not run
510510
# (due to only having one batch)
511511
proj <- MajorityVote_ATAC(proj, log_flag)
512512
pal <- paletteDiscrete(values = proj$Cell_type_voting)
513513
p2 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "Cell_type_voting", embedding = "UMAP", pal = pal, force = TRUE, keepAxis = TRUE) +
514-
ggplot2::ggtitle(paste0("ATAC Data After Integration (By Majority Vote Cell Type) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
514+
ggplot2::ggtitle(paste0("ATAC Data Integration\n(By Majority Vote Cell Type)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
515515
ggplot2::ggsave(filename = paste0(output_dir, "Final_ATAC_UMAP_by_Majority_Vote_Cell_Type.png"), plot = p2, device = "png", width = 8, height = 8, units = "in")
516516
ArchR::plotPDF(p1,p2, name = "UMAP_Cell_Type_Label_Plots", ArchRProj = proj, addDOC = FALSE, width = 5, height = 5)
517517
}

R/process_batches.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ IntegrateByBatch_ATAC <- function(proj, output_dir = getwd(), exit_with_code = F
367367
}
368368
# Plot integrated UMAPs
369369
p1 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "seurat_clusters", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
370-
ggplot2::ggtitle(paste0("ATAC Data After Integration (By Clusters) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
370+
ggplot2::ggtitle(paste0("ATAC Data Integration\n(By Clusters)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
371371
ggplot2::ggsave(filename = paste0(output_dir, "Final_ATAC_UMAP_by_Clusters.png"), plot = p1, device = "png", width = 8, height = 8, units = "in")
372372
p2 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "Sample", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
373-
ggplot2::ggtitle(paste0("ATAC Data After Integration (By Sample) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
373+
ggplot2::ggtitle(paste0("ATAC Data Integration\n(By Sample)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
374374
ggplot2::ggsave(filename = paste0(output_dir, "Final_ATAC_UMAP_by_Sample.png"), plot = p2, device = "png", width = 8, height = 8, units = "in")
375375
p3 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "TSSEnrichment", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
376-
ggplot2::ggtitle(paste0("ATAC Data After Integration (By TSS Enrichment) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
376+
ggplot2::ggtitle(paste0("ATAC Data Integration\n(By TSS Enrichment)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.key.size = ggplot2::unit(1, "cm"), legend.text = ggplot2::element_text(size=10))
377377
ggplot2::ggsave(filename = paste0(output_dir, "Final_ATAC_UMAP_by_TSSEnrichment.png"), plot = p3, device = "png", width = 8, height = 8, units = "in")
378378
ArchR::plotPDF(p1,p2,p3, name = "UMAP_Final_Integrated_Plots", ArchRProj = proj, addDOC = FALSE, width = 5, height = 5)
379379
return(proj)
@@ -426,12 +426,12 @@ VisualizeIntegration <- function(sc_obj, output_dir = getwd(), exit_with_code =
426426
sample_count <- length(unique(sc_obj$sample))
427427
cell_count <- length(sc_obj$cell_name)
428428
# Plot by cluster
429-
current_title <- paste0("RNA Data Integration (By Cluster) \n (", sample_count, " Samples, ", cell_count, " Cells)")
429+
current_title <- paste0("RNA Data Integration\n(By Cluster)\n(", sample_count, " Samples, ", cell_count, " Cells)")
430430
print_UMAP_RNA(sc_obj, file_name = "Final_RNA_UMAP_by_Cluster.png",
431431
group_by_category = "seurat_clusters", output_dir = output_dir, title = current_title,
432432
log_flag = log_flag)
433433
# Plot by sample
434-
current_title <- paste0("RNA Data Integration (By Sample) \n (", sample_count, " Samples, ", cell_count, " Cells)")
434+
current_title <- paste0("RNA Data Integration\n(By Sample)\n(", sample_count, " Samples, ", cell_count, " Cells)")
435435
print_UMAP_RNA(sc_obj, file_name = "Final_RNA_UMAP_by_Sample.png",
436436
group_by_category = "sample", output_dir = output_dir, title = current_title,
437437
log_flag = log_flag)

R/process_multiome.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ FindMultiomeOverlap <- function(sc_obj, proj, data_modality = "RNA", output_dir
3333
sample_text <- paste0("(", num_samples, " Samples, ", num_cells, " Cells)")
3434
}
3535
p1 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "Sample", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
36-
ggplot2::ggtitle(paste0("Multiome Overlap for ATAC Data (By Sample) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
36+
ggplot2::ggtitle(paste0("Multiome Overlap for ATAC Data\n(By Sample)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
3737
ggplot2::ggsave(filename = paste0(output_dir, "Final_Multiome_Overlap_ATAC_UMAP_by_Sample.png"), plot = p1, device = "png", width = 8, height = 8, units = "in")
3838
} else if(data_modality == "RNA") {
3939
sc_obj <- sc_obj[,ArchR::getCellNames(proj)]
4040
sample_count <- length(unique(sc_obj$sample))
4141
cell_count <- length(sc_obj$cell_name)
42-
current_title <- paste0("Multiome Overlap for RNA Data (By Sample) \n (", sample_count, " Samples, ", cell_count, " Cells)")
42+
current_title <- paste0("Multiome Overlap for RNA Data\n(By Sample)\n(", sample_count, " Samples, ", cell_count, " Cells)")
4343
print_UMAP_RNA(sc_obj, file_name = "Final_Multiome_Overlap_RNA_UMAP_by_Sample.png",
4444
group_by_category = "sample", output_dir = output_dir, title = current_title,
4545
log_flag = log_flag)
@@ -98,16 +98,16 @@ TransferRNALabels <- function(sc_obj, proj, RNA_output_dir = getwd(), ATAC_outpu
9898
sample_text <- paste0("(", num_samples, " Samples, ", num_cells, " Cells)")
9999
}
100100
p1 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "Cell_type_voting_RNA", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
101-
ggplot2::ggtitle(paste0("Multiome Overlap for ATAC Data \n (By RNA Majority Vote Cell Type) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
101+
ggplot2::ggtitle(paste0("Multiome Overlap for ATAC Data\n(By RNA Majority Vote Cell Type)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
102102
ggplot2::ggsave(filename = paste0(ATAC_output_dir, "Final_Multiome_Overlap_ATAC_UMAP_by_RNA_Majority_Vote_Cell_Type_Labels.png"), plot = p1, device = "png", width = 8, height = 8, units = "in")
103103
p2 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "Cell_type_voting", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
104-
ggplot2::ggtitle(paste0("Multiome Overlap for ATAC Data \n (By ATAC Majority Vote Cell Type) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
104+
ggplot2::ggtitle(paste0("Multiome Overlap for ATAC Data\n(By ATAC Majority Vote Cell Type)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
105105
ggplot2::ggsave(filename = paste0(ATAC_output_dir, "Final_Multiome_Overlap_ATAC_UMAP_by_Original_ATAC_Majority_Vote_Cell_Type_Labels.png"), plot = p2, device = "png", width = 8, height = 8, units = "in")
106106
ArchR::plotPDF(p1,p2, name = "UMAP_multiome_ATAC_with_RNA_labels_and_original_labels_plots", ArchRProj = proj, addDOC = FALSE, width = 5, height = 5)
107107
# RNA
108108
sample_count <- length(unique(sc_obj$sample))
109109
cell_count <- length(sc_obj$cell_name)
110-
current_title <- paste0("Multiome Overlap for RNA Data \n (By RNA Majority Vote Cell Type) \n (", sample_count, " Samples, ", cell_count, " Cells)")
110+
current_title <- paste0("Multiome Overlap for RNA Data\n(By RNA Majority Vote Cell Type)\n(", sample_count, " Samples, ", cell_count, " Cells)")
111111
print_UMAP_RNA(sc_obj, file_name = "Final_Multiome_Overlap_RNA_UMAP_by_RNA_Majority_Vote_Cell_Type_Labels.png",
112112
group_by_category = "predicted_celltype_majority_vote", output_dir = RNA_output_dir, title = current_title,
113113
log_flag = log_flag)

R/process_raw_data.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ InitialProcessing_RNA <- function(sc_obj, species = "human", output_dir = getwd(
290290
sc_obj <- Seurat::RunUMAP(sc_obj, reduction = "pca", dims = 1:30, seed.use = get_speedi_seed())
291291
sample_count <- length(unique(sc_obj$sample))
292292
cell_count <- length(sc_obj$cell_name)
293-
current_title <- paste0("RNA Data Before Integration \n (By Sample) \n (", sample_count, " Samples, ", cell_count, " Cells)")
293+
current_title <- paste0("RNA Data Before Integration\n(By Sample)\n(", sample_count, " Samples, ", cell_count, " Cells)")
294294
print_UMAP_RNA(sc_obj, file_name = "Before_Batch_Correction_RNA_UMAP_by_Sample.png",
295295
group_by_category = "sample", output_dir = output_dir, title = current_title,
296296
log_flag = log_flag)
@@ -358,10 +358,10 @@ InitialProcessing_ATAC <- function(proj, output_dir = getwd(), exit_with_code =
358358
sample_text <- paste0("(", num_samples, " Samples, ", num_cells, " Cells)")
359359
}
360360
p1 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "Sample", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
361-
ggplot2::ggtitle(paste0("ATAC Data Before Integration (By Sample) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
361+
ggplot2::ggtitle(paste0("ATAC Data Before Integration\n(By Sample)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.text = ggplot2::element_text(size=10))
362362
ggplot2::ggsave(filename = paste0(output_dir, "Before_Batch_Correction_ATAC_UMAP_by_Sample.png"), plot = p1, device = "png", width = 8, height = 8, units = "in")
363363
p2 <- ArchR::plotEmbedding(ArchRProj = proj, colorBy = "cellColData", name = "TSSEnrichment", embedding = "UMAP", force = TRUE, keepAxis = TRUE) +
364-
ggplot2::ggtitle(paste0("ATAC Data Before Integration (By TSS Enrichment) \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
364+
ggplot2::ggtitle(paste0("ATAC Data Before Integration\n(By TSS Enrichment)\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), legend.key.size = ggplot2::unit(1, "cm"), legend.text = ggplot2::element_text(size=10))
365365
ggplot2::ggsave(filename = paste0(output_dir, "Before_Batch_Correction_ATAC_UMAP_by_TSSEnrichment.png"), plot = p2, device = "png", width = 8, height = 8, units = "in")
366366
ArchR::plotPDF(p1,p2, name = "UMAPs_After_Initial_Processing_Plots", ArchRProj = proj, addDOC = FALSE, width = 5, height = 5)
367367
print_SPEEDI("Step 4: Complete", log_flag)

R/qc.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ Create_QC_Output_Prefiltered_RNA <- function(sc_obj, output_dir = getwd(), log_f
1111
# Normalize paths (in case user provides relative paths)
1212
output_dir <- normalize_dir_path(output_dir)
1313
print_SPEEDI("Printing QC plots on pre-filtered data (RNA)", log_flag)
14-
p <- Seurat::VlnPlot(sc_obj, features = c("nFeature_RNA"), split.by = "sample", group.by = "sample", raster = FALSE)
14+
p <- Seurat::VlnPlot(sc_obj, features = c("nFeature_RNA"), split.by = "sample", group.by = "sample", raster = FALSE) + ggplot2::xlab("Sample")
1515
ggplot2::ggsave(paste0(output_dir, "pre-filtered_nFeature_violin_plot.png"), plot = p, device = "png", width = 10, height = 10, units = "in")
16-
p <- Seurat::VlnPlot(sc_obj, features = c("nCount_RNA"), split.by = "sample", group.by = "sample", raster = FALSE)
16+
p <- Seurat::VlnPlot(sc_obj, features = c("nCount_RNA"), split.by = "sample", group.by = "sample", raster = FALSE) + ggplot2::xlab("Sample")
1717
ggplot2::ggsave(paste0(output_dir, "pre-filtered_nCount_violin_plots.png"), plot = p, device = "png", width = 10, height = 10, units = "in")
18-
p <- Seurat::VlnPlot(sc_obj, features = c("percent.mt"), split.by = "sample", group.by = "sample", raster = FALSE)
18+
p <- Seurat::VlnPlot(sc_obj, features = c("percent.mt"), split.by = "sample", group.by = "sample", raster = FALSE) + ggplot2::xlab("Sample")
1919
ggplot2::ggsave(paste0(output_dir, "pre-filtered_percentMT_violin_plots.png"), plot = p, device = "png", width = 10, height = 10, units = "in")
20-
p <- Seurat::VlnPlot(sc_obj, features = c("percent.hb"), split.by = "sample", group.by = "sample", raster = FALSE)
20+
p <- Seurat::VlnPlot(sc_obj, features = c("percent.hb"), split.by = "sample", group.by = "sample", raster = FALSE) + ggplot2::xlab("Sample")
2121
ggplot2::ggsave(paste0(output_dir, "pre-filtered_percentHB_violin_plots.png"), plot = p, device = "png", width = 10, height = 10, units = "in")
22-
p <- Seurat::VlnPlot(sc_obj, features = c("percent.rp"), split.by = "sample", group.by = "sample", raster = FALSE)
22+
p <- Seurat::VlnPlot(sc_obj, features = c("percent.rp"), split.by = "sample", group.by = "sample", raster = FALSE) + ggplot2::xlab("Sample")
2323
ggplot2::ggsave(paste0(output_dir, "pre-filtered_percentRP_violin_plots.png"), plot = p, device = "png", width = 10, height = 10, units = "in")
2424
# Create nCount vs nFeature scatter plot for each sample
2525
individual_samples <- Seurat::SplitObject(sc_obj, split.by = "sample")
@@ -59,13 +59,13 @@ Create_QC_Output_Prefiltered_ATAC <- function(proj, output_dir = getwd(), log_fl
5959
print_SPEEDI("Printing QC plots on pre-filtered data (ATAC)", log_flag)
6060
# Plot out TSS Enrichment / Doublet Enrichment / Nucleosome Ratio for each sample to help us decide filtering thresholds
6161
p1 <- ArchR::plotGroups(ArchRProj = proj, groupBy = "Sample", colorBy = "cellColData", name = "TSSEnrichment", plotAs = "ridges") +
62-
ggplot2::ggtitle(paste0("TSS Enrichment \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=22))
62+
ggplot2::ggtitle(paste0("TSS Enrichment\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), axis.text=ggplot2::element_text(size=10), axis.title=ggplot2::element_text(size=14))
6363
ggplot2::ggsave(filename = paste0(output_dir, "pre-filtered_TSSEnrichment.png"), plot = p1, device = "png", width = 8, height = 8, units = "in")
6464
p2 <- ArchR::plotGroups(ArchRProj = proj, groupBy = "Sample", colorBy = "cellColData", name = "DoubletEnrichment", plotAs = "ridges") +
65-
ggplot2::ggtitle(paste0("Doublet Enrichment \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=22))
65+
ggplot2::ggtitle(paste0("Doublet Enrichment\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), axis.text=ggplot2::element_text(size=10), axis.title=ggplot2::element_text(size=14))
6666
ggplot2::ggsave(filename = paste0(output_dir, "pre-filtered_DoubletEnrichment.png"), plot = p2, device = "png", width = 8, height = 8, units = "in")
6767
p3 <- ArchR::plotGroups(ArchRProj = proj, groupBy = "Sample", colorBy = "cellColData", name = "NucleosomeRatio", plotAs = "ridges") +
68-
ggplot2::ggtitle(paste0("Nucleosome Ratio \n ", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=22))
68+
ggplot2::ggtitle(paste0("Nucleosome Ratio\n", sample_text)) + ggplot2::theme(plot.title = ggplot2::element_text(size=18), axis.text=ggplot2::element_text(size=10), axis.title=ggplot2::element_text(size=14))
6969
ggplot2::ggsave(filename = paste0(output_dir, "pre-filtered_NucleosomeRatio.png"), plot = p3, device = "png", width = 8, height = 8, units = "in")
7070
ArchR::plotPDF(p1,p2,p3, name = "pre-filtered_QC_metrics_plots", ArchRProj = proj, addDOC = FALSE, width = 7, height = 5)
7171
gc()

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ print_heatmap_cell_type_proportions_RNA <- function(sc_obj, file_name, output_di
234234
sample_count <- length(unique(sc_obj$sample))
235235
cell_count <- length(sc_obj$cell_name)
236236
output.plot <- pheatmap::pheatmap(voting_cell_type_proportion, cluster_rows = FALSE, cluster_cols = FALSE, display_numbers = TRUE, number_format = "%.3f", legend = FALSE) +
237-
ggplot2::ggtitle(paste0("Cell Type Proportions \n Integrated RNA Data \n (", sample_count, " Samples, ", cell_count, " Cells)")) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
237+
ggplot2::ggtitle(paste0("RNA Data Integration\n(Cell Type Proportions)\n(", sample_count, " Samples, ", cell_count, " Cells)")) + ggplot2::theme(plot.title = ggplot2::element_text(size=18))
238238
ggplot2::ggsave(filename = paste0(output_dir, file_name), plot = output.plot, device = "png", width = 8, height = 8, units = "in")
239239
return(TRUE)
240240
}

0 commit comments

Comments
 (0)