annotate mykrobe_parser.R @ 4:8529045f0fdf draft

planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
author nml
date Thu, 25 Apr 2019 10:13:46 -0400
parents f2608dccd3e0
children deebc6410d13
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
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
155 opt$name) # Mutation_set_version
0
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",
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
163 "Mutation_set_version")
0
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",
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
188 "Mykrobe_Ofloxacin_gyrA",
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
189 "Ofloxacin_R_mutations",
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
190 "Ofloxacin_Prediction",
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
191 "Mykrobe_Moxifloxacin_gyrA",
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
192 "Moxifloxacin_R_mutations",
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
193 "Moxifloxacin_Prediction",
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
194 "Mykrobe_rpsL",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
195 "Mykrobe_Streptomycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
196 "Mykrobe_Streptomycin_gid",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
197 "Streptomycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
198 "Streptomycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
199 "Mykrobe_Amikacin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
200 "Amikacin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
201 "Amikacin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
202 "Mykrobe_Capreomycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
203 "Mykrobe_Capreomycin_tlyA",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
204 "Capreomycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
205 "Capreomycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
206 "Mykrobe_Kanamycin_rrs",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
207 "Mykrobe_Kanamycin_eis",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
208 "Kanamycin_R_mutations",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
209 "Kanamycin_Prediction",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
210 "Lims_Comment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
211 "Lims_INTComment",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
212 "Mykrobe_Workflow_Version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
213 "mykrobe_version",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
214 "Mykrobe_Resistance_probe_set",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
215 "Mykrobe_min_depth_default_5",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
216 "Mykrobe_min_conf_default_10",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
217 "LIMS_file",
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
218 "Mutation_set_version")
0
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 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
221
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
222
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
223 # 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
224 all_drugs <- c("Isoniazid",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
225 "Rifampicin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
226 "Ethambutol",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
227 "Pyrazinamide",
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
228 "Moxifloxacin",
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
229 "Ofloxacin",
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
230 "Streptomycin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
231 "Amikacin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
232 "Capreomycin",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
233 "Kanamycin")
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 # Do Stuff ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
236
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
237 # 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
238
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
239 if (is.null(opt$file)){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
240 # 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
241 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
242 pattern = "*.json",
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
243 full.names = T)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
244 }else{
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
245 files <- unlist(strsplit(opt$file, ","))
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
246 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
247
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
248 files <- files[!duplicated(basename(files))]
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 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
251 ~ fromJSON(.x, simplifyDataFrame = F)
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
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
254
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
255 # 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
256
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
257 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
258 bind_rows()
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
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
261 # Predictions of resistance or susceptibility
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
262 predictions.table <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
263 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
264 select(file, drug, susceptibility) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
265 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
266 spread(drug, susceptibility, fill = "failed") %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
267 select(-starts_with("NA"))
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 if (length(predictions.table) == 1){
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
270 print(predictions.table)
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
271 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
272 }
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
273
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
274 # Variants, if present
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
275 if (0 < predictions.table %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
276 select(ends_with("_Prediction")) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
277 unlist(use.names = F) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
278 str_count("[R,r]") %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
279 sum()){
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
280
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
281 # 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
282 # 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
283
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
284 variants.temp <-
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
285 temp %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
286 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
287 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
288 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
289 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
290 mutate(R_mutations = variants) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
291 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
292 unnest(variants) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
293 separate(variants, c("gene", "mutation"), "_") %>%
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
294 mutate(columnname = ifelse(gene %in% c("tlyA", "rrs", "eis", "gid"), # Check for columns that include the drug name or not and paste accordingly
2
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
295 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
296 paste("Mykrobe", gene, sep = "_"))) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
297 # 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
298 # 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
299 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
300 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
301
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
302 # 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
303 variants.1 <-
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
304 variants.temp %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
305 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
306 distinct() %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
307 spread(tempcols, R_mutations)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
308
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
309 variants.2 <-
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
310 variants.temp %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
311 select(file, columnname, mutation) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
312 group_by(file, columnname) %>%
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
313 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
314 spread(columnname, mutation)
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
315
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
316 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
317 }else{
f2608dccd3e0 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents: 0
diff changeset
318 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
319 }
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
320
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
321
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
322 # Make a report ####
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
323
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
324 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
325 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
326 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
327 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
328 full_join(variants.table) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
329 full_join(predictions.table) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
330 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
331 filter(file != "")
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
332
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
333 # 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
334 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
335 report %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
336 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
337 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
338 full_join(anti_join(report, ., by = "file")) %>%
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
339 select(columns)
0
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
340
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
341
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
342 # 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
343 report <-
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
344 report %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
345 mutate(
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
346 Lims_Comment = params["Lims_Comment"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
347 Lims_INTComment = params["Lims_INTComment"],
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
348 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
349 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
350 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
351 LIMS_file = params["LIMS_file"],
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
352 Mutation_set_version = params["Mutation_set_version"]
0
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
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 #View(report)
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 # Write some output
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
359 # Report as is
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
360 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
361 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
362
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
363 # 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
364 temp %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
365 select(file,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
366 phylo_group,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
367 species,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
368 lineage,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
369 phylo_group_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
370 species_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
371 lineage_per_covg,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
372 phylo_group_depth,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
373 species_depth,
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
374 lineage_depth) %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
375 distinct() %>%
6eae14751768 planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff changeset
376 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
377 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
378 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
379
4
8529045f0fdf planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents: 2
diff changeset
380 quit()