Skip to content

Instantly share code, notes, and snippets.

@GuangchuangYu
Last active January 9, 2018 04:58
Show Gist options
  • Save GuangchuangYu/b331b39fc1207c091f9b76e308cffa96 to your computer and use it in GitHub Desktop.
Save GuangchuangYu/b331b39fc1207c091f9b76e308cffa96 to your computer and use it in GitHub Desktop.
qbar <- function(x, verbose=TRUE) {
enc = encoding(quality(x))
qual <- sapply(seq_along(x), function(i) enc[to_char_vector(x[i])])
mq <- rowMeans(qual)
if (verbose) {
names(mq) <- NULL
print(mq)
}
pillar:::spark_bar(mq/max(enc))
}
to_char_vector <- function(x) {
toString(x@quality@quality) %>% strsplit(split='') %>% unlist
}
require(ShortRead)
x <- readFastq(system.file('extdata/E-MTAB-1147/ERR127302_1_subset.fastq.gz', package='ShortRead'))
qbar(x[1:50])
@GuangchuangYu
Copy link
Author

> require(ShortRead)
> x <- readFastq(system.file('extdata/E-MTAB-1147/ERR127302_1_subset.fastq.gz', package='ShortRead'))
>
> qbar(x[1:50])
 [1] 38.76 38.42 38.36 37.92 37.78 38.20 37.92 38.56 38.28 38.22 37.98 38.08
[13] 38.12 37.94 38.12 38.34 37.86 37.96 38.26 37.98 37.12 36.36 36.70 36.28
[25] 36.92 36.98 36.78 37.04 36.44 36.66 36.44 36.44 36.36 36.46 36.90 35.86
[37] 36.30 36.22 35.76 36.14 35.60 35.70 34.88 34.34 35.28 35.82 35.46 34.70
[49] 34.52 34.08 33.74 33.88 33.24 34.16 33.38 33.44 32.44 34.00 32.86 33.88
[61] 33.72 33.48 33.12 32.98 31.32 32.00 32.58 30.82 31.12 29.62 29.28 27.76
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment