Mercurial > repos > jvolkening > nanopore_qc
annotate nanopore_qc.R @ 0:e0006d8bf849 draft
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
author | jvolkening |
---|---|
date | Sat, 02 Mar 2024 03:35:34 +0000 |
parents | |
children |
rev | line source |
---|---|
0
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
1 #!/usr/bin/Rscript |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
2 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
3 # NanoporeQC was forked from: |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
4 # MinionQC version 1.0 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
5 # Copyright (C) 2017 Robert Lanfear |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
6 # |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
7 # Modifications (c) 2018-2024 Jeremy Volkening |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
8 # |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
9 # Released under the MIT license (see LICENSE) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
10 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
11 # supress warnings |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
12 options(warn=-1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
13 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
14 libs <- c( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
15 'ggplot2', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
16 'tidyr', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
17 'dplyr', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
18 'readr', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
19 'yaml', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
20 'scales', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
21 'futile.logger', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
22 'data.table', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
23 'optparse' |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
24 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
25 for (l in libs) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
26 library(l, character.only = T, quietly = T) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
27 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
28 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
29 # option parsing # |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
30 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
31 parser <- OptionParser() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
32 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
33 parser <- add_option(parser, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
34 opt_str = c("-i", "--input"), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
35 type = "character", |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
36 dest = 'input.file', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
37 help="Input file or directory (required). Either a full path to a sequence_summary.txt file, or a full path to a directory containing one or more such files. In the latter case the directory is searched recursively." |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
38 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
39 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
40 parser <- add_option(parser, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
41 opt_str = c("-o", "--outputdirectory"), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
42 type = "character", |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
43 dest = 'output.dir', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
44 help="Output directory (required). If a single sequencing_summary.txt file is passed as input, then the output directory will contain just the plots associated with that file. If a directory containing more than one sequencing_summary.txt files is passed as input, then the plots will be put into sub-directories that have the same names as the parent directories of each sequencing_summary.txt file" |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
45 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
46 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
47 parser <- add_option(parser, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
48 opt_str = c("-q", "--qscore_cutoff"), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
49 type="double", |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
50 default=7.0, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
51 dest = 'q', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
52 help="The cutoff value for the mean Q score of a read (default 7). Used to create separate plots for reads above and below this threshold" |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
53 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
54 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
55 parser <- add_option(parser, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
56 opt_str = c("-d", "--discard_failed"), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
57 type="logical", |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
58 default=FALSE, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
59 dest = 'filt.failed', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
60 help="Discard reads that failed Albacore filtering" |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
61 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
62 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
63 opt = parse_args(parser) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
64 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
65 input.file = opt$input.file |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
66 output.dir = opt$output.dir |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
67 filt.failed = opt$filt.failed |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
68 q = opt$q |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
69 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
70 # this is how we label the reads at least as good as q |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
71 q_title = paste("Q>=", q, sep="") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
72 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
73 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
74 # build the map for R9.5, which has this unusual non-sequential numbering layout |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
75 map <- rbind( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
76 data.frame( channel=33:64, row=rep(1:4, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
77 data.frame( channel=481:512, row=rep(5:8, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
78 data.frame( channel=417:448, row=rep(9:12, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
79 data.frame( channel=353:384, row=rep(13:16, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
80 data.frame( channel=289:320, row=rep(17:20, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
81 data.frame( channel=225:256, row=rep(21:24, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
82 data.frame( channel=161:192, row=rep(25:28, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
83 data.frame( channel=97:128, row=rep(29:32, each=8), col=rep(1:8, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
84 data.frame( channel=1:32, row=rep(1:4, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
85 data.frame( channel=449:480, row=rep(5:8, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
86 data.frame( channel=385:416, row=rep(9:12, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
87 data.frame( channel=321:352, row=rep(13:16, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
88 data.frame( channel=257:288, row=rep(17:20, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
89 data.frame( channel=193:224, row=rep(21:24, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
90 data.frame( channel=129:160, row=rep(25:28, each=8), col=rep(16:9, 4) ), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
91 data.frame( channel=65:96, row=rep(29:32, each=8), col=rep(16:9, 4) ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
92 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
93 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
94 add_cols <- function(d, min.q){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
95 # take a sequencing sumamry file (d), and a minimum Q value you are interested in (min.q) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
96 # return the same data frame with the following columns added |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
97 # cumulative.bases |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
98 # hour of run |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
99 # reads.per.hour |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
100 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
101 d = subset(d, mean_qscore_template >= min.q) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
102 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
103 if(nrow(d)==0){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
104 flog.error(paste("There are no reads with a mean Q score higher than your cutoff of ", min.q, ". Please choose a lower cutoff and try again.", sep = "")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
105 quit() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
106 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
107 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
108 d = merge(d, map, by="channel") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
109 d = d[with(d, order(start_time)), ] # sort by read length |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
110 d$cumulative.bases.time = cumsum(as.numeric(d$start_time)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
111 d = d[with(d, order(-sequence_length_template)), ] # sort by read length |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
112 d$cumulative.bases = cumsum(as.numeric(d$sequence_length_template)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
113 d$hour = d$start_time %/% 3600 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
114 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
115 # add the reads generated for each hour |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
116 reads.per.hour = as.data.frame(table(d$hour)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
117 names(reads.per.hour) = c("hour", "reads_per_hour") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
118 reads.per.hour$hour = as.numeric(as.character(reads.per.hour$hour)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
119 d = merge(d, reads.per.hour, by = c("hour")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
120 return(d) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
121 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
122 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
123 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
124 load_summary <- function(filepath, min.q){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
125 # load a sequencing summary and add some info |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
126 # min.q is a vector of length 2 defining 2 levels of min.q to have |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
127 # by default the lowest value is -Inf, i.e. includes all reads. The |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
128 # other value in min.q is set by the user at the command line |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
129 d = read_tsv( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
130 filepath, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
131 col_types = cols_only( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
132 channel = 'i', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
133 passes_filtering = 'c', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
134 num_events_template = 'i', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
135 sequence_length_template = 'i', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
136 mean_qscore_template = 'n', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
137 sequence_length_2d = 'i', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
138 mean_qscore_2d = 'n', |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
139 start_time = 'n' |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
140 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
141 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
142 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
143 if("sequence_length_2d" %in% names(d)){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
144 # it's a 1D2 or 2D run |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
145 d$sequence_length_template = as.numeric(as.character(d$sequence_length_2d)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
146 d$mean_qscore_template = as.numeric(as.character(d$mean_qscore_2d)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
147 d$num_events_template = NA |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
148 d$start_time = as.numeric(as.character(d$start_time)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
149 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
150 }else{ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
151 d$sequence_length_template = as.numeric(as.character(d$sequence_length_template)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
152 d$mean_qscore_template = as.numeric(as.character(d$mean_qscore_template)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
153 d$num_events_template = as.numeric(as.character(d$num_events_template)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
154 d$start_time = as.numeric(as.character(d$start_time)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
155 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
156 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
157 # ignore 0-length reads |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
158 d <- d[d$sequence_length_template > 0,] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
159 # ignore reads failing filtering |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
160 if (filt.failed) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
161 d <- d[d$passes_filtering == 'True',] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
162 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
163 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
164 d$events_per_base = d$num_events_template/d$sequence_length_template |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
165 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
166 flowcell = basename(dirname(filepath)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
167 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
168 # add columns for all the reads |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
169 d1 = add_cols(d, min.q[1]) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
170 d1$Q_cutoff = "All reads" |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
171 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
172 # add columns for just the reads that pass the user Q threshold |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
173 d2 = add_cols(d, min.q[2]) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
174 d2$Q_cutoff = q_title |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
175 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
176 # bind those two together into one data frame |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
177 d = as.data.frame(rbindlist(list(d1, d2))) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
178 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
179 # name the flowcell (useful for analyses with >1 flowcell) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
180 d$flowcell = flowcell |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
181 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
182 # make sure this is a factor |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
183 d$Q_cutoff = as.factor(d$Q_cutoff) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
184 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
185 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
186 keep = c("hour","start_time", "channel", "sequence_length_template", "mean_qscore_template", "row", "col", "cumulative.bases", "cumulative.bases.time", "reads_per_hour", "Q_cutoff", "flowcell", "events_per_base") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
187 d = d[keep] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
188 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
189 d$start_bin = cut(d$start_time, 9,labels=c(1:9)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
190 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
191 return(d) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
192 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
193 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
194 reads.gt <- function(d, len){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
195 # return the number of reads in data frame d |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
196 # that are at least as long as length len |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
197 return(length(which(d$sequence_length_template>=len))) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
198 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
199 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
200 bases.gt <- function(d, len){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
201 # return the number of bases contained in reads from |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
202 # data frame d |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
203 # that are at least as long as length len |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
204 reads = subset(d, sequence_length_template >= len) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
205 return(sum(as.numeric(reads$sequence_length_template))) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
206 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
207 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
208 log10_minor_break = function (...){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
209 # function to add minor breaks to a log10 graph |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
210 # hat-tip: https://stackoverflow.com/questions/30179442/plotting-minor-breaks-on-a-log-scale-with-ggplot |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
211 function(x) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
212 minx = floor(min(log10(x), na.rm=T))-1; |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
213 maxx = ceiling(max(log10(x), na.rm=T))+1; |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
214 n_major = maxx-minx+1; |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
215 major_breaks = seq(minx, maxx, by=1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
216 minor_breaks = |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
217 rep(log10(seq(1, 9, by=1)), times = n_major)+ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
218 rep(major_breaks, each = 9) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
219 return(10^(minor_breaks)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
220 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
221 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
222 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
223 binSearch <- function(min, max, df, t = 100000) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
224 # binary search algorithm, thanks to https://stackoverflow.com/questions/46292438/optimising-a-calculation-on-every-cumulative-subset-of-a-vector-in-r/46303384#46303384 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
225 # the aim is to return the number of reads in a dataset (df) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
226 # that comprise the largest subset of reads with an N50 of t |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
227 # we use this to calculte the number of 'ultra long' reads |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
228 # which are defined as those with N50 > 100KB |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
229 mid = floor(mean(c(min, max))) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
230 if (mid == min) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
231 if (df$sequence_length_template[min(which(df$cumulative.bases>df$cumulative.bases[min]/2))] < t) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
232 return(min - 1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
233 } else { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
234 return(max - 1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
235 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
236 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
237 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
238 n = df$sequence_length_template[min(which(df$cumulative.bases>df$cumulative.bases[mid]/2))] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
239 if (n >= t) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
240 return(binSearch(mid, max, df)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
241 } else { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
242 return(binSearch(min, mid, df)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
243 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
244 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
245 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
246 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
247 summary.stats <- function(d, Q_cutoff="All reads"){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
248 # Calculate summary stats for a single value of min.q |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
249 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
250 rows = which(as.character(d$Q_cutoff)==Q_cutoff) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
251 d = d[rows,] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
252 d = d[with(d, order(-sequence_length_template)), ] # sort by read length, just in case |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
253 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
254 total.bases = sum(as.numeric(d$sequence_length_template)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
255 total.reads = nrow(d) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
256 N50.length = d$sequence_length_template[min(which(d$cumulative.bases > (total.bases/2)))] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
257 mean.length = round(mean(as.numeric(d$sequence_length_template)), digits = 1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
258 median.length = round(median(as.numeric(d$sequence_length_template)), digits = 1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
259 max.length = max(as.numeric(d$sequence_length_template)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
260 mean.q = round(mean(d$mean_qscore_template), digits = 1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
261 median.q = round(median(d$mean_qscore_template), digits = 1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
262 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
263 #calculate ultra-long reads and bases (max amount of data with N50>100KB) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
264 ultra.reads = binSearch(1, nrow(d), d, t = 100000) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
265 if(ultra.reads>=1){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
266 ultra.gigabases = sum(as.numeric(d$sequence_length_template[1:ultra.reads]))/1000000000 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
267 }else{ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
268 ultra.gigabases = 0 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
269 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
270 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
271 reads = list( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
272 reads.gt(d, 10000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
273 reads.gt(d, 20000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
274 reads.gt(d, 50000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
275 reads.gt(d, 100000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
276 reads.gt(d, 200000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
277 reads.gt(d, 500000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
278 reads.gt(d, 1000000), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
279 ultra.reads) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
280 names(reads) = c(">10kb", ">20kb", ">50kb", ">100kb", ">200kb", ">500kb", ">1m", "ultralong") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
281 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
282 bases = list( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
283 bases.gt(d, 10000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
284 bases.gt(d, 20000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
285 bases.gt(d, 50000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
286 bases.gt(d, 100000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
287 bases.gt(d, 200000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
288 bases.gt(d, 500000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
289 bases.gt(d, 1000000)/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
290 ultra.gigabases) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
291 names(bases) = c(">10kb", ">20kb", ">50kb", ">100kb", ">200kb", ">500kb", ">1m", "ultralong") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
292 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
293 return(list('total.gigabases' = total.bases/1000000000, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
294 'total.reads' = total.reads, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
295 'N50.length' = N50.length, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
296 'mean.length' = mean.length, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
297 'median.length' = median.length, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
298 'max.length' = max.length, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
299 'mean.q' = mean.q, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
300 'median.q' = median.q, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
301 'reads' = reads, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
302 'gigabases' = bases |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
303 )) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
304 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
305 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
306 channel.summary <- function(d){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
307 # calculate summaries of what happened in each of the channels |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
308 # of a flowcell |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
309 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
310 a <- d %>% group_by(channel) %>% summarize( |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
311 total.bases = sum(sequence_length_template), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
312 total.reads = sum(which(sequence_length_template>=0)), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
313 mean.read.length = mean(sequence_length_template), |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
314 median.read.length = median(sequence_length_template) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
315 ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
316 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
317 #b = melt(a, id.vars = c("channel")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
318 b = gather(a, key, -channel) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
319 return(b) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
320 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
321 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
322 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
323 single.flowcell <- function(input.file, output.dir, q=8){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
324 # wrapper function to analyse data from a single flowcell |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
325 # input.file is a sequencing_summary.txt file from a 1D run |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
326 # output.dir is the output directory into which to write results |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
327 # q is the cutoff used for Q values, set by the user |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
328 flog.info(paste("Loading input file:", input.file)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
329 d = load_summary(input.file, min.q=c(-Inf, q)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
330 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
331 flowcell = unique(d$flowcell) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
332 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
333 flog.info(paste(sep = "", flowcell, ": creating output directory:", output.dir)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
334 dir.create(output.dir) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
335 out.txt = file.path(output.dir, "summary.yaml") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
336 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
337 flog.info(paste(sep = "", flowcell, ": summarising input file for flowcell")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
338 all.reads.summary = summary.stats(d, Q_cutoff = "All reads") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
339 q10.reads.summary = summary.stats(d, Q_cutoff = q_title) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
340 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
341 summary = list("input file" = input.file, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
342 "All reads" = all.reads.summary, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
343 cutoff = q10.reads.summary, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
344 "notes" = 'ultralong reads refers to the largest set of reads with N50>100KB') |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
345 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
346 names(summary)[3] = q_title |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
347 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
348 write(as.yaml(summary), out.txt) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
349 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
350 muxes = seq(from = 0, to = max(d$hour), by = 8) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
351 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
352 # make plots |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
353 flog.info(paste(sep = "", flowcell, ": plotting length histogram")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
354 len.lims <- quantile(d$sequence_length_template,c(0.01,0.99)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
355 len.lims[1] <- max(1,len.lims[1]) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
356 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
357 p1 = ggplot(d, aes(x = sequence_length_template)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
358 geom_histogram(bins = 200, fill="steelblue") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
359 scale_x_log10(breaks=round(10^pretty(log10(len.lims),n=5),0),limits=len.lims) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
360 facet_wrap(~Q_cutoff, ncol = 1, scales = "free_y") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
361 #theme(text = element_text(size = 15)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
362 theme_linedraw() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
363 xlab("Read length") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
364 ylab("Number of reads") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
365 ggsave(filename = file.path(output.dir, "length_histogram.png"), width = 7, height = 4, dpi=300, plot = p1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
366 ggsave(filename = file.path(output.dir, "length_histogram.screen.png"), width = 7, height = 4, dpi=90, plot = p1) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
367 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
368 flog.info(paste(sep = "", flowcell, ": plotting mean Q score histogram")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
369 q.lims <- quantile(d$mean_qscore_template,c(0.005,0.995)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
370 p2 = ggplot(subset(d, Q_cutoff=="All reads"), aes(x = mean_qscore_template)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
371 geom_histogram(bins = 200, fill="steelblue") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
372 xlim(q.lims) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
373 geom_vline(xintercept=q) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
374 #theme(text = element_text(size = 15)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
375 theme_linedraw() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
376 xlab("Mean Q score of read") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
377 ylab("Number of reads") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
378 ggsave(filename = file.path(output.dir, "q_histogram.png"), width = 7, height = 4, dpi=300, plot = p2) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
379 ggsave(filename = file.path(output.dir, "q_histogram.screen.png"), width = 7, height = 4, dpi=90, plot = p2) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
380 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
381 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
382 flog.info(paste(sep = "", flowcell, ": plotting flowcell overview")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
383 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
384 df <- data.frame(row=integer(),col=integer(),bin=integer(), quality=numeric()) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
385 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
386 # swap rows and columns |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
387 for (b in c(1,5,9)) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
388 m <- matrix(data=rep(0,512),nrow=16,ncol=32) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
389 for (r in 1:32) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
390 for (c in 1:16) { |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
391 sub <- subset(d, Q_cutoff=="All reads" & col == c & row == r & start_bin == b) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
392 Q <- median(sub$mean_qscore_template) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
393 df <- rbind(df, list(row=r, col=c, bin=b, quality=Q) ) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
394 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
395 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
396 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
397 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
398 df$bin <- factor(df$bin) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
399 levels(df$bin) <- c("Run start", "Run middle", "Run end") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
400 p5 = ggplot(df, aes(col, row)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
401 geom_tile(aes(fill = quality), color="white") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
402 scale_fill_gradient(low = "white", high="steelblue") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
403 xlab("Column") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
404 ylab("Row") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
405 facet_wrap(~bin, ncol=3) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
406 theme_linedraw() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
407 theme(panel.grid.minor = element_blank(), panel.grid.major=element_blank()) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
408 #theme(text = element_text(size = 40), axis.text.x = element_text(size=12), axis.text.y = element_text(size=12), legend.text=element_text(size=12)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
409 ggsave(filename = file.path(output.dir, "flowcell_overview.png"), width = 7, height = 4, dpi=300, plot = p5) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
410 ggsave(filename = file.path(output.dir, "flowcell_overview.screen.png"), width = 7, height = 4, dpi=90, plot = p5) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
411 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
412 flog.info(paste(sep = "", flowcell, ": plotting cumulative yield summary")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
413 p5a = ggplot(d, aes(x=start_time/3600, y=cumulative.bases.time, colour = Q_cutoff)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
414 geom_line(size = 1) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
415 geom_vline(xintercept = muxes, colour = 'red', linetype = 'dashed', alpha = 0.5) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
416 xlab("Elapsed time (hrs)") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
417 ylab("Total yield in bases") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
418 scale_colour_discrete(guide = guide_legend(title = "Reads")) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
419 scale_x_continuous() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
420 theme_linedraw() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
421 #theme(text = element_text(size = 15)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
422 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
423 ggsave(filename = file.path(output.dir, "cumulative_yield.png"), width = 7, height = 4, dpi=300, plot = p5a) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
424 ggsave(filename = file.path(output.dir, "cumulative_yield.screen.png"), width = 7, height = 4, dpi=90, plot = p5a) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
425 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
426 flog.info(paste(sep = "", flowcell, ": plotting flowcell yield summary")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
427 p6 = ggplot(d, aes(x=sequence_length_template, y=cumulative.bases, colour = Q_cutoff)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
428 geom_line(size = 1) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
429 xlab("Minimum read length") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
430 ylab("Total yield in bases") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
431 scale_colour_discrete(guide = guide_legend(title = "Reads")) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
432 #theme(text = element_text(size = 15)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
433 theme_linedraw() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
434 xmax = max(d$sequence_length_template[which(d$cumulative.bases > 0.01 * max(d$cumulative.bases))]) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
435 p6 = p6 + scale_x_continuous(limits = c(0, xmax)) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
436 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
437 ggsave(filename = file.path(output.dir, "yield_summary.png"), width = 7, height = 4, dpi=300, plot = p6) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
438 ggsave(filename = file.path(output.dir, "yield_summary.screen.png"), width = 7, height = 4, dpi=90, plot = p6) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
439 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
440 flog.info(paste(sep = "", flowcell, ": plotting sequence length over time")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
441 e = subset(d, Q_cutoff=="All reads") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
442 e$Q = paste(">=", q, sep="") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
443 e$Q[which(e$mean_qscore_template<q)] = paste("<", q, sep="") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
444 p7 = ggplot(e, aes(x=start_time/3600, y=sequence_length_template, colour = Q, group = Q)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
445 geom_vline(xintercept = muxes, colour = 'red', linetype = 'dashed', alpha = 0.5) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
446 geom_smooth() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
447 xlab("Elapsed time (hrs)") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
448 ylab("Mean read length") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
449 ylim(0, NA) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
450 theme_linedraw() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
451 ggsave(filename = file.path(output.dir, "length_by_hour.png"), width = 7, height = 4, dpi=300, plot = p7) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
452 ggsave(filename = file.path(output.dir, "length_by_hour.screen.png"), width = 7, height = 4, dpi=90, plot = p7) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
453 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
454 flog.info(paste(sep = "", flowcell, ": plotting Q score over time")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
455 p8 = ggplot(e, aes(x=start_time/3600, y=mean_qscore_template, colour = Q, group = Q)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
456 geom_vline(xintercept = muxes, colour = 'red', linetype = 'dashed', alpha = 0.5) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
457 geom_smooth() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
458 xlab("Elapsed time (hrs)") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
459 ylab("Mean Q score") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
460 ylim(0, NA) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
461 theme_linedraw() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
462 ggsave(filename = file.path(output.dir, "q_by_hour.png"), width = 7, height = 4, dpi=300, plot = p8) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
463 ggsave(filename = file.path(output.dir, "q_by_hour.screen.png"), width = 7, height = 4, dpi=90, plot = p8) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
464 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
465 flog.info(paste(sep = "", flowcell, ": plotting reads per hour")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
466 f = d[c("hour", "reads_per_hour", "Q_cutoff")] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
467 f = f[!duplicated(f),] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
468 g = subset(f, Q_cutoff=="All reads") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
469 h = subset(f, Q_cutoff==q_title) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
470 max = max(f$hour) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
471 # all of this is just to fill in hours with no reads recorded |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
472 all = 0:max |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
473 add.g = all[which(all %in% g$hour == FALSE)] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
474 if(length(add.g)>0){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
475 add.g = data.frame(hour = add.g, reads_per_hour = 0, Q_cutoff = "All reads") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
476 g = rbind(g, add.g) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
477 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
478 add.h = all[which(all %in% h$hour == FALSE)] |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
479 if(length(add.h)>0){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
480 add.h = data.frame(hour = add.h, reads_per_hour = 0, Q_cutoff = q_title) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
481 h = rbind(h, add.h) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
482 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
483 i = rbind(g, h) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
484 i$Q_cutoff = as.character(i$Q_cutoff) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
485 i$Q_cutoff[which(i$Q_cutoff==q_title)] = paste("Q>=", q, sep="") |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
486 p9 = ggplot(i, aes(x=hour, y=reads_per_hour, colour = Q_cutoff, group = Q_cutoff)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
487 geom_vline(xintercept = muxes, colour = 'red', linetype = 'dashed', alpha = 0.5) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
488 #geom_point() + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
489 geom_line(size=1) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
490 xlab("Elapsed time (hrs)") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
491 ylab("Number of reads per hour") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
492 ylim(0, NA) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
493 scale_color_discrete(guide = guide_legend(title = "Reads")) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
494 theme_linedraw() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
495 ggsave(filename = file.path(output.dir, "reads_per_hour.png"), width = 7, height = 4, dpi=300, plot = p9) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
496 ggsave(filename = file.path(output.dir, "reads_per_hour.screen.png"), width = 7, height = 4, dpi=90, plot = p9) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
497 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
498 flog.info(paste(sep = "", flowcell, ": plotting read length vs. q score scatterplot")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
499 p10 = ggplot(subset(d, Q_cutoff=="All reads"), aes(x = sequence_length_template, y = mean_qscore_template, colour = events_per_base)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
500 geom_point(alpha=0.05, size = 0.4) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
501 scale_x_log10(minor_breaks=log10_minor_break()) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
502 labs(colour='Events per base\n(log scale)\n') + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
503 theme(text = element_text(size = 15)) + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
504 xlab("Read length") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
505 ylab("Mean Q score of read") + |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
506 theme_linedraw() |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
507 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
508 if(max(d$events_per_base, na.rm=T)>0){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
509 # a catch for 1D2 runs which don't have events per base |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
510 p10 = p10 + scale_colour_distiller(trans = "log", labels = scientific, palette = 'Spectral') |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
511 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
512 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
513 ggsave(filename = file.path(output.dir, "length_vs_q.png"), width = 7, height = 4, dpi=300, plot = p10) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
514 ggsave(filename = file.path(output.dir, "length_vs_q.screen.png"), width = 7, height = 4, dpi=90, plot = p10) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
515 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
516 return(d) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
517 } |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
518 |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
519 if(file_test("-f", input.file)==TRUE){ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
520 # if it's an existing file (not a folder) just run one analysis |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
521 d = single.flowcell(input.file, output.dir, q) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
522 }else{ |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
523 #WTF |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
524 flog.warn(paste("Could find a sequencing summary file in your input which was: ", |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
525 input.file, |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
526 "\nThe input must be a sequencing_summary.txt file produced by Albacore")) |
e0006d8bf849
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit b99a7d95d62b95ececc9d808f5f183b9eb718f80-dirty
jvolkening
parents:
diff
changeset
|
527 } |