annotate mykrobe_parser.R @ 0:6eae14751768 draft

planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
author nml
date Fri, 28 Sep 2018 16:01:47 -0400
parents
children f2608dccd3e0
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 ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
23 library(jsonlite, quietly = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
24 library(here, quietly = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
25 suppressMessages(library(dplyr, quietly = T))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
26 suppressMessages(library(purrr, quietly = T))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
27 library(tidyr, quietly = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
28 library(stringr, quietly = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
29 library(optparse, quietly = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
30
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
31 # 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
32
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
33 # 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
34
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
35 getResults <- function(listelement){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
36 # 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
37 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
38 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
39 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
40 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
41 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
42 return()}
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
43
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
44 # 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
45 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
46 file = names(listelement), # One element
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
47 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
48 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
49 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
50 species = species, # As above
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
51 lineage = lineage, # As above
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
52 # 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
53 # 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 )
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
62
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
63 # 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
64 # 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
65 # 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
66
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
67 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
68 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
69 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
70 temp$susceptibility <- NA
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
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
73 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
74 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
75 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
76 temp$drug <- NA
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
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
79 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
80 ~ 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
81 ~ paste(.y,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
82 .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
83 .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
84 .x[["info"]][["conf"]],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
85 sep = ":"))) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
86 map_chr(~ paste(.x, collapse = "__"))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
87
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
88 if(length(mapped.variants) != 0){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
89 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
90 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
91 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
92 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
93
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
94 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
95
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
96 # 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
97 # 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
98 as_tibble(temp)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
99 }
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 sink(stdout(), type = "message")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
102
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
103 suppressPackageStartupMessages({
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
104 library(jsonlite)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
105 library(here)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
106 library(dplyr)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
107 library(purrr)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
108 library(tidyr)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
109 library(stringr)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
110 library(optparse)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
111 })
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
112
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
113 # 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
114 option_list = list(
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
115 make_option(c("-f", "--file"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
116 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
117 default=NULL,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
118 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
119 metavar="character"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
120 make_option(c("-d", "--dir"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
121 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
122 default=NULL,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
123 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
124 metavar="character"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
125 make_option(c("-v", "--version"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
126 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
127 default="",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
128 help="Mykrobe Workflow Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
129 metavar="character"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
130 make_option(c("-D", "--depth"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
131 type="integer",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
132 default=5,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
133 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
134 metavar="integer"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
135 make_option(c("-c", "--conf"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
136 type="integer",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
137 default=10,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
138 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
139 metavar="integer"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
140 make_option(c("-n", "--name"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
141 type="character",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
142 default="",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
143 help="Name of the run",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
144 metavar="character")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
145 )
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 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
148 opt = parse_args(opt_parser)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
149
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
150 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
151 print_help(opt_parser)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
152 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
153 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
154
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
155 # 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
156 params <- c("", # Lims_Comment
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
157 "", # Lims_INTComment
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
158 opt$version, # Mykrobe_Workflow_Version
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
159 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
160 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
161 "", # 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
162 opt$name) # LIMS_filename
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
163
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
164 names(params) <- c("Lims_Comment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
165 "Lims_INTComment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
166 "Mykrobe_Workflow_Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
167 "Mykrobe_min_depth_default_5",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
168 "Mykrobe_min_conf_default_10",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
169 "LIMS_file",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
170 "LIMS_filename")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
171
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
172
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
173 # 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
174
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
175 # 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
176 columns <- c("file",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
177 "Mykrobe_fabG1",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
178 "Mykrobe_katG",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
179 "Mykrobe_ahpC",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
180 "Mykrobe_inhA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
181 "Mykrobe_ndh",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
182 "Isoniazid_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
183 "Isoniazid_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
184 "Mykrobe_rpoB",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
185 "Rifampicin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
186 "Rifampicin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
187 "Mykrobe_embB",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
188 "Mykrobe_embA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
189 "Ethambutol_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
190 "Ethambutol_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
191 "Mykrobe_pncA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
192 "Mykrobe_rpsA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
193 "Pyrazinamide_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
194 "Pyrazinamide_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
195 "Mykrobe_gyrA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
196 "Quinolones_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
197 "Quinolones_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
198 "Mykrobe_rpsL",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
199 "Mykrobe_Streptomycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
200 "Mykrobe_Streptomycin_gid",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
201 "Streptomycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
202 "Streptomycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
203 "Mykrobe_Amikacin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
204 "Amikacin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
205 "Amikacin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
206 "Mykrobe_Capreomycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
207 "Mykrobe_Capreomycin_tlyA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
208 "Capreomycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
209 "Capreomycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
210 "Mykrobe_Kanamycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
211 "Mykrobe_Kanamycin_eis",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
212 "Kanamycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
213 "Kanamycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
214 "Lims_Comment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
215 "Lims_INTComment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
216 "Mykrobe_Workflow_Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
217 "mykrobe_version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
218 "Mykrobe_Resistance_probe_set",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
219 "Mykrobe_min_depth_default_5",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
220 "Mykrobe_min_conf_default_10",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
221 "LIMS_file",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
222 "LIMS_filename")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
223
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
224 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
225
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
226
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
227 # 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
228 all_drugs <- c("Isoniazid",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
229 "Rifampicin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
230 "Ethambutol",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
231 "Pyrazinamide",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
232 "Moxifloxacin_Ofloxacin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
233 "Streptomycin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
234 "Amikacin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
235 "Capreomycin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
236 "Kanamycin")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
237
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
238 # Do Stuff ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
239
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
240 # 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
241
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
242 if (is.null(opt$file)){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
243 # 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
244 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
245 pattern = "*.json",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
246 full.names = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
247 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
248 files <- unlist(strsplit(opt$file, ","))
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 files <- files[!duplicated(basename(files))]
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 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
254 ~ fromJSON(.x, simplifyDataFrame = F)
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
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
258 # 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
259
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
260 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
261 bind_rows()
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
262
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
263
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
264 # Predictions of resistance or susceptibility
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
265 predictions.table <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
266 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
267 select(file, drug, susceptibility) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
268 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
269 spread(drug, susceptibility, fill = "failed") %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
270 select(-starts_with("NA"))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
271
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
272 if (length(predictions.table) == 1){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
273 print(predictions.table)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
274 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
275 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
276
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
277 # Variants
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
278 # Multiple resistance mutations and confidence per drug in the X_R_mutations column
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
279 # Actual protein changes in Mykrobe_X columns
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
280
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
281 variants.temp <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
282 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
283 select(file, drug, variants = `variants (gene:alt_depth:wt_depth:conf)`) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
284 mutate(variants = replace(variants, variants == "", NA)) %>% # Make missing data consistent...
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
285 filter(!is.na(variants)) %>% # ...Then get rid of it
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
286 mutate(tempcols = paste(drug, "R_mutations", sep = "_")) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
287 mutate(R_mutations = variants) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
288 mutate(variants = strsplit(variants, "__")) %>% # Split the mutations across rows (list first then split across rows)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
289 unnest(variants) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
290 separate(variants, c("gene", "mutation"), "_") %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
291 mutate(columnname = ifelse(gene %in% c("tlyA", "rrs", "gid"), # Check for columns that include the drug name or not and paste accordingly
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
292 paste("Mykrobe", drug, gene, sep = "_"),
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
293 paste("Mykrobe", gene, sep = "_"))) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
294 # Extract out the mutation information with a regex that covers all potential genes
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
295 # This regex looks for whatever is ahead of the first colon and after the last hyphen
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
296 mutate(mutation = str_match(mutation, "(.*)-.*:")[,2]) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
297 select(file, tempcols, R_mutations, columnname, mutation)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
298
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
299 # Split each kind of variants into its own temp table then merge
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
300 variants.1 <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
301 variants.temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
302 select(file, tempcols, R_mutations) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
303 distinct() %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
304 spread(tempcols, R_mutations)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
305
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
306 variants.2 <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
307 variants.temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
308 select(file, columnname, mutation) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
309 group_by(file, columnname) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
310 summarise(mutation = paste(mutation, collapse = ";")) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
311 spread(columnname, mutation)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
312
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
313 variants.table <- full_join(variants.1, variants.2, by = "file")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
314
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
315 # Make a report ####
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 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
318 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
319 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
320 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
321 full_join(variants.table) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
322 full_join(predictions.table) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
323 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
324 filter(file != "")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
325
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
326 # 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
327 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
328 report %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
329 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
330 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
331 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
332 select(columns) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
333 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
334 Moxifloxacin_Ofloxacin_Prediction = Quinolones_Prediction)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
335
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
336
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
337 # 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
338 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
339 report %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
340 mutate(
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
341 Lims_Comment = params["Lims_Comment"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
342 Lims_INTComment = params["Lims_INTComment"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
343 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
344 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
345 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
346 LIMS_file = params["LIMS_file"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
347 LIMS_filename = params["LIMS_filename"]
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
348 )
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
349
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
350
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
351 #View(report)
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 # Write some output
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
354 # Report as is
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
355 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
356 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
357
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
358 # 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
359 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
360 select(file,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
361 phylo_group,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
362 species,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
363 lineage,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
364 phylo_group_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
365 species_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
366 lineage_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
367 phylo_group_depth,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
368 species_depth,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
369 lineage_depth) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
370 distinct() %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
371 write.csv("output-jsondata.csv", row.names = F)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
372 print("Writing JSON data to CSV as output-jsondata.txt")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
373 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
374
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
375 quit()