Mercurial > repos > nml > mykrobe_parser
annotate mykrobe_parser.R @ 7:12b397ad8687 draft default tip
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 97945a3ad655f1a0f99f577d0d423124460d900a
author | nml |
---|---|
date | Tue, 24 Oct 2023 21:28:06 +0000 |
parents | 8e7e5a660942 |
children |
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 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
2 # |
0
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 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
4 # |
0
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: |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
8 # |
0
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 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
10 # |
0
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 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
21 # Updated August 2023 |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
22 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
23 # Libraries #### |
2
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
24 |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
25 sink(stdout(), type = "message") |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
26 |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
27 suppressPackageStartupMessages({ |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
28 library(jsonlite) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
29 library(here) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
30 library(dplyr) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
31 library(purrr) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
32 library(tidyr) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
33 library(stringr) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
34 library(optparse) |
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
35 }) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
36 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
37 # 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
|
38 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
39 # Here's a function to recreate that output table from the input JSON files for 2019 |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
40 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
41 getResults2019 <- function(listelement) { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
42 # Define list levels for various elements of the json |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
43 phylo_group <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
44 names(listelement[[1]][["phylogenetics"]][["phylo_group"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
45 if ("Non_tuberculosis_mycobacterium_complex" %in% phylo_group) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
46 warning( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
47 paste( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
48 "Non-tuberculosis mycobacteria detected in file ", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
49 names(listelement), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
50 ". Skipping.", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
51 sep = "" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
52 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
53 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
54 return() |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
55 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
56 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
57 species <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
58 names(listelement[[1]][["phylogenetics"]][["species"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
59 lineage <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
60 if (length(listelement[[1]][["phylogenetics"]][["lineage"]]) == 1) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
61 names(listelement[[1]][["phylogenetics"]][["lineage"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
62 } else { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
63 listelement[[1]][["phylogenetics"]][["lineage"]][["lineage"]] |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
64 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
65 |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
66 # Start building a list of all your various elements |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
67 temp <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
68 list( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
69 mykrobe_version = listelement[[1]][["version"]][["mykrobe-predictor"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
70 file = names(listelement), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
71 # One element |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
72 plate_name = "test", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
73 # This probably needs changing |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
74 sample = "sequence_calls", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
75 # Likewise change this |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
76 phylo_group = phylo_group, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
77 # As above |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
78 species = species, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
79 # As above |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
80 lineage = lineage, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
81 # As above |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
82 # The following expressions drill down into the list elements and pull out what is needed. |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
83 # It's inelegant and vulnerable to changes in the input formats but if they're consistent it'll work |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
84 phylo_group_per_covg = listelement[[1]][["phylogenetics"]][["phylo_group"]][[phylo_group]][["percent_coverage"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
85 species_per_covg = listelement[[1]][["phylogenetics"]][["species"]][[species]][["percent_coverage"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
86 lineage_per_covg = listelement[[1]][["phylogenetics"]][["lineage"]][[lineage]][["percent_coverage"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
87 phylo_group_depth = listelement[[1]][["phylogenetics"]][["phylo_group"]][[phylo_group]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
88 species_depth = listelement[[1]][["phylogenetics"]][["species"]][[species]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
89 lineage_depth = listelement[[1]][["phylogenetics"]][["lineage"]][[lineage]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
90 Mykrobe_Resistance_probe_set = basename(listelement[[1]][["probe_sets"]][2]) # Is it always the second? |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
91 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
92 |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
93 # 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
|
94 # 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
|
95 # All of these also check if there are missing values in drug/susceptibility/variant elements and adds the column anyhow |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
96 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
97 if (length(map_chr(listelement[[1]][["susceptibility"]], "predict")) != 0) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
98 temp$susceptibility <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
99 map_chr(listelement[[1]][["susceptibility"]], "predict") |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
100 } else { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
101 temp$susceptibility <- NA |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
102 } |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
103 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
104 if (length(names(listelement[[1]][["susceptibility"]])) != 0) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
105 temp$drug <- names(listelement[[1]][["susceptibility"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
106 } else { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
107 temp$drug <- NA |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
108 } |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
109 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
110 mapped.variants <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
111 map( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
112 listelement[[1]][["susceptibility"]], # Dig into the lists, pull out variants and collapse into chr vector |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
113 ~ imap( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
114 .x[["called_by"]], # imap is shorthand for map2(x, names(x), ...), calling .y gets you the name / index of the current element |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
115 ~ paste(.y, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
116 .x[["info"]][["coverage"]][["alternate"]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
117 .x[["info"]][["coverage"]][["reference"]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
118 .x[["info"]][["conf"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
119 sep = ":" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
120 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
121 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
122 ) %>% |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
123 map_chr(~ paste(.x, collapse = "__")) |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
124 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
125 if (length(mapped.variants) != 0) { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
126 temp$`variants (gene:alt_depth:wt_depth:conf)` <- mapped.variants |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
127 } else { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
128 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
|
129 } |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
130 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
131 temp$`genes (prot_mut-ref_mut:percent_covg:depth)` <- NA |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
132 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
133 # Take that list and mash all the elements together as columns in a tibble, recycling as needed to fill in space |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
134 # eg. phylo_group is repeated/recycled as many times as there are drugs tested |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
135 as_tibble(temp) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
136 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
137 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
138 # Here's a function to recreate that output table from the input JSON files for panel 2020 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
139 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
140 getResults2020 <- function(listelement) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
141 # Define list levels for various elements of the json |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
142 phylo_group <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
143 names(listelement[[1]][["phylogenetics"]][["phylo_group"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
144 if ("Non_tuberculosis_mycobacterium_complex" %in% phylo_group) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
145 warning( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
146 paste( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
147 "Non-tuberculosis mycobacteria detected in file ", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
148 names(listelement), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
149 ". Skipping.", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
150 sep = "" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
151 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
152 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
153 return() |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
154 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
155 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
156 species <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
157 names(listelement[[1]][["phylogenetics"]][["species"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
158 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
159 # Start building a list of all your various elements |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
160 temp <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
161 list( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
162 mykrobe_version = listelement[[1]][["version"]][["mykrobe-predictor"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
163 file = names(listelement), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
164 # One element |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
165 plate_name = "test", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
166 # This probably needs changing |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
167 sample = "sequence_calls", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
168 # Likewise change this |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
169 phylo_group = phylo_group, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
170 # As above |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
171 species = species, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
172 # As above |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
173 # The following expressions drill down into the list elements and pull out what is needed. |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
174 # It's inelegant and vulnerable to changes in the input formats but if they're consistent it'll work |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
175 phylo_group_per_covg = listelement[[1]][["phylogenetics"]][["phylo_group"]][[phylo_group]][["percent_coverage"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
176 species_per_covg = listelement[[1]][["phylogenetics"]][["species"]][[species]][["percent_coverage"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
177 phylo_group_depth = listelement[[1]][["phylogenetics"]][["phylo_group"]][[phylo_group]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
178 species_depth = listelement[[1]][["phylogenetics"]][["species"]][[species]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
179 Mykrobe_Resistance_probe_set = basename(listelement[[1]][["probe_sets"]][2]) # Is it always the second? |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
180 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
181 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
182 # Super cool nested and vectorized (for SPEED!) functions to grab the predictions for drug sensitivity and gene variants |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
183 # Both produce character vectors of the same length as the number of drugs tested in the same order |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
184 # All of these also check if there are missing values in drug/susceptibility/variant elements and adds the column anyhow |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
185 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
186 if (length(map_chr(listelement[[1]][["susceptibility"]], "predict")) != 0) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
187 temp$susceptibility <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
188 map_chr(listelement[[1]][["susceptibility"]], "predict") |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
189 } else { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
190 temp$susceptibility <- NA |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
191 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
192 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
193 if (length(names(listelement[[1]][["susceptibility"]])) != 0) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
194 temp$drug <- names(listelement[[1]][["susceptibility"]]) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
195 } else { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
196 temp$drug <- NA |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
197 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
198 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
199 mapped.variants <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
200 map( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
201 listelement[[1]][["susceptibility"]], # Dig into the lists, pull out variants and collapse into chr vector |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
202 ~ imap( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
203 .x[["called_by"]], # imap is shorthand for map2(x, names(x), ...), calling .y gets you the name / index of the current element |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
204 ~ paste(.y, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
205 .x[["info"]][["coverage"]][["alternate"]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
206 .x[["info"]][["coverage"]][["reference"]][["median_depth"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
207 .x[["info"]][["conf"]], |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
208 sep = ":" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
209 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
210 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
211 ) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
212 map_chr(~ paste(.x, collapse = "__")) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
213 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
214 if (length(mapped.variants) != 0) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
215 temp$`variants (gene:alt_depth:wt_depth:conf)` <- mapped.variants |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
216 } else { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
217 temp$`variants (gene:alt_depth:wt_depth:conf)` <- NA |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
218 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
219 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
220 temp$`genes (prot_mut-ref_mut:percent_covg:depth)` <- NA |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
221 |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
222 # 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
|
223 # 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
|
224 as_tibble(temp) |
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 # Get command line arguments with optparse |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
228 option_list <- list( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
229 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
230 c("-f", "--file"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
231 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
232 default = NULL, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
233 help = 'dataset file name or quoted comma separated names: eg. "file1,file2,file3"', |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
234 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
235 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
236 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
237 c("-d", "--dir"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
238 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
239 default = NULL, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
240 help = "directory location of json files", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
241 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
242 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
243 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
244 c("-v", "--version"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
245 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
246 default = "", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
247 help = "Mykrobe Workflow Version", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
248 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
249 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
250 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
251 c("-p", "--panel"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
252 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
253 default = "2019", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
254 help = "Mykrobe Panel Version: 2019 or 2020. [default= %default]", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
255 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
256 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
257 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
258 c("-D", "--depth"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
259 type = "integer", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
260 default = 5, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
261 help = "Minimum depth of coverage [default= %default]", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
262 metavar = "integer" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
263 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
264 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
265 c("-c", "--conf"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
266 type = "integer", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
267 default = 10, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
268 help = "Minimum genotype confidence for variant genotyping [default= %default]", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
269 metavar = "integer" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
270 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
271 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
272 c("-n", "--name"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
273 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
274 default = "", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
275 help = "Name of the run", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
276 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
277 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
278 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
279 c("-r", "--reportfile"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
280 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
281 default = "report", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
282 help = "File name for susceptibility report data", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
283 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
284 ), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
285 make_option( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
286 c("-s", "--speciationfile"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
287 type = "character", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
288 default = "jsondata", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
289 help = "File name for speciation data", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
290 metavar = "character" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
291 ) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
292 ) |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
293 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
294 opt_parser <- OptionParser(option_list = option_list) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
295 opt <- parse_args(opt_parser) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
296 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
297 if (is.null(opt$file) && is.null(opt$dir)) { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
298 print_help(opt_parser) |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
299 stop("At least one argument must be supplied to input file or directory", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
300 call. = FALSE |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
301 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
302 } |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
303 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
304 if (opt$panel != "2019" && opt$panel != "2020") { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
305 print_help(opt_parser) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
306 stop("Panel must be one of 2019 or 2020", call. = FALSE) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
307 } |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
308 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
309 # Parameters to take from Galaxy/CL as args or however works best |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
310 params <- c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
311 "", # Lims_Comment |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
312 "", # Lims_INTComment |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
313 opt$version, # Mykrobe_Workflow_Version |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
314 opt$panel, # Mykrobe Panel Version |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
315 opt$depth, # Mykrobe_min_depth_default_5 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
316 opt$conf, # Mykrobe_min_conf_default_10 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
317 "", # LIMS_file - empty as it's an upload field in LIMS |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
318 opt$name |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
319 ) # Mutation_set_version |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
320 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
321 names(params) <- c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
322 "Lims_Comment", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
323 "Lims_INTComment", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
324 "Mykrobe_Workflow_Version", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
325 "Mykrobe_Panel_Version", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
326 "Mykrobe_min_depth_default_5", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
327 "Mykrobe_min_conf_default_10", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
328 "LIMS_file", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
329 "Mutation_set_version" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
330 ) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
331 |
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 # 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
|
334 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
335 # Make a default dataframe to combine the rest into and enforce column order / fill missing ones with NAs |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
336 columns <- c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
337 "file", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
338 "Mykrobe_fabG1", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
339 "Mykrobe_katG", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
340 "Mykrobe_ahpC", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
341 "Mykrobe_inhA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
342 "Mykrobe_ndh", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
343 "Isoniazid_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
344 "Isoniazid_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
345 "Mykrobe_rpoB", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
346 "Rifampicin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
347 "Rifampicin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
348 "Mykrobe_embB", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
349 "Mykrobe_embA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
350 "Ethambutol_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
351 "Ethambutol_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
352 "Mykrobe_pncA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
353 "Mykrobe_rpsA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
354 "Pyrazinamide_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
355 "Pyrazinamide_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
356 "Mykrobe_Ofloxacin_gyrA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
357 "Ofloxacin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
358 "Ofloxacin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
359 "Mykrobe_Moxifloxacin_gyrA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
360 "Moxifloxacin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
361 "Moxifloxacin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
362 "Mykrobe_Ciprofloxacin_gyrA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
363 "Ciprofloxacin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
364 "Ciprofloxacin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
365 "Mykrobe_rpsL", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
366 "Mykrobe_Streptomycin_rrs", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
367 "Mykrobe_Streptomycin_gid", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
368 "Streptomycin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
369 "Streptomycin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
370 "Mykrobe_Amikacin_rrs", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
371 "Amikacin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
372 "Amikacin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
373 "Mykrobe_Capreomycin_rrs", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
374 "Mykrobe_Capreomycin_tlyA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
375 "Capreomycin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
376 "Capreomycin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
377 "Mykrobe_Kanamycin_rrs", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
378 "Mykrobe_Kanamycin_eis", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
379 "Kanamycin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
380 "Kanamycin_Prediction", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
381 "Lims_Comment", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
382 "Lims_INTComment", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
383 "Mykrobe_Workflow_Version", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
384 "mykrobe_version", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
385 "Mykrobe_Resistance_probe_set", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
386 "Mykrobe_min_depth_default_5", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
387 "Mykrobe_min_conf_default_10", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
388 "LIMS_file", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
389 "Mutation_set_version" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
390 ) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
391 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
392 report <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
393 setNames(data.frame(matrix( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
394 "", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
395 ncol = length(columns), nrow = 1 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
396 ), stringsAsFactors = FALSE), columns) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
397 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
398 report_cols <- c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
399 "file", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
400 "phylo_group", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
401 "species", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
402 "lineage", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
403 "phylo_group_per_covg", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
404 "species_per_covg", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
405 "lineage_per_covg", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
406 "phylo_group_depth", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
407 "species_depth", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
408 "lineage_depth" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
409 ) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
410 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
411 # List of drugs that are tested |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
412 all_drugs <- c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
413 "Isoniazid", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
414 "Rifampicin", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
415 "Ethambutol", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
416 "Pyrazinamide", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
417 "Moxifloxacin", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
418 "Ofloxacin", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
419 "Streptomycin", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
420 "Amikacin", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
421 "Capreomycin", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
422 "Kanamycin" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
423 ) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
424 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
425 # Do Stuff #### |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
426 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
427 # 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
|
428 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
429 if (is.null(opt$file)) { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
430 # opt$dir is used to get the list of files, a vector of non-duplicated files is then passed to map |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
431 files <- list.files( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
432 path = opt$dir, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
433 pattern = "*.json", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
434 full.names = TRUE |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
435 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
436 } else { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
437 files <- unlist(strsplit(opt$file, ",")) |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
438 } |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
439 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
440 files <- files[!duplicated(basename(files))] |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
441 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
442 list.of.json.files <- map( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
443 files, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
444 ~ fromJSON(.x, simplifyDataFrame = FALSE) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
445 ) |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
446 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
447 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
448 # Apply the correct getResults function to each element in your list then bash it together into a final report |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
449 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
450 if (opt$panel == "2019") { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
451 temp <- map(list.of.json.files, getResults2019) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
452 bind_rows() |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
453 } else if (opt$panel == "2020") { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
454 temp <- map(list.of.json.files, getResults2020) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
455 bind_rows() |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
456 columns <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
457 setdiff( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
458 columns, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
459 c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
460 "Mykrobe_Ciprofloxacin_gyrA", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
461 "Ciprofloxacin_R_mutations", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
462 "Ciprofloxacin_Prediction" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
463 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
464 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
465 report_cols <- setdiff( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
466 report_cols, |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
467 c( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
468 "lineage", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
469 "lineage_per_covg", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
470 "lineage_depth" |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
471 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
472 ) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
473 } else { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
474 stop("Panel must be one of 2019 or 2020", call. = FALSE) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
475 } |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
476 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
477 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
478 # Predictions of resistance or susceptibility |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
479 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
480 predictions.table <- |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
481 temp %>% |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
482 select(file, drug, susceptibility) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
483 mutate(drug = paste(drug, "_Prediction", sep = "")) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
484 spread(drug, susceptibility, fill = "failed") %>% |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
485 select(-starts_with("NA")) |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
486 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
487 if (length(predictions.table) == 1) { |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
488 print(predictions.table) |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
489 stop("No susceptibility results in files specified. Did the testing fail?", |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
490 call. = FALSE |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
491 ) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
492 } |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
493 |
2
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
494 # Variants, if present |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
495 num.variants <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
496 predictions.table %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
497 select(ends_with("_Prediction")) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
498 unlist(use.names = FALSE) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
499 str_count("[R,r]") %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
500 sum() |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
501 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
502 if (num.variants > 0) { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
503 # Multiple resistance mutations and confidence per drug in the X_R_mutations column |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
504 # Actual protein changes in Mykrobe_X columns |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
505 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
506 variants.temp <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
507 temp %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
508 select(file, drug, variants = `variants (gene:alt_depth:wt_depth:conf)`) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
509 mutate(variants = replace(variants, variants == "", NA)) %>% # Make missing data consistent... |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
510 filter(!is.na(variants)) %>% # ...Then get rid of it |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
511 mutate(tempcols = paste(drug, "R_mutations", sep = "_")) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
512 mutate(R_mutations = variants) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
513 mutate(variants = strsplit(variants, "__")) %>% # Split the mutations across rows (list first then split across rows) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
514 unnest(variants) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
515 separate(variants, c("gene", "mutation"), "_") %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
516 mutate(columnname = ifelse( |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
517 gene %in% c("gyrA", "rrs", "eis", "gid"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
518 # Check for columns that include the drug name or not and paste accordingly |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
519 paste("Mykrobe", drug, gene, sep = "_"), |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
520 paste("Mykrobe", gene, sep = "_") |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
521 )) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
522 # Extract out the mutation information with a regex that covers all potential genes |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
523 # This regex looks for whatever is ahead of the first colon and after the last hyphen |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
524 mutate(mutation = str_match(mutation, "(.*)-.*:")[, 2]) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
525 select(file, tempcols, R_mutations, columnname, mutation) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
526 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
527 # Split each kind of variants into its own temp table then merge |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
528 variants.1 <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
529 variants.temp %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
530 select(file, tempcols, R_mutations) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
531 distinct() %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
532 spread(tempcols, R_mutations) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
533 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
534 variants.2 <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
535 variants.temp %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
536 select(file, columnname, mutation) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
537 group_by(file, columnname) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
538 summarise(mutation = paste(mutation, collapse = ";")) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
539 spread(columnname, mutation) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
540 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
541 variants.table <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
542 full_join(variants.1, variants.2, by = "file") |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
543 } else { |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
544 variants.table <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
545 data.frame(file = predictions.table$file, stringsAsFactors = FALSE) |
2
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
546 } |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
547 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
548 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
549 # Make a report #### |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
550 |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
551 report <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
552 temp %>% |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
553 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
|
554 distinct() %>% # Drop duped rows and combine all the tables together |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
555 full_join(variants.table) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
556 full_join(predictions.table) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
557 bind_rows(report) %>% # Use bind_rows to add columns (eg. unteseted drugs) to the final output |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
558 filter(file != "") |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
559 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
560 # Only add the 'no mutation' replacement to the columns that actually have a result |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
561 report <- |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
562 report %>% |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
563 filter_at(vars(ends_with("_Prediction")), any_vars(. != "failed")) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
564 mutate_at(vars(starts_with("Mykrobe_")), funs(replace(., is.na(.), "No Mutation"))) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
565 full_join(anti_join(report, ., by = "file")) %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
566 select(columns) |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
567 |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
568 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
569 # Add in the parameters fed from Galaxy using named character vector |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
570 report <- |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
571 report %>% |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
572 mutate( |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
573 Lims_Comment = params["Lims_Comment"], |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
574 Lims_INTComment = params["Lims_INTComment"], |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 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
|
579 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
|
580 ) |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
581 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
582 # Write some output |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
583 # Report as is |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
584 write.csv(report, "output-report.csv", row.names = FALSE) |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
585 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
|
586 |
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
587 # Select specific columns from temp and output them |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
588 # Addition of any_of accounts for both 2019 and 2020 panels |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
589 |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
590 temp %>% |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
591 select_at( # This is a dplyr 0.8.3 function, superceded in newer versions but this tool is built around a number of specific deps |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
592 report_cols |
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
593 ) %>% |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
594 distinct() %>% |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
595 write.csv(file = "output-jsondata.csv", row.names = FALSE) |
2
f2608dccd3e0
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 1d77b6cae26ef3456ff6d469d71c61cab6a19906-dirty
nml
parents:
0
diff
changeset
|
596 print("Writing JSON data to CSV as output-jsondata.csv") |
6
8e7e5a660942
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 077a66175f3666924b42f216bbcb671ee0d026f2
nml
parents:
5
diff
changeset
|
597 sink(NULL, type = "message") # close the sink |
0
6eae14751768
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 0b64469b5d819a9c5b9ea85d07ccbc3b5fb6b25e-dirty
nml
parents:
diff
changeset
|
598 |
4
8529045f0fdf
planemo upload for repository https://github.com/phac-nml/mykrobe-parser commit 34d9c47b9451e5f7843028dba22b96d125fb09f5
nml
parents:
2
diff
changeset
|
599 quit() |