|
| 1 | +version 1.0 |
| 2 | + |
| 3 | +task amrfinderplus_nuc { |
| 4 | + input { |
| 5 | + File assembly |
| 6 | + String samplename |
| 7 | + # Parameters |
| 8 | + # --indent_min Minimum DNA %identity [0-1]; default is 0.9 (90%) or curated threshold if it exists |
| 9 | + # --mincov Minimum DNA %coverage [0-1]; default is 0.5 (50%) |
| 10 | + String? organism # make optional? |
| 11 | + Int? minid |
| 12 | + Int? mincov |
| 13 | + Int cpu = 4 |
| 14 | + String docker = "quay.io/staphb/ncbi-amrfinderplus:3.10.24" |
| 15 | + } |
| 16 | + command <<< |
| 17 | + # logging info |
| 18 | + date | tee DATE |
| 19 | + amrfinder --version | tee AMRFINDER_VERSION |
| 20 | + |
| 21 | + ### set $amrfinder_organism BASH variable based on gambit_predicted_taxon or user-defined input string |
| 22 | + ### final variable has strict syntax/spelling based on list from amrfinder --list_organisms |
| 23 | + # there may be other Acinetobacter species to add later, like those in the A. baumannii-calcoaceticus species complex |
| 24 | + if [[ "~{organism}" == *"Acinetobacter"*"baumannii"* ]]; then |
| 25 | + amrfinder_organism="Acinetobacter_baumannii" |
| 26 | + elif [[ "~{organism}" == *"Campylobacter"*"coli"* ]] || [[ "~{organism}" == *"Campylobacter"*"jejuni"* ]]; then |
| 27 | + amrfinder_organism="Campylobacter" |
| 28 | + elif [[ "~{organism}" == *"Clostridioides"*"difficile"* ]]; then |
| 29 | + amrfinder_organism="Clostridioides_difficile" |
| 30 | + elif [[ "~{organism}" == *"Enterococcus"*"faecalis"* ]]; then |
| 31 | + amrfinder_organism="Enterococcus_faecalis" |
| 32 | + elif [[ "~{organism}" == *"Enterococcus"*"faecium"* ]] || [[ "~{organism}" == *"Enterococcus"*"hirae"* ]]; then |
| 33 | + amrfinder_organism="Enterococcus_faecium" |
| 34 | + # should capture all Shigella and Escherichia species |
| 35 | + elif [[ "~{organism}" == *"Escherichia"* ]] || [[ "~{organism}" == *"Shigella"* ]]; then |
| 36 | + amrfinder_organism="Escherichia" |
| 37 | + # add other Klebsiella species later? Cannot use K. oxytoca as per amrfinderplus wiki |
| 38 | + elif [[ "~{organism}" == *"Klebsiella"*"aerogenes"* ]] || [[ "~{organism}" == *"Klebsiella"*"pnemoniae"* ]]; then |
| 39 | + amrfinder_organism="Klebsiella" |
| 40 | + # because some people spell the species 'gonorrhea' differently |
| 41 | + elif [[ "~{organism}" == *"Neisseria"*"gonorrhea"* ]] || [[ "~{organism}" == *"Neisseria"*"gonorrhoeae"* ]] || [[ "~{organism}" == *"Neisseria"*"meningitidis"* ]]; then |
| 42 | + amrfinder_organism="Neisseria" |
| 43 | + elif [[ "~{organism}" == *"Pseudomonas"*"aeruginosa"* ]]; then |
| 44 | + amrfinder_organism="Pseudomonas_aeruginosa" |
| 45 | + # pretty broad, could work on Salmonella bongori and other species |
| 46 | + elif [[ "~{organism}" == *"Salmonella"* ]]; then |
| 47 | + amrfinder_organism="Salmonella" |
| 48 | + elif [[ "~{organism}" == *"Staphylococcus"*"aureus"* ]]; then |
| 49 | + amrfinder_organism="Staphylococcus_aureus" |
| 50 | + elif [[ "~{organism}" == *"Staphylococcus"*"pseudintermedius"* ]]; then |
| 51 | + amrfinder_organism="Staphylococcus_pseudintermedius" |
| 52 | + elif [[ "~{organism}" == *"Streptococcus"*"agalactiae"* ]]; then |
| 53 | + amrfinder_organism="Streptococcus_agalactiae" |
| 54 | + elif [[ "~{organism}" == *"Streptococcus"*"pneumoniae"* ]] || [[ "~{organism}" == *"Streptococcus"*"mitis"* ]]; then |
| 55 | + amrfinder_organism="Streptococcus_pneumoniae" |
| 56 | + elif [[ "~{organism}" == *"Streptococcus"*"pyogenes"* ]]; then |
| 57 | + amrfinder_organism="Streptococcus_pyogenes" |
| 58 | + elif [[ "~{organism}" == *"Vibrio"*"cholerae"* ]]; then |
| 59 | + amrfinder_organism="Vibrio_cholerae" |
| 60 | + else |
| 61 | + echo "Either Gambit predicted taxon is not supported by NCBI-AMRFinderPlus or the user did not supply an organism as input." |
| 62 | + echo "Skipping the use of amrfinder --organism optional parameter." |
| 63 | + fi |
| 64 | +
|
| 65 | + # checking bash variable |
| 66 | + echo "amrfinder_organism is set to:" ${amrfinder_organism} |
| 67 | + |
| 68 | + # if amrfinder_organism variable is set, use --organism flag, otherwise do not use --organism flag |
| 69 | + if [[ -v amrfinder_organism ]] ; then |
| 70 | + # always use --plus flag, others may be left out if param is optional and not supplied |
| 71 | + # send STDOUT/ERR to log file for capturing database version |
| 72 | + amrfinder --plus \ |
| 73 | + --organism ${amrfinder_organism} \ |
| 74 | + ~{'--name ' + samplename} \ |
| 75 | + ~{'--nucleotide ' + assembly} \ |
| 76 | + ~{'-o ' + samplename + '_amrfinder_all.tsv'} \ |
| 77 | + ~{'--threads ' + cpu} \ |
| 78 | + ~{'--coverage_min ' + mincov} \ |
| 79 | + ~{'--ident_min ' + minid} 2>&1 | tee amrfinder.STDOUT-and-STDERR.log |
| 80 | + else |
| 81 | + # always use --plus flag, others may be left out if param is optional and not supplied |
| 82 | + # send STDOUT/ERR to log file for capturing database version |
| 83 | + amrfinder --plus \ |
| 84 | + ~{'--name ' + samplename} \ |
| 85 | + ~{'--nucleotide ' + assembly} \ |
| 86 | + ~{'-o ' + samplename + '_amrfinder_all.tsv'} \ |
| 87 | + ~{'--threads ' + cpu} \ |
| 88 | + ~{'--coverage_min ' + mincov} \ |
| 89 | + ~{'--ident_min ' + minid} 2>&1 | tee amrfinder.STDOUT-and-STDERR.log |
| 90 | + fi |
| 91 | +
|
| 92 | + # capture the database version from the stdout and stderr file that was just created |
| 93 | + grep "Database version:" amrfinder.STDOUT-and-STDERR.log | sed 's|Database version: ||' >AMRFINDER_DB_VERSION |
| 94 | +
|
| 95 | + # Element Type possibilities: AMR, STRESS, and VIRULENCE |
| 96 | + # create headers for 3 output files; tee to 3 files and redirect STDOUT to dev null so it doesn't print to log file |
| 97 | + head -n 1 ~{samplename}_amrfinder_all.tsv | tee ~{samplename}_amrfinder_stress.tsv ~{samplename}_amrfinder_virulence.tsv ~{samplename}_amrfinder_amr.tsv >/dev/null |
| 98 | + # looks for all rows with STRESS, AMR, or VIRULENCE and append to TSVs |
| 99 | + grep 'STRESS' ~{samplename}_amrfinder_all.tsv >> ~{samplename}_amrfinder_stress.tsv |
| 100 | + grep 'VIRULENCE' ~{samplename}_amrfinder_all.tsv >> ~{samplename}_amrfinder_virulence.tsv |
| 101 | + # || true is so that the final grep exits with code 0, preventing failures |
| 102 | + grep 'AMR' ~{samplename}_amrfinder_all.tsv >> ~{samplename}_amrfinder_amr.tsv || true |
| 103 | +
|
| 104 | + # create string outputs for all genes identified in AMR, STRESS, VIRULENCE |
| 105 | + amr_genes=$(awk -F '\t' '{ print $7 }' ~{samplename}_amrfinder_amr.tsv | tail -n+2 | tr '\n' ', ' | sed 's/.$//') |
| 106 | + stress_genes=$(awk -F '\t' '{ print $7 }' ~{samplename}_amrfinder_stress.tsv | tail -n+2 | tr '\n' ', ' | sed 's/.$//') |
| 107 | + virulence_genes=$(awk -F '\t' '{ print $7 }' ~{samplename}_amrfinder_virulence.tsv | tail -n+2 | tr '\n' ', ' | sed 's/.$//') |
| 108 | +
|
| 109 | + # if variable for list of genes is EMPTY, write string saying it is empty to float to Terra table |
| 110 | + if [ -z "${amr_genes}" ]; then |
| 111 | + amr_genes="No AMR genes detected by NCBI-AMRFinderPlus" |
| 112 | + fi |
| 113 | + if [ -z "${stress_genes}" ]; then |
| 114 | + stress_genes="No STRESS genes detected by NCBI-AMRFinderPlus" |
| 115 | + fi |
| 116 | + if [ -z "${virulence_genes}" ]; then |
| 117 | + virulence_genes="No VIRULENCE genes detected by NCBI-AMRFinderPlus" |
| 118 | + fi |
| 119 | +
|
| 120 | + # create final output strings |
| 121 | + echo "${amr_genes}" > AMR_GENES |
| 122 | + echo "${stress_genes}" > STRESS_GENES |
| 123 | + echo "${virulence_genes}" > VIRULENCE_GENES |
| 124 | + >>> |
| 125 | + output { |
| 126 | + File amrfinderplus_all_report = "~{samplename}_amrfinder_all.tsv" |
| 127 | + File amrfinderplus_amr_report = "~{samplename}_amrfinder_amr.tsv" |
| 128 | + File amrfinderplus_stress_report = "~{samplename}_amrfinder_stress.tsv" |
| 129 | + File amrfinderplus_virulence_report = "~{samplename}_amrfinder_virulence.tsv" |
| 130 | + String amrfinderplus_amr_genes = read_string("AMR_GENES") |
| 131 | + String amrfinderplus_stress_genes = read_string("STRESS_GENES") |
| 132 | + String amrfinderplus_virulence_genes = read_string("VIRULENCE_GENES") |
| 133 | + String amrfinderplus_version = read_string("AMRFINDER_VERSION") |
| 134 | + String amrfinderplus_db_version = read_string("AMRFINDER_DB_VERSION") |
| 135 | + } |
| 136 | + runtime { |
| 137 | + memory: "8 GB" |
| 138 | + cpu: cpu |
| 139 | + docker: docker |
| 140 | + disks: "local-disk 100 SSD" |
| 141 | + preemptible: 0 |
| 142 | + maxRetries: 3 |
| 143 | + } |
| 144 | +} |
0 commit comments