annotate mykrobe_parser.R @ 3:0dcfdec76c3c draft

planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 44e99120db3fc06ca9302bc52687b00424e8b478
author nml
date Fri, 26 Oct 2018 16:57:34 -0400
parents f2608dccd3e0
children 8529045f0fdf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
1 # Copyright Government of Canada 2018
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
2 #
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
3 # Written by: National Microbiology Laboratory, Public Health Agency of Canada
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
4 #
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not use
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
6 # this work except in compliance with the License. You may obtain a copy of the
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
7 # License at:
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
8 #
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
9 # http://www.apache.org/licenses/LICENSE-2.0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
10 #
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
11 # Unless required by applicable law or agreed to in writing, software distributed
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
12 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
13 # CONDITIONS OF ANY KIND, either express or implied. See the License for the
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
14 # specific language governing permissions and limitations under the License.
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
15
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
16
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
17 # Parsing JSONs from Mykrobe Predict into CSV reports
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
18 # Take the JSON output from Mykrobe, rearrange, output for LIMS
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
19 # Adrian Zetner
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
20 # August 2018
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
21
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
22 # Libraries ####
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
23
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
24 sink(stdout(), type = "message")
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
25
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
26 suppressPackageStartupMessages({
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
27 library(jsonlite)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
28 library(here)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
29 library(dplyr)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
30 library(purrr)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
31 library(tidyr)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
32 library(stringr)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
33 library(optparse)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
34 })
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
35
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
36 # Define custom functions, variables, and paths. Collect and use CL arguments ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
37
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
38 # Here's a function to recreate that output table from the input JSON files
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
39
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
40 getResults <- function(listelement){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
41 # Define list levels for various elements of the json
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
42 species <- names(listelement[[1]][["phylogenetics"]][["species"]])
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
43 lineage <- names(listelement[[1]][["phylogenetics"]][["lineage"]])
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
44 phylo_group <- names(listelement[[1]][["phylogenetics"]][["phylo_group"]])
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
45 if("Non_tuberculosis_mycobacterium_complex" %in% phylo_group){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
46 warning(paste("Non-tuberculosis mycobacteria detected in file ", names(listelement), ". Skipping.", sep = ""))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
47 return()}
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
48
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
49 # Start building a list of all your various elements
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
50 temp <- list(mykrobe_version = listelement[[1]][["version"]][["mykrobe-predictor"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
51 file = names(listelement), # One element
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
52 plate_name = "test", # This probably needs changing
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
53 sample = "sequence_calls", # Likewise change this
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
54 phylo_group = phylo_group, # As above
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
55 species = species, # As above
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
56 lineage = lineage, # As above
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
57 # The following expressions drill down into the list elements and pull out what is needed.
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
58 # It's inelegant and vulnerable to changes in the input formats but if they're consistent it'll work
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
59 phylo_group_per_covg = listelement[[1]][["phylogenetics"]][["phylo_group"]][[phylo_group]][["percent_coverage"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
60 species_per_covg = listelement[[1]][["phylogenetics"]][["species"]][[species]][["percent_coverage"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
61 lineage_per_covg = listelement[[1]][["phylogenetics"]][["lineage"]][[lineage]][["percent_coverage"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
62 phylo_group_depth = listelement[[1]][["phylogenetics"]][["phylo_group"]][[phylo_group]][["median_depth"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
63 species_depth = listelement[[1]][["phylogenetics"]][["species"]][[species]][["median_depth"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
64 lineage_depth = listelement[[1]][["phylogenetics"]][["lineage"]][[lineage]][["median_depth"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
65 Mykrobe_Resistance_probe_set = basename(listelement[[1]][["probe_sets"]][2]) # Is it always the second?
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
66 )
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
67
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
68 # Super cool nested and vectorized (for SPEED!) functions to grab the predictions for drug sensitivity and gene variants
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
69 # Both produce character vectors of the same length as the number of drugs tested in the same order
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
70 # All of these also check if there are missing values in drug/susceptibility/variant elements and adds the column anyhow
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
71
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
72 if(length(map_chr(listelement[[1]][["susceptibility"]], "predict")) != 0){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
73 temp$susceptibility <- map_chr(listelement[[1]][["susceptibility"]], "predict")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
74 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
75 temp$susceptibility <- NA
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
76 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
77
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
78 if(length(names(listelement[[1]][["susceptibility"]])) != 0){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
79 temp$drug <- names(listelement[[1]][["susceptibility"]])
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
80 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
81 temp$drug <- NA
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
82 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
83
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
84 mapped.variants <- map(listelement[[1]][["susceptibility"]], # Dig into the lists, pull out variants and collapse into chr vector
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
85 ~ imap(.x[["called_by"]], # imap is shorthand for map2(x, names(x), ...), calling .y gets you the name / index of the current element
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
86 ~ paste(.y,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
87 .x[["info"]][["coverage"]][["alternate"]][["median_depth"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
88 .x[["info"]][["coverage"]][["reference"]][["median_depth"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
89 .x[["info"]][["conf"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
90 sep = ":"))) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
91 map_chr(~ paste(.x, collapse = "__"))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
92
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
93 if(length(mapped.variants) != 0){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
94 temp$`variants (gene:alt_depth:wt_depth:conf)` <- mapped.variants
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
95 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
96 temp$`variants (gene:alt_depth:wt_depth:conf)` <- NA
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
97 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
98
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
99 temp$`genes (prot_mut-ref_mut:percent_covg:depth)` <- NA
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
100
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
101 # Take that list and mash all the elements together as columns in a tibble, recycling as needed to fill in space
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
102 # eg. phylo_group is repeated/recycled as many times as there are drugs tested
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
103 as_tibble(temp)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
104 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
105
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
106 # Get command line arguments with optparse
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
107 option_list = list(
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
108 make_option(c("-f", "--file"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
109 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
110 default=NULL,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
111 help='dataset file name or quoted comma separated names: eg. "file1,file2,file3"',
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
112 metavar="character"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
113 make_option(c("-d", "--dir"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
114 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
115 default=NULL,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
116 help="directory location of json files",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
117 metavar="character"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
118 make_option(c("-v", "--version"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
119 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
120 default="",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
121 help="Mykrobe Workflow Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
122 metavar="character"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
123 make_option(c("-D", "--depth"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
124 type="integer",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
125 default=5,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
126 help="Minimum depth of coverage [default= %default]",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
127 metavar="integer"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
128 make_option(c("-c", "--conf"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
129 type="integer",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
130 default=10,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
131 help="Minimum genotype confidence for variant genotyping [default= %default]",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
132 metavar="integer"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
133 make_option(c("-n", "--name"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
134 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
135 default="",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
136 help="Name of the run",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
137 metavar="character")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
138 )
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
139
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
140 opt_parser = OptionParser(option_list=option_list)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
141 opt = parse_args(opt_parser)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
142
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
143 if (is.null(opt$file) & is.null(opt$dir)){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
144 print_help(opt_parser)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
145 stop("At least one argument must be supplied to input file or directory", call.=FALSE)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
146 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
147
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
148 # Parameters to take from Galaxy/CL as args or however works best
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
149 params <- c("", # Lims_Comment
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
150 "", # Lims_INTComment
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
151 opt$version, # Mykrobe_Workflow_Version
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
152 opt$depth, # Mykrobe_min_depth_default_5
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
153 opt$conf, # Mykrobe_min_conf_default_10
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
154 "", # LIMS_file - empty as it's an upload field in LIMS
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
155 opt$name) # LIMS_filename
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
156
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
157 names(params) <- c("Lims_Comment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
158 "Lims_INTComment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
159 "Mykrobe_Workflow_Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
160 "Mykrobe_min_depth_default_5",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
161 "Mykrobe_min_conf_default_10",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
162 "LIMS_file",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
163 "LIMS_filename")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
164
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
165
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
166 # A default report in the order our LIMS requires
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
167
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
168 # Make a default dataframe to combine the rest into and enforce column order / fill missing ones with NAs
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
169 columns <- c("file",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
170 "Mykrobe_fabG1",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
171 "Mykrobe_katG",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
172 "Mykrobe_ahpC",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
173 "Mykrobe_inhA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
174 "Mykrobe_ndh",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
175 "Isoniazid_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
176 "Isoniazid_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
177 "Mykrobe_rpoB",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
178 "Rifampicin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
179 "Rifampicin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
180 "Mykrobe_embB",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
181 "Mykrobe_embA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
182 "Ethambutol_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
183 "Ethambutol_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
184 "Mykrobe_pncA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
185 "Mykrobe_rpsA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
186 "Pyrazinamide_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
187 "Pyrazinamide_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
188 "Mykrobe_gyrA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
189 "Quinolones_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
190 "Quinolones_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
191 "Mykrobe_rpsL",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
192 "Mykrobe_Streptomycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
193 "Mykrobe_Streptomycin_gid",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
194 "Streptomycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
195 "Streptomycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
196 "Mykrobe_Amikacin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
197 "Amikacin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
198 "Amikacin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
199 "Mykrobe_Capreomycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
200 "Mykrobe_Capreomycin_tlyA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
201 "Capreomycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
202 "Capreomycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
203 "Mykrobe_Kanamycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
204 "Mykrobe_Kanamycin_eis",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
205 "Kanamycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
206 "Kanamycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
207 "Lims_Comment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
208 "Lims_INTComment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
209 "Mykrobe_Workflow_Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
210 "mykrobe_version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
211 "Mykrobe_Resistance_probe_set",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
212 "Mykrobe_min_depth_default_5",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
213 "Mykrobe_min_conf_default_10",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
214 "LIMS_file",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
215 "LIMS_filename")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
216
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
217 report <- setNames(data.frame(matrix("", ncol = length(columns), nrow = 1), stringsAsFactors = F), columns)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
218
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
219
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
220 # List of drugs that are tested
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
221 all_drugs <- c("Isoniazid",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
222 "Rifampicin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
223 "Ethambutol",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
224 "Pyrazinamide",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
225 "Moxifloxacin_Ofloxacin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
226 "Streptomycin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
227 "Amikacin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
228 "Capreomycin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
229 "Kanamycin")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
230
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
231 # Do Stuff ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
232
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
233 # Import all the JSON files into a list of lists format ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
234
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
235 if (is.null(opt$file)){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
236 # opt$dir is used to get the list of files, a vector of non-duplicated files is then passed to map
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
237 files <- list.files(path = opt$dir,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
238 pattern = "*.json",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
239 full.names = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
240 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
241 files <- unlist(strsplit(opt$file, ","))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
242 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
243
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
244 files <- files[!duplicated(basename(files))]
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
245
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
246 list.of.json.files <- map(files,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
247 ~ fromJSON(.x, simplifyDataFrame = F)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
248 )
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
249
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
250
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
251 # Apply that getResults function to each element in your list then bash it together into a final report
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
252
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
253 temp <- map(list.of.json.files, getResults) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
254 bind_rows()
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
255
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
256
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
257 # Predictions of resistance or susceptibility
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
258 predictions.table <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
259 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
260 select(file, drug, susceptibility) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
261 mutate(drug = paste(drug, "_Prediction", sep = "")) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
262 spread(drug, susceptibility, fill = "failed") %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
263 select(-starts_with("NA"))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
264
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
265 if (length(predictions.table) == 1){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
266 print(predictions.table)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
267 stop("No susceptibility results in files specified. Did the testing fail?", call.=FALSE)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
268 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
269
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
270 # Variants, if present
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
271 if (0 < predictions.table %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
272 select(ends_with("_Prediction")) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
273 unlist(use.names = F) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
274 str_count("[R,r]") %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
275 sum()){
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
276
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
277 # Multiple resistance mutations and confidence per drug in the X_R_mutations column
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
278 # Actual protein changes in Mykrobe_X columns
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
279
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
280 variants.temp <-
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
281 temp %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
282 select(file, drug, variants = `variants (gene:alt_depth:wt_depth:conf)`) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
283 mutate(variants = replace(variants, variants == "", NA)) %>% # Make missing data consistent...
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
284 filter(!is.na(variants)) %>% # ...Then get rid of it
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
285 mutate(tempcols = paste(drug, "R_mutations", sep = "_")) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
286 mutate(R_mutations = variants) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
287 mutate(variants = strsplit(variants, "__")) %>% # Split the mutations across rows (list first then split across rows)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
288 unnest(variants) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
289 separate(variants, c("gene", "mutation"), "_") %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
290 mutate(columnname = ifelse(gene %in% c("tlyA", "rrs", "gid"), # Check for columns that include the drug name or not and paste accordingly
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
291 paste("Mykrobe", drug, gene, sep = "_"),
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
292 paste("Mykrobe", gene, sep = "_"))) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
293 # Extract out the mutation information with a regex that covers all potential genes
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
294 # This regex looks for whatever is ahead of the first colon and after the last hyphen
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
295 mutate(mutation = str_match(mutation, "(.*)-.*:")[,2]) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
296 select(file, tempcols, R_mutations, columnname, mutation)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
297
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
298 # Split each kind of variants into its own temp table then merge
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
299 variants.1 <-
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
300 variants.temp %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
301 select(file, tempcols, R_mutations) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
302 distinct() %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
303 spread(tempcols, R_mutations)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
304
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
305 variants.2 <-
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
306 variants.temp %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
307 select(file, columnname, mutation) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
308 group_by(file, columnname) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
309 summarise(mutation = paste(mutation, collapse = ";")) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
310 spread(columnname, mutation)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
311
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
312 variants.table <- full_join(variants.1, variants.2, by = "file")
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
313 }else{
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
314 variants.table <- data.frame(file=predictions.table$file, stringsAsFactors = F)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
315 }
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
316
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
317
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
318 # Make a report ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
319
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
320 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
321 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
322 select(file, mykrobe_version, Mykrobe_Resistance_probe_set) %>% # Get important info from initial table
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
323 distinct() %>% # Drop duped rows and combine all the tables together
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
324 full_join(variants.table) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
325 full_join(predictions.table) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
326 bind_rows(report) %>% # Use bind_rows to add columns (eg. unteseted drugs) to the final output
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
327 filter(file != "")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
328
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
329 # Only add the 'no mutation' replacement to the columns that actually have a result
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
330 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
331 report %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
332 filter_at(vars(ends_with("_Prediction")), any_vars(. != "failed")) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
333 mutate_at(vars(starts_with("Mykrobe_")), funs(replace(., is.na(.), "No Mutation"))) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
334 full_join(anti_join(report, ., by = "file")) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
335 select(columns) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
336 rename(Moxifloxacin_Ofloxacin_R_mutations = Quinolones_R_mutations,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
337 Moxifloxacin_Ofloxacin_Prediction = Quinolones_Prediction)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
338
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
339
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
340 # Add in the parameters fed from Galaxy using named character vector
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
341 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
342 report %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
343 mutate(
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
344 Lims_Comment = params["Lims_Comment"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
345 Lims_INTComment = params["Lims_INTComment"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
346 Mykrobe_Workflow_Version = params["Mykrobe_Workflow_Version"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
347 Mykrobe_min_depth_default_5 = params["Mykrobe_min_depth_default_5"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
348 Mykrobe_min_conf_default_10 = params["Mykrobe_min_conf_default_10"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
349 LIMS_file = params["LIMS_file"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
350 LIMS_filename = params["LIMS_filename"]
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
351 )
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
352
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
353
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
354 #View(report)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
355
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
356 # Write some output
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
357 # Report as is
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
358 write.csv(report, "output-report.csv", row.names = F)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
359 print("Writing Susceptibility report to CSV as output-report.csv")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
360
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
361 # Select specific columns from temp and output them
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
362 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
363 select(file,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
364 phylo_group,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
365 species,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
366 lineage,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
367 phylo_group_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
368 species_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
369 lineage_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
370 phylo_group_depth,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
371 species_depth,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
372 lineage_depth) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
373 distinct() %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
374 write.csv("output-jsondata.csv", row.names = F)
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
375 print("Writing JSON data to CSV as output-jsondata.csv")
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
376 sink(NULL, type="message") # close the sink
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
377
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
378 quit()