Skip to content

Commit

Permalink
adding plotting AMRs (#9)
Browse files Browse the repository at this point in the history
* Update amr.md

* add script to plot amrfinder results

* plot_amrfinder

* Update amr.md

* Update amr.md

* Update docs/amr.md

Co-authored-by: C. Titus Brown <titus@idyll.org>

---------

Co-authored-by: C. Titus Brown <titus@idyll.org>
  • Loading branch information
AnneliektH and ctb authored Apr 29, 2024
1 parent 7160204 commit 1eddf40
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs/amr.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ of the metagenome.

First, install the software. Run:
```
mamba create -n amrfinder -y ncbi-amrfinderplus megahit prodigal csvtk
mamba create -n amrfinder -y ncbi-amrfinderplus megahit prodigal csvtk matplotlib seaborn pandas
conda activate amrfinder
```

Expand Down Expand Up @@ -102,3 +102,11 @@ reads to it to get the abundance. This is because assembly collapses
the abundance of the output contigs, and you have to recover it through
other means.


Now we can plot the abundances of the AMRs we found:
```
../scripts/plot_amr.py CD136.amrfinder.tsv -o CD136.amrfinder.pdf
```
![CD136 amrfinder](https://github.com/AnneliektH/2024-pig-paradigm-workshop/blob/main/docs/images/CD136.amrfinder.png)


Binary file added docs/images/CD136.amrfinder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions scripts/plot_amr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env python
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import sys
import argparse


def main():
p = argparse.ArgumentParser()
p.add_argument('df')
p.add_argument('-o', '--output-figure', required=True)
args = p.parse_args()

df = pd.read_csv(args.df, sep = '\t')
df_all = df.Class.value_counts().to_frame().reset_index()
figure = sns.barplot(data=df_all, x="count", y="Class", hue="Class", legend=False)
figure.figure.set_size_inches(15,5)
figure.figure.savefig(args.output_figure)



if __name__ == '__main__':
sys.exit(main())

0 comments on commit 1eddf40

Please sign in to comment.