-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-analysis.R
155 lines (110 loc) · 3.17 KB
/
run-analysis.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
# #####################
# General configuration
# #####################
# Set the base directory
baseDir <- getwd()
# Define which experiment(s) should be analyzed
experiments = c(1, 2)
# Define which min logFC values should be analyzed
logFC_values <- c(2,4)
# Define which p values should be considered
p_values <- c(0.05)
# Define the degree for the polynomial fit
polyDegree <- 3
# Define name of negative control treatment
treat_NC <- 'NC'
# Define the graphics dimensions
graphics_dimensions <- c(1200, 700)
# Create a folder for graphics
graphicsDir <- paste0(baseDir, '/graphics')
if (!dir.exists(graphicsDir)) {
dir.create(graphicsDir)
}
# Create a folder for results
resultsDir <- paste0(baseDir, '/results')
if (!dir.exists(resultsDir)) {
dir.create(resultsDir)
}
# Targets file
targetsFile <- 'Targets.tsv'
# Prevent scientific notation
options(scipen = 99)
# ########
# Packages
# ########
# Install the Bioconductor Manager
if (!require('BiocManager', quietly = TRUE))
install.packages('BiocManager')
# Install Bioconductor Packages
BiocManager::install('limma', update = TRUE, ask = FALSE, force = TRUE, checkBuilt = TRUE)
require(limma)
# Load R packages
require(statmod)
require(stringr)
require(gplots)
require(tidyr)
require(dplyr)
require(VennDiagram)
# #########
# Functions
# #########
# Define a function to print to the log file
print_to_log <- function(...) {
tmp_arguments <- list(...)
tmp_string <- ''
for (tmp_argument in tmp_arguments) {
tmp_string <- paste0(tmp_string, tmp_argument)
}
cat(paste0(Sys.time(), ': ', tmp_string), fill = TRUE)
}
# ##################################
# Read or create the annotation file
# ##################################
# Create a folder for annotation files
annotationDir <- paste0(baseDir, '/annotation-files')
if (!dir.exists(annotationDir)) {
dir.create(annotationDir)
}
setwd(annotationDir)
tryCatch(
expr = {
currentMonth <- format(Sys.Date(), format = '%Y-%m')
annotationFile <- paste0(
'Human_agilent_sureprint_g3_ge_8x60k_v2_',
gsub('-', '_', as.character(currentMonth)),
'.tsv'
)
if (!file.exists(annotationFile)) {
source(paste0(baseDir, '/', '_annotation-file-generator.R'), local = TRUE)
}
},
finally = {
setwd(baseDir)
}
)
# ################
# Run the Analysis
# ################
dim_eset <- list()
for (experiment in experiments) {
graphicsDirExp <- paste0(graphicsDir, '/exp_', experiment)
if (dir.exists(graphicsDirExp)) {
unlink(graphicsDirExp, recursive = TRUE)
}
dir.create(graphicsDirExp)
dir.create(paste0(graphicsDirExp, '/data-processing'))
resultsDirExp <- paste0(resultsDir, '/exp_', experiment)
if (dir.exists(resultsDirExp)) {
unlink(resultsDirExp, recursive = TRUE)
}
dir.create(resultsDirExp)
# Capture the output to a log file
sink(file = paste0(resultsDirExp, '/log.txt'), append = TRUE, type = c('output', 'message'), split = TRUE)
source(paste0(baseDir, '/', '_analysis-script.R'), local = TRUE)
# Remove tmp variables
rm(list = ls(pattern = '^tmp_'))
# End the output capture
sink(file = NULL, split = FALSE)
# Close all connections
closeAllConnections()
}