Before using code patterns, verify installed versions match. If versions differ:
Python: pip show <package> then help(module.function) to check signatures
CLI: <tool> --version then <tool> --help to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
AMR Detection
"Screen my isolates for antibiotic resistance genes" → Identify antimicrobial resistance determinants in bacterial genomes or metagenomes by searching against curated resistance gene databases.
# Assembled contigs
amrfinder -n contigs.fasta -o amr_results.tsv --threads 8
# With organism for point mutations
amrfinder -n contigs.fasta -O Escherichia -o amr_results.tsv
# Include stress/virulence genes
amrfinder -n contigs.fasta -O Salmonella --plus -o amr_results.tsv
From Protein Sequences
# If you have predicted proteins
amrfinder -p proteins.faa -o amr_results.tsv
# Combined nucleotide and protein
amrfinder -n contigs.fasta -p proteins.faa -g gff_annotation.gff \
-O Escherichia -o amr_results.tsv
Output Fields
Column
Description
Gene symbol
AMR gene name
Sequence name
Contig/protein ID
Element type
AMR, STRESS, VIRULENCE
Element subtype
Specific class
Class
Drug class
Subclass
Specific drug
% Coverage
Query coverage
% Identity
Sequence identity
Batch Processing
for fasta in assemblies/*.fasta; do
sample=$(basename $fasta .fasta)
amrfinder -n $fasta -O Escherichia --plus \
-o results/${sample}_amr.tsv --threads 4
done
# Combine results
head -1 results/sample1_amr.tsv > combined_amr.tsv
for f in results/*_amr.tsv; do
tail -n+2 $f >> combined_amr.tsv
done
ResFinder
Installation
conda install -c bioconda resfinder
# Or use web: https://cge.food.dtu.dk/services/ResFinder/
Run ResFinder
# Assembled genome
python -m resfinder -ifa contigs.fasta -o resfinder_output \
-db_res /path/to/resfinder_db -acq
# With species for point mutations
python -m resfinder -ifa contigs.fasta -o resfinder_output \
-db_res /path/to/resfinder_db \
-db_point /path/to/pointfinder_db \
-s "Escherichia coli" -acq
# Default (ncbi)
abricate contigs.fasta > abricate_results.tsv
# Specific database
abricate --db resfinder contigs.fasta > resfinder_results.tsv
abricate --db card contigs.fasta > card_results.tsv
# Multiple databases
for db in ncbi card resfinder; do
abricate --db $db contigs.fasta > ${db}_results.tsv
done
Batch Summary
# Run on multiple samples
abricate assemblies/*.fasta > all_results.tsv
# Generate summary matrix
abricate --summary all_results.tsv > summary_matrix.tsv
Metagenome AMR Profiling
Using ShortBRED
# Map reads to AMR markers
shortbred_quantify.py --markers amr_markers.faa \
--wgs reads_1.fq reads_2.fq \
--results amr_abundance.tsv \
--threads 8
Using GROOT
# Index database
groot index -m card.90 -i groot_index -p 8
# Align and report
groot align -i groot_index -f reads_1.fq,reads_2.fq -p 8 | \
groot report > amr_report.tsv
Complete Workflow
Goal: Screen a bacterial assembly for antimicrobial resistance genes using multiple databases for comprehensive resistance profiling.
Approach: Run AMRFinderPlus with organism-specific point mutation detection, then ABRicate against NCBI/CARD/ResFinder databases, and summarize drug class counts.