-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonoclePCA.R
More file actions
126 lines (113 loc) · 3.01 KB
/
MonoclePCA.R
File metadata and controls
126 lines (113 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Author: Benben Miao
# Email: [email protected]
# Rversion: 4.2.2
# Date: 2023-02-13
# -> 0. Install and Library
# install.packages(c("ggplot2", "ggsci"))
# BiocManager::install(c('BiocGenerics', 'DelayedArray', 'DelayedMatrixStats',
# 'limma', 'lme4', 'S4Vectors', 'SingleCellExperiment',
# 'SummarizedExperiment', 'batchelor', 'HDF5Array',
# 'terra', 'ggrastr'), force = TRUE)
# remotes::install_github("cole-trapnell-lab/monocle3", dependencies = TRUE)
library(monocle3)
library(ggplot2)
library(dplyr)
# <- 0. Install and Library
options(warn = 1)
# -> 1. File Read
# file_path = "data/SeuratMatrix/Cell1000xGene1000.txt"
# file_format = "txt"
# # "xlsx", "xls", "txt", "csv"
#
# if (file_format == "xlsx" | file_format == "xls") {
# data <- readxl::read_excel(path = file_path,
# sheet = NULL,
# col_names = TRUE,
# na = "",
# progress = readxl::readxl_progress()
# )
# } else if (file_format == "txt" | file_format == "csv") {
# data <- read.table(file = file_path,
# header = TRUE,
# sep = "\t",
# stringsAsFactors = F,
# row.names = 1
# )
# } else if (file_format == "csv") {
# data <- read.table(file = file_path,
# header = TRUE,
# sep = ",",
# stringsAsFactors = F
# )
# }
# <- 1. File Read
# -> 2. Data Operation
# <- 2. Data Operation
# -> 3. Plot Parameters
fonts <- "Times"
# ChoiceBox: "Times", "Palatino", "Bookman", "Courier", "Helvetica", "URWGothic", "NimbusMon", "NimbusSan"
cellRangerMatrixPath <- "./data/CellRanger3Matrix/"
# TextArea:
numPCs <- 50
# Slider: 50, 2, 200, 1
normMethod <- "log"
# ChoiceBox: "log", "size_only"
# <- 3. Plot Parameters
# # -> 4. Plot
cds <- load_mm_data(mat_path = paste(cellRangerMatrixPath, "matrix.mtx.gz", sep = ""),
feature_anno_path = paste(cellRangerMatrixPath, "features.tsv.gz", sep = ""),
cell_anno_path = paste(cellRangerMatrixPath, "barcodes.tsv.gz", sep = "")
)
cds <- preprocess_cds(cds,
method = "PCA", # "PCA", "LSI"
num_dim = numPCs,
norm_method = normMethod, # "log", "size_only", "none"
use_genes = NULL,
pseudo_count = NULL,
scaling = TRUE,
verbose = FALSE,
build_nn_index = FALSE,
nn_control = list()
)
plot <- plot_pc_variance_explained(cds) +
geom_point(size = 3, color = "red", alpha = 0.80) +
theme_light()
# # <- 4. Plot
# -> 5. Save parameters
pdf_name = "results.pdf"
jpeg_name = "results.jpeg"
device_pdf = "pdf"
device_jpeg = "jpeg"
# "pdf", "jpeg", "tiff", "png", "bmp", "svg"
width = 10.00
height = 6.18
units = "in"
# "in", "cm", "mm", "px"
dpi <- 300
# <- 5. Save parameters
# -> 6. Save image
ggsave(
filename = pdf_name,
plot = plot,
device = device_pdf,
path = NULL,
scale = 1,
width = width,
height = height,
units = units,
dpi = dpi,
limitsize = TRUE
)
ggsave(
filename = jpeg_name,
plot = plot,
device = device_jpeg,
path = NULL,
scale = 1,
width = width,
height = height,
units = units,
dpi = dpi,
limitsize = TRUE
)
# <- 6. Save image