Skip to main content

Publication-quality AMR + Virulence heatmap with phylogenetic tree from abricate output

Project description

abriplot

Publication-quality AMR and Virulence gene heatmap with phylogenetic tree from abricate output.

PyPI version License: MIT Python 3.8+


What it does

abriplot takes the TSV files produced by abricate (CARD and VFDB databases) and a Newick phylogenetic tree, and produces a single publication-ready figure with:

  • Phylogenetic tree — branch lengths proportional, samples ordered by topology
  • AMR gene heatmap — presence/absence matrix from CARD, genes sorted by prevalence
  • Drug-class annotation strip — one row per resistance class above the AMR block; multi-class genes appear in all relevant rows; classes auto-detected from your data
  • Virulence gene heatmap — presence/absence matrix from VFDB
  • PDF + PNG exported automatically

Example figure


Installation

pip install abriplot

No Biopython required — pure Python Newick parser included.


Quick start

abriplot \
    --input_dir  /path/to/abricate_results/ \
    --tree       /path/to/tree.nwk \
    --output     figure.pdf

This produces figure.pdf and figure.png in the current directory.


All options

usage: abriplot [-h] --input_dir DIR --tree FILE [--output FILE] [--title TEXT]
                [--min_identity FLOAT] [--min_coverage FLOAT]
                [--top_amr INT] [--top_vf INT]

required arguments:
  --input_dir DIR       Directory containing *__card.tsv and *__vfdb.tsv files
  --tree FILE           Newick tree file (.nwk / .tree)

output:
  --output FILE         Output path — pdf, png, or svg [default: abriplot_figure.pdf]
  --title TEXT          Figure title [default: 'Phylogenetic Distribution of AMR
                        and Virulence Genes']

filtering:
  --min_identity FLOAT  Minimum % identity threshold [default: 80]
  --min_coverage FLOAT  Minimum % coverage threshold [default: 80]
  --top_amr INT         Keep only the N most prevalent AMR genes [default: all]
  --top_vf INT          Keep only the N most prevalent virulence genes [default: all]

Examples

# Custom title for a publication
abriplot --input_dir results/ --tree tree.nwk --output fig1.pdf \
         --title "AMR gene distribution in V. cholerae (2002–2019)"

# Tighter figure — top 40 AMR genes, top 25 VF genes
abriplot --input_dir results/ --tree tree.nwk --output fig1.pdf \
         --top_amr 40 --top_vf 25

# Stricter filtering
abriplot --input_dir results/ --tree tree.nwk --output fig1.pdf \
         --min_identity 95 --min_coverage 90

Input file format

abricate output files must follow the naming convention:

<sample>__card.tsv
<sample>__vfdb.tsv

These are produced automatically when you run abricate with the --db card and --db vfdb flags. Example abricate command:

abricate --db card  assembly.fasta > sample__card.tsv
abricate --db vfdb  assembly.fasta > sample__vfdb.tsv

Use as a library

from abriplot.io     import load_all
from abriplot.newick import tip_order
from abriplot.plot   import (build_matrix, order_by_tree,
                              sort_genes_by_prevalence, make_figure)

with open("tree.nwk") as f:
    ordered_tips, root, leaves = tip_order(f.read())

amr_records, vf_records = load_all("results/", min_id=80, min_cov=80)

amr_mat, amr_meta = build_matrix(amr_records)
vf_mat,  _        = build_matrix(vf_records)

amr_mat = order_by_tree(amr_mat, ordered_tips)
vf_mat  = order_by_tree(vf_mat,  ordered_tips).reindex(amr_mat.index, fill_value=0)

amr_mat = sort_genes_by_prevalence(amr_mat)
vf_mat  = sort_genes_by_prevalence(vf_mat)

make_figure(amr_mat, vf_mat, amr_meta, root, leaves,
            amr_mat.index.tolist(), "figure.pdf",
            title="My custom title")

Requirements

  • Python ≥ 3.8
  • numpy ≥ 1.21
  • pandas ≥ 1.3
  • matplotlib ≥ 3.5

License

MIT © [Sushant Nimbhokar]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abriplot-0.1.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abriplot-0.1.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file abriplot-0.1.1.tar.gz.

File metadata

  • Download URL: abriplot-0.1.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for abriplot-0.1.1.tar.gz
Algorithm Hash digest
SHA256 da8284acaaf0e0128b5202557ec0721c9d5e84d59d3129786b518dbce2df4ad2
MD5 08ce6bd445554c193ac17c586161aad3
BLAKE2b-256 0fe154f6c6a04c4c7ba2bb7466e701031be55e987641ed563e9c4b323ea67c13

See more details on using hashes here.

File details

Details for the file abriplot-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: abriplot-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for abriplot-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 02548e81d2eb5ae5e99e33dce7f0ac0cea499aea4e7ca31cc2fdc7f80f679f34
MD5 8b54aa42baf1ae157f507bf4924e8715
BLAKE2b-256 10b17ffdd44def4dc63184c3391eac99f8de250ef8d13f93e5189453db647295

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page