Skip to content

Tips and tricks

Arjun Prasad edited this page Jun 18, 2020 · 32 revisions

Several users have asked questions about running AMRFinderPlus and/or modifying the output in various ways. AMRFinderPlus hews to UNIX traditions for command-line programs so there are many ways to modify the way it is run. Most of these assume standard UNIX utilities and the bash shell.

Combine mutliple AMRFinderPlus output files prepending each line with the filename

When running AMRFinderPlus on many assemblies it is often useful to combine the output from many runs into one file with an additional column for an assembly identifier. There are a few ways to do this outlined in issue 25.

The following assumes the files you want to combine are named *.amrfinder. It will create a file named combined.tsv that contains all of the AMRFinderPlus files combined.

h=$(head -1 $(ls *.amrfinder | head -1))
echo $'filename\t' "$h" > combined.tsv
grep -v '^Protein identifier' *.amrfinder | sed 's/:/\t/'  >> combined.tsv

Use a bash loop to run on a number of files serially

This assumes that you're using a consistent filename format with .assembly.fa as the extension on your assembly nucleotide FASTA files, and that you want to run AMRFinderPlus serially (one job after the other). See issue 32 for another example.

for assembly in *.assembly.fa
do
    base=$(basename $assembly .assembly.fa)
    amrfinder -n $assembly --threads 8 --plus > $base.amrfinder
done

Combine results of AMRFinderPlus on many assemblies into one file for easier analysis

Sometimes you want to collate the above output into a single file, prefixing each line by the filename. Here's one way to do that. This assumes that you want to combine all the AMRFinderPlus output files named with a .amrfinder extension (Inspired by Issue 25)

header=$( head -1 $( ls *.amrfinder | head -1 ) )
echo $'filename\t' "$header" > together.amrfinder.tab
grep '' *.amrfinder | grep -v 'Protein identifier\tContig id' \
    | sed 's/:/\t/' >> together.amrfinder.tab
Clone this wiki locally