This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharONT_preprocessing.R
385 lines (341 loc) · 21.8 KB
/
CharONT_preprocessing.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
#
# Copyright 2021 Simone Maestri. All rights reserved.
# Simone Maestri <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
args = commandArgs(trailingOnly=TRUE)
config_file_ind <- grep(x = args, pattern = "\\.R")
raw_reads_ind <- setdiff(c(1, 2), config_file_ind)
config_file <- args[config_file_ind]
d1_tmp <- args[raw_reads_ind]
#load variables
source(config_file)
if (!exists("do_subsampling_flag")) {
do_subsampling_flag <- 0
}
if (!exists("num_fast5_files")) {
num_fast5_files <- 25
}
if (!exists("gpu_basecalling_flag") || pair_strands_flag_cpu == 1) {
gpu_basecalling_flag <- 0
}
if (!exists("fast_basecalling_flag_cpu") || flowcell == "FLO-MIN107") {
fast_basecalling_flag_cpu <- 0
}
if (!exists("require_two_barcodes_flag")) {
require_two_barcodes_flag <- 0
}
if (!exists("pair_strands_flag_cpu") || flowcell != "FLO-MIN107") {
pair_strands_flag_cpu <- 0
}
if (!exists("min_qual")) {
min_qual <- 7
}
if (!exists("min_seq_length")) {
min_seq_length <- 0
}
if (!exists("do_in_silico_pcr")) {
do_in_silico_pcr <- 0
}
if (!exists("pcr_id_thr")) {
pcr_id_thr <- 0.8
}
if (do_subsampling_flag == 1) {
#d2 is the directory which is going to include processed reads
d2 <- paste0(dirname(d1_tmp), "/", basename(d1_tmp), "_", num_fast5_files, "_subsampled_fast5_files_analysis")
} else {
d2 <- paste0(dirname(d1_tmp), "/", basename(d1_tmp), "_analysis")
}
d2_basecalling <- paste0(d2, "/basecalling")
d2_preprocessing <- paste0(d2, "/preprocessing")
#d3 is the directory which is going to include results
d3 <- paste0(d2, "/analysis")
#logfile is the file which is going to include the log
logfile <- paste0(d3, "/logfile.txt")
if (!exists("save_space_flag")) {
save_space_flag <- 0
}
if (!exists("skip_demultiplexing_flag")) {
skip_demultiplexing_flag <- 1
BC_int <- "BC01"
}
if (pair_strands_flag_cpu == 1) {
basecaller <- paste0(BASECALLER_DIR, "/guppy_basecaller")
basecaller_1d2 <- paste0(BASECALLER_DIR, "/guppy_basecaller_1d2")
} else {
basecaller <- paste0(BASECALLER_DIR, "/guppy_basecaller")
}
demultiplexer <- paste0(BASECALLER_DIR, "/guppy_barcoder")
basecaller_version <- system(paste0(basecaller, " --version"), intern = TRUE)[1]
if (!dir.exists(d2)) {
dir.create(d2)
}
if (!dir.exists(d3)) {
dir.create(d3)
}
cat(text = "Welcome to CharONT preprocessing pipeline!", file = logfile, sep = "\n", append = TRUE)
cat(text = "Welcome to CharONT preprocessing pipeline!", sep = "\n")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
if (do_subsampling_flag == 1) {
cat(text = paste0("Subsampling ", num_fast5_files, " fast5 files from directory ", d1_tmp), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Subsampling ", num_fast5_files, " fast5 files from directory ", d1_tmp), sep = "\n")
system(command = paste0(subsample_fast5, " ", d1_tmp, " ", num_fast5_files))
d1 <- paste0(gsub("\\/$", "", d1_tmp), "_", num_fast5_files, "_subsampled_fast5_files")
} else {
d1 <- d1_tmp
}
cat(text = paste0("Raw reads directory: ", d1), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Raw reads directory: ", d1), sep = "\n")
cat(text = paste0("Basecalled reads directory: ", d2_basecalling), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Basecalled reads directory: ", d2_basecalling), sep = "\n")
cat(text = paste0("Preprocessing directory: ", d2_preprocessing), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Preprocessing directory: ", d2_preprocessing), sep = "\n")
cat(text = paste0("Analysis and results directory: ", d3), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Analysis and results directory: ", d3), sep = "\n")
cat(text = paste0("Flow-cell: ", flowcell), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Flow-cell: ", flowcell), sep = "\n")
cat(text = paste0("Kit: ", kit), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Kit: ", kit), sep = "\n")
if (skip_demultiplexing_flag != 1) {
cat(text = paste0("Barcodes used in this experiment: ", paste0(BC_int, collapse = ", ")), file = logfile, sep = ", ", append = TRUE)
cat(text = paste0("Barcodes used in this experiment: ", paste0(BC_int, collapse = ", ")), sep = ", ")
}
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
cat(text = paste0("Basecalling is going to be performed by ", basecaller_version), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Basecalling is going to be performed by ", basecaller_version), sep = "\n")
if (fast_basecalling_flag_cpu == 1) {
cat(text = "Basecalling model: fast", file = logfile, sep = "\n", append = TRUE)
cat(text = "Basecalling model: fast", sep = "\n")
} else if (fast_basecalling_flag_cpu != 1 || gpu_basecalling_flag == 1) {
cat(text = "Basecalling model: high-accuracy", file = logfile, sep = "\n", append = TRUE)
cat(text = "Basecalling model: high-accuracy", sep = "\n")
}
if (skip_demultiplexing_flag == 1) {
cat(text = paste0("Demultiplexing is not going to be performed; the sample will be renamed BC01"), file = logfile, sep = ", ", append = TRUE)
cat(text = paste0("Demultiplexing is not going to be performed; the sample will be renamed BC01"), sep = ", ")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
} else {
if (require_two_barcodes_flag == 1) {
cat(text = paste0("Demultiplexing is going to be performed by guppy_barcoder after basecalling, keeping only reads with barcodes at both ends of the read"), file = logfile, sep = ", ", append = TRUE)
cat(text = paste0("Demultiplexing is going to be performed by guppy_barcoder after basecalling, keeping only reads with barcodes at both ends of the read"), sep = ", ")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
} else {
cat(text = paste0("Demultiplexing is going to be performed by guppy_barcoder after basecalling"), file = logfile, sep = ", ", append = TRUE)
cat(text = paste0("Demultiplexing is going to be performed by guppy_barcoder after basecalling"), sep = ", ")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
}
}
if (do_in_silico_pcr == 1) {
cat(text = paste0("In-silico PCR will be performed using primers ", pcr_silico_primer_one, " and ", pcr_silico_primer_two), file = logfile, sep = ", ", append = TRUE)
cat(text = paste0("In-silico PCR will be performed using primers ", pcr_silico_primer_one, " and ", pcr_silico_primer_two), sep = ", ")
}
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
BC_tot <- c("BC01", "BC02", "BC03", "BC04", "BC05", "BC06", "BC07", "BC08", "BC09", "BC10", "BC11", "BC12")
BC_tot_full <- c(BC_tot, paste0("BC", 13:99))
BC_trash <- setdiff(BC_tot_full, BC_int)
BC_trash <- paste0("^", BC_trash)
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
if (!dir.exists(d2_basecalling)) {
dir.create(d2_basecalling)
cat(text = paste0("Basecalling started at ", date()), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Basecalling started at ", date()), sep = "\n")
num_threads_caller <- round(num_threads/4)
if (gpu_basecalling_flag == 1) {
system(paste0(basecaller, " -r -i ", d1, " -s ", d2_basecalling, " ", conf_par_gpu, " --disable_pings"))
} else {
if (fast_basecalling_flag_cpu == 1) {
system(paste0(basecaller, " -r -i ", d1, " --cpu_threads_per_caller ", num_threads_caller, " --num_callers 4", " -c dna_r9.4.1_450bps_fast.cfg -s ", d2_basecalling, " --disable_pings"))
} else {
system(paste0(basecaller, " -r -i ", d1, " --cpu_threads_per_caller ", num_threads_caller, " --num_callers 4", " --flowcell ", flowcell, " --kit ", kit, " -s ", d2_basecalling, " --disable_pings"))
}
}
if (gpu_basecalling_flag !=1 && pair_strands_flag_cpu == 1) {
system(paste0(basecaller, " -r -i ", d1, " --cpu_threads_per_caller ", num_threads_caller, " --num_callers 4", " --flowcell ", flowcell, " --kit ", kit, " --fast5_out -s ", d2_basecalling, " --disable_pings"))
system(paste0(basecaller_1d2, " -r -i ", d2_basecalling, "/workspace --cpu_threads_per_caller ", num_threads_caller, " --num_callers 4", " --config dna_r9.5_450bps_1d2_raw.cfg -f ", d2_basecalling, "/sequencing_summary.txt -s ", d2, "/basecalling_1d2 --disable_pings"))
d2_basecalling <- paste0(d2, "/basecalling_1d2")
}
cat(text = paste0("Basecalling finished at ", date()), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Basecalling finished at ", date()), sep = "\n")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
}
if (!dir.exists(d2_preprocessing)) {
dir.create(d2_preprocessing)
if (skip_demultiplexing_flag == 1) {
fastq_files <- list.files(path = d2_basecalling, pattern = ".*\\.fastq", full.names = TRUE, recursive = TRUE)
num_reads_tot <- 0
for (i in 1:length(fastq_files)) {
num_reads_tot <- num_reads_tot + length(grep(x = readLines(fastq_files[i]), pattern = "^\\+$"))
}
system(paste0("cat ", paste0(fastq_files, collapse = " "), " > ", d2_preprocessing, "/BC01_tmp1.fastq"))
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
} else {
cat(text = paste0("Demultiplexing started at ", date()), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Demultiplexing started at ", date()), sep = "\n")
if (require_two_barcodes_flag == 1) {
system(paste0(demultiplexer, " -r -i ", d2_basecalling, " -t ", num_threads, " -s ", d2_preprocessing, " --enable_trim_barcodes --require_barcodes_both_ends --barcode_kits \"", paste0(barcode_kits, collapse = " "), "\""))
} else {
system(paste0(demultiplexer, " -r -i ", d2_basecalling, " -t ", num_threads, " -s ", d2_preprocessing, " --enable_trim_barcodes --barcode_kits \"", paste0(barcode_kits, collapse = " "), "\""))
}
cat(text = paste0("Demultiplexing finished at ", date()), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Demultiplexing finished at ", date()), sep = "\n")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
fastq_files <- list.files(path = d2_preprocessing, pattern = ".*\\.fastq", full.names = TRUE, recursive = TRUE)
num_reads_tot <- 0
for (i in 1:length(fastq_files)) {
num_reads_tot <- num_reads_tot + length(grep(x = readLines(fastq_files[i]), pattern = "^\\+$"))
}
barcode_dirs <- grep(x = list.dirs(d2_preprocessing), pattern = paste0("barcode", substr(x = BC_int, start = 3, stop = 5), collapse = "|"), value = TRUE)
for (i in 1:length(barcode_dirs)) {
fastq_files_curr_barcode <- list.files(path = barcode_dirs[i], pattern = ".*\\.fastq", full.names = TRUE)
system(paste0("cat ", paste0(fastq_files_curr_barcode, collapse = " "), " > ", d2_preprocessing, "/BC", substr(x = basename(barcode_dirs[i]), start = 8, stop = 9), "_tmp1.fastq"))
}
}
cat(text = paste0("Number of basecalled reads: ", num_reads_tot), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Number of basecalled reads: ", num_reads_tot), sep = "\n")
cat(text = "", file = logfile, sep = "\n", append = TRUE)
cat(text = "", sep = "\n")
if (!dir.exists(paste0(d2, "/qc"))) {
dir.create(paste0(d2, "/qc"))
cat(text = paste0("Creating folder: ", d2, "/qc, which is going to include stats about the sequencing run"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Creating folder: ", d2, "/qc, which is going to include stats about the sequencing run"), sep = "\n")
cat(text = "", file = logfile, sep = "\n", append = TRUE)
cat(text = "", sep = "\n")
cat(text = "Now performing quality control with PycoQC", file = logfile, sep = "\n", append = TRUE)
cat(text = "Now performing quality control with PycoQC", sep = "\n")
cat(text = "", file = logfile, sep = "\n", append = TRUE)
cat(text = "", sep = "\n")
if (skip_demultiplexing_flag == 1) {
system(paste0(PYCOQC, " -f ", d2_basecalling, "/sequencing_summary.txt -o ", d2, "/qc/pycoQC_report.html --min_pass_qual ", min_qual))
} else {
if (pair_strands_flag_cpu == 1) {
system(paste0(PYCOQC, " -f ", d2_basecalling, "/sequencing_summary.txt -b ", d2_preprocessing, "/barcoding_summary.txt -o ", d2, "/qc/pycoQC_report.html --min_pass_qual ", min_qual))
} else {
system(paste0(PYCOQC, " -f ", d2_basecalling, "/sequencing_summary.txt -b ", d2_preprocessing, "/barcoding_summary.txt -o ", d2, "/qc/pycoQC_report.html --min_pass_qual ", min_qual))
}
}
}
demu_files <- list.files(path = d2_preprocessing, pattern = "BC", full.names = TRUE)
for (i in 1:length(demu_files)) {
BC_val_curr <- substr(x = basename(demu_files[i]), start = 3, stop = 4)
if (paste0("BC", BC_val_curr) %in% BC_int) {
fastq_file_curr <- list.files(path = paste0(d2_preprocessing), pattern = paste0("BC", BC_val_curr, "_tmp1\\.fastq"), full.names = TRUE)
if (length(fastq_file_curr) == 0) {
BC_int <- setdiff(BC_int, paste0("BC", BC_val_curr))
BC_trash <- c(BC_trash, paste0("BC", BC_val_curr))
next
}
system(paste0(SEQTK, " seq -A ", d2_preprocessing, "/BC", BC_val_curr, "_tmp1.fastq > ", d2_preprocessing, "/BC", BC_val_curr, "_tmp1.fasta"))
sequences <- readDNAStringSet(paste0(d2_preprocessing, "/BC", BC_val_curr, "_tmp1.fasta"), "fasta")
ws <- width(sequences)
read_length <- ws
cat(text = paste0("Mean read length (stdev) for sample BC", BC_val_curr, ": ", sprintf("%.0f", mean(ws)), " (", sprintf("%.0f", sd(ws)), ")"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Mean read length (stdev) for sample BC", BC_val_curr, ": ", sprintf("%.0f", mean(ws)), " (", sprintf("%.0f", sd(ws)), ")"), sep = "\n")
if (do_in_silico_pcr == 1) {
cat(text = paste0("Now filtering out reads with quality lower than ", min_qual, " for sample BC", BC_val_curr), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Now filtering out reads with quality lower than ", min_qual, " for sample BC", BC_val_curr), sep = "\n")
system(paste0("cat ", d2_preprocessing, "/BC", BC_val_curr, "_tmp1.fastq | ", NANOFILT, " -q ", min_qual, " --logfile ", d2_preprocessing, "/BC", BC_val_curr, "_NanoFilt.log > ", d2_preprocessing, "/BC", BC_val_curr, "_tmp2.fastq"))
system(paste0(SEQTK, " seq -A ", d2_preprocessing, "/BC", BC_val_curr, "_tmp2.fastq > ", d2_preprocessing, "/BC", BC_val_curr, "_tmp2.fasta"))
in_silico_pcr_sam_one <- paste0(d2_preprocessing, "/BC", BC_val_curr, "_pcr_primer_one.sam")
in_silico_pcr_sam_two <- paste0(d2_preprocessing, "/BC", BC_val_curr, "_pcr_primer_two.sam")
cat(text = paste0("Looking for pcr_silico_primer_one for sample BC", BC_val_curr), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Looking for pcr_silico_primer_one for sample BC", BC_val_curr), sep = "\n")
system(paste0(MSA, " in=", d2_preprocessing, "/BC", BC_val_curr, "_tmp2.fastq out=", in_silico_pcr_sam_one, " literal=", pcr_silico_primer_one, " qin=33 cutoff=", pcr_id_thr))
cat(text = paste0("Looking for pcr_silico_primer_two for sample BC", BC_val_curr), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Looking for pcr_silico_primer_two for sample BC", BC_val_curr), sep = "\n")
system(paste0(MSA, " in=", d2_preprocessing, "/BC", BC_val_curr, "_tmp2.fastq out=", in_silico_pcr_sam_two, " literal=", pcr_silico_primer_two, " qin=33 cutoff=", pcr_id_thr))
cat(text = paste0("Extracting in-silico PCR products for sample BC", BC_val_curr), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Extracting in-silico PCR products for sample BC", BC_val_curr), sep = "\n")
system(paste0(CUTPRIMERS, " in=", d2_preprocessing, "/BC", BC_val_curr, "_tmp2.fastq out=", d2_preprocessing, "/BC", BC_val_curr, "_tmp3.fastq sam1=", in_silico_pcr_sam_one, " sam2=", in_silico_pcr_sam_two, " qin=33 fake=f include=t fixjunk"))
cat(text = paste0("Now filtering out in-silico PCR products shorter than ", min_seq_length, " bp for sample BC", BC_val_curr), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Now filtering out in-silico PCR products shorter than ", min_seq_length, " bp for sample BC", BC_val_curr), sep = "\n")
system(paste0("cat ", d2_preprocessing, "/BC", BC_val_curr, "_tmp3.fastq | ", NANOFILT, " -l ", min_seq_length, " --logfile ", d2_preprocessing, "/BC", BC_val_curr, "_NanoFilt.log > ", d3, "/BC", BC_val_curr, ".fastq"))
cat(text = "\n", file = logfile, append = TRUE)
} else {
cat(text = paste0("Now filtering out reads shorter than ", min_seq_length, " bp and with quality lower than ", min_qual, " for sample BC", BC_val_curr), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Now filtering out reads shorter than ", min_seq_length, " bp and with quality lower than ", min_qual, " for sample BC", BC_val_curr), sep = "\n")
system(paste0("cat ", d2_preprocessing, "/BC", BC_val_curr, "_tmp1.fastq | ", NANOFILT, " -l ", min_seq_length, " -q ", min_qual, " --logfile ", d2_preprocessing, "/BC", BC_val_curr, "_NanoFilt.log > ", d3, "/BC", BC_val_curr, ".fastq"))
}
system(paste0(SEQTK, " seq -A ", d3, "/BC", BC_val_curr, ".fastq > ", d3, "/BC", BC_val_curr, ".fasta"))
sequences_pass <- readDNAStringSet(paste0(d3, "/BC", BC_val_curr, ".fasta"), "fasta")
ws_pass <- width(sequences_pass)
read_length_pass <- ws_pass
if (length(grep(x = readLines(paste0( d3, "/BC", BC_val_curr, ".fasta")), pattern = "^>")) < 1) {
cat(text = paste0("WARNING: skipping sample BC", BC_val_curr, ", since no reads survived the quality filtering!"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("WARNING: skipping sample BC", BC_val_curr, ", since no reads survived the quality filtering!"), sep = "\n")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
system(paste0("rm ", d3, "/BC", BC_val_curr, ".fastq"))
system(paste0("rm ", d3, "/BC", BC_val_curr, ".fasta"))
next
}
cat(text = paste0("Mean read length for sample BC", BC_val_curr, " after quality filtering: ", sprintf("%.0f", mean(ws_pass)), " (", sprintf("%.0f", sd(ws_pass)), ")"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Mean read length for sample BC", BC_val_curr, " after quality filtering: ", sprintf("%.0f", mean(ws_pass)), " (", sprintf("%.0f", sd(ws_pass)), ")"), sep = "\n")
png(paste0(d2, "/qc/hist_BC", BC_val_curr, "_unfiltered.png"))
hist(read_length, main = paste("Read length before quality filtering - sample BC", BC_val_curr), col = "blue", breaks = 100, xlab = "Read length", ylab = "Number of reads")
dev.off()
png(paste0(d2, "/qc/hist_BC", BC_val_curr, ".png"))
hist(read_length_pass, main = paste("Read length after quality filtering - sample BC", BC_val_curr), col = "blue", breaks = 100, xlab = "Read length", ylab = "Number of reads")
dev.off()
cat(text = "\n", file = logfile, append = TRUE)
}
}
}
BC_files_bn <- list.files(path = d3, pattern = "^BC\\d+\\.fasta$")
BC_files_bn_fq <- list.files(path = d3, pattern = "^BC\\d+\\.fastq$")
BC_files <- paste0(d3, "/", BC_files_bn)
BC_files_fq <- paste0(d3, "/", BC_files_bn_fq)
num_reads_BC_int <- 0
num_reads_vec <- vector(length = length(BC_files))
for (i in 1:length(BC_files)) {
num_reads_vec[i] <- length(grep(x = readLines(BC_files[i]), pattern = "^>"))
cat(text = paste0("Number of reads assigned to ", gsub("\\.fasta$", "", basename(BC_files_bn[i])), ": ", num_reads_vec[i]), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Number of reads assigned to ", gsub("\\.fasta$", "", basename(BC_files_bn[i])), ": ", num_reads_vec[i]), sep = "\n")
num_reads_BC_int <- num_reads_BC_int + num_reads_vec[i]
}
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
cat(text = paste0("Running CharONT pipeline"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Running CharONT pipeline"), sep = "\n")
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
system(paste0("Rscript ", CharONT, " ", d3))
if (save_space_flag == 1) {
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
cat(text = paste0("Deleting ", d2_preprocessing, " directory"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Deleting ", d2_preprocessing, " directory"), sep = "\n")
system(command = paste0("rm -r ", d2_preprocessing))
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
cat(text = paste0("Deleting ", d2_basecalling, " directory"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Deleting ", d2_basecalling, " directory"), sep = "\n")
system(command = paste0("rm -r ", d2_basecalling))
}
cat(text = "\n", file = logfile, append = TRUE)
cat(text = "\n")
cat(text = paste0("Workflow ended at ", date(), "!"), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Workflow ended at ", date(), "!"), sep = "\n")
cat(text = paste0("Look at the results in directory ", d3), file = logfile, sep = "\n", append = TRUE)
cat(text = paste0("Look at the results in directory ", d3), sep = "\n")