forked from chunjie-sam-liu/qc-wdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readlength.R
111 lines (79 loc) · 2.46 KB
/
readlength.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
# Metainfo ----------------------------------------------------------------
# @AUTHOR: Chun-Jie Liu
# @CONTACT: chunjie.sam.liu.at.gmail.com
# @DATE: Wed Jul 27 15:37:31 2022
# @DESCRIPTION: filename
# Library -----------------------------------------------------------------
library(magrittr)
library(ggplot2)
library(patchwork)
library(rlang)
# datadir -----------------------------------------------------------------
datadir="/scr1/users/liuc9/bam-qc"
# Function ----------------------------------------------------------------
fn_loaddata <- function(.x) {
# .x <- fastqcdatas[[1]]
aname <- strsplit(
x = .x,
split = "/"
)[[1]]
tissue <- aname[[6]]
samplename <- strsplit(x = aname[[7]], split = "\\.")[[1]][[1]]
d <- readr::read_lines(file = .x, num_threads =2)
start <- which(grepl("#Length\tCount", d)) + 1
m <- which(grepl(">>END_MODULE", d))
end <- m[which(m - start > 0)[[1]]] - 1
tibble::tibble(
a = d[c(start:end)]
) %>%
tidyr::separate(col = a, into = c("readlength", "count"), sep = "\t") %>%
dplyr::mutate_all(.funs = as.numeric) ->
lengthdist
lengthdist %>%
dplyr::arrange(-count) %>%
dplyr::slice(1) %>%
dplyr::pull(1) ->
readlengthmode
readlength <- gsub(pattern = "Sequence length\t", replacement = "", x = d[[9]])
tibble::tibble(
tissue = tissue,
samplename = samplename,
readlength = readlength,
readlengthmode = readlengthmode,
readlengthdist = list(lengthdist)
)
}
fastqcdatas <- list.files(
path = datadir,
pattern = "fastqc_data.txt",
all.files =TRUE,
full.names = TRUE,
recursive = TRUE
)
# fastqcdatas %>%
# purrr::map(
# .f = fn_loaddata
# ) %>%
# dplyr::bind_rows() ->
length(fastqcdatas)
parallelMap::parallelStartSocket(25)
parallelMap::parallelLibrary("magrittr")
fastqcdatas_loaded <- parallelMap::parallelMap(fn_loaddata, fastqcdatas)
parallelMap::parallelStop()
# merge data --------------------------------------------------------------
fastqcdatas_loaded %>%
dplyr::bind_rows() ->
readlength_dist
readlength_dist %>%
dplyr::group_by(readlength) %>%
dplyr::count()
readlength_dist %>%
dplyr::filter(readlengthmode == 101)
readlength_dist %>%
dplyr::group_by(readlength) %>%
dplyr::count()
readlength_dist %>%
dplyr::group_by(readlengthmode) %>%
dplyr::count()
# save image --------------------------------------------------------------
save.image(file = "data/readlength.rda")