Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AMR accumulation/rarefaction plot view. #46

Merged
merged 6 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ to [Common Changelog](https://common-changelog.org)

### Added

- Add AMR accumulation/rarefaction plot view. ([#46](https://github.com/metagenlab/zDB/pull/46)) (Niklaus Johner)
- Add AMR heatmap view. ([#45](https://github.com/metagenlab/zDB/pull/45)) (Niklaus Johner)
- Add AMR details view. ([#44](https://github.com/metagenlab/zDB/pull/44)) (Niklaus Johner)
- Add AMR Venn diagram view. ([#41](https://github.com/metagenlab/zDB/pull/41)) (Niklaus Johner)
Expand Down
41 changes: 26 additions & 15 deletions testing/webapp/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
'/module_comparison/',
'/orthogroup/group_85',
'/orthogroup_comparison',
'/pan_genome/amr',
'/pan_genome/cog',
'/pan_genome/ko',
'/pan_genome/orthogroup',
Expand Down Expand Up @@ -188,21 +189,6 @@ def test_cog_barchart(self):
self.assertPlot(resp)
self.assertContains(resp, "Distribution of COGs within COG categories")

def test_pan_genome_cog(self):
resp = self.client.get("/pan_genome/cog")
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'chlamdb/pan_genome.html')
self.assertEqual("cog", resp.context["type"])
self.assertTitle(resp, "Comparisons: Clusters of Orthologous groups (COGs)")
self.assertNoPlot(resp)

resp = self.client.post("/pan_genome/cog", data={"targets": ["0", "1"]})
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'chlamdb/pan_genome.html')
self.assertEqual("cog", resp.context["type"])
self.assertTitle(resp, "Comparisons: Clusters of Orthologous groups (COGs)")
self.assertPlot(resp)


class ComparisonViewsTestMixin():

Expand All @@ -215,6 +201,7 @@ class ComparisonViewsTestMixin():
table_html = '<table class="hover" id="mytable" style="padding-top: 1em;">'
venn_html = '<div id="venn_diagram" '
heatmap_html = '<div id="heatmap" '
rarefaction_plot_html = 'id="rarefaction_plot"'

def assertPageTitle(self, resp, title):
self.assertContains(
Expand Down Expand Up @@ -254,6 +241,14 @@ def assertHeatmap(self, resp):
self.assertTrue(resp.context.get("envoi_heatmap", False))
self.assertContains(resp, self.heatmap_html)

def assertNoRarefactionPlot(self, resp):
self.assertFalse(resp.context.get("envoi", False))
self.assertNotContains(resp, self.rarefaction_plot_html)

def assertRarefactionPlot(self, resp):
self.assertTrue(resp.context.get("envoi", False))
self.assertContains(resp, self.rarefaction_plot_html)

@property
def tab_comp_view(self):
return f"/{self.view_type}_comparison"
Expand Down Expand Up @@ -347,6 +342,22 @@ def test_plot_heatmap_view(self):
self.assertHeatmap(resp)
self.assertNav(resp)

def test_pan_genome_view(self):
resp = self.client.get(f"/pan_genome/{self.view_type}")
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'chlamdb/pan_genome.html')
self.assertEqual(self.view_type, resp.context["type"])
self.assertPageTitle(resp, self.page_title)
self.assertNoRarefactionPlot(resp)

resp = self.client.post(f"/pan_genome/{self.view_type}",
data={"targets": ["0", "1"]})
self.assertEqual(200, resp.status_code)
self.assertTemplateUsed(resp, 'chlamdb/pan_genome.html')
self.assertEqual(self.view_type, resp.context["type"])
self.assertPageTitle(resp, self.page_title)
self.assertRarefactionPlot(resp)


class TestPfamViews(SimpleTestCase, ComparisonViewsTestMixin):

Expand Down
1 change: 1 addition & 0 deletions webapp/templates/chlamdb/extract_nav_tabs_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<li class={% if active_tab == "venn" %}"active"{%endif%}><a href="{% url 'venn_amr' %}">Venn</a></li>
<li class={% if active_tab == "comp" %}"active"{%endif%}><a href="{% url 'amr_comparison' %}">Presence/absence table</a></li>
<li class={% if active_tab == "heat" %}"active"{%endif%}><a href="{% url 'plot_heatmap' 'amr' %}">Heatmaps</a></li>
<li class={% if active_tab == "pan" %}"active"{%endif%}><a href="{% url 'pan_genome' 'amr' %}">Accumulation/rarefaction plot </a></li>
</ul>
</nav>
{% endif %}
Expand Down
150 changes: 78 additions & 72 deletions webapp/templates/chlamdb/pan_genome.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,95 @@
{% include "chlamdb/header.html" %}
</head>
<script src="https://d3js.org/d3.v4.js"></script>

<div class="container-fluid" id="main_container">
<div class="row">
<div id="wrapper">
<div id="page-content-wrapper">
<div class="row">
<div class="col-lg-12">
{% include "chlamdb/menu.html" %}
{% include "chlamdb/extract_nav_tabs_template.html" with type=type active_tab="pan" %}

<br>
<p class="page-title"><b>Accumulation/rarefaction plot of
{% if type == 'pfam' %}
Pfam domains
{% elif type == 'cog' %}
COG categories
{% elif type == 'interpro'%}
Interpro Entries.
{% elif type == 'EC' %}
EC numbers. Based on PRIAM data. Partial EC are not considered.
{% elif type == 'ko' %}
Kegg orthologous groups (KO)
{% elif type == 'orthology' %}
orthologous groups
{% endif %}</b><a href="https://zdb.readthedocs.io/en/latest/tutorial/website.html#comparisons" id="show-option"
target="_blank" ><i class="fab fa-info-circle " style="size: 5em;" ></i></a></p>
<div id="page-content-wrapper">
<div class="row">
<div class="col-lg-12">
{% include "chlamdb/menu.html" %}
{% include "chlamdb/extract_nav_tabs_template.html" with type=type active_tab="pan" %}

<br>
<p class="page-title">
<b>
Accumulation/rarefaction plot of
{% if type == 'pfam' %}
Pfam domains
{% elif type == 'cog' %}
COG categories
{% elif type == 'interpro'%}
Interpro Entries.
{% elif type == 'EC' %}
EC numbers. Based on PRIAM data. Partial EC are not considered.
{% elif type == 'ko' %}
Kegg orthologous groups (KO)
{% elif type == 'orthogroup' %}
orthologous groups
{% elif type == 'amr' %}
Antimicrobial resistance genes
{% endif %}
</b>
<a href="https://zdb.readthedocs.io/en/latest/tutorial/website.html#comparisons" id="show-option" target="_blank" >
<i class="fab fa-info-circle " style="size: 5em;" ></i>
</a>
</p>



<form action='{% url "pan_genome" type %}' method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
<form action='{% url "pan_genome" type %}' method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>


</div>
</div>
{% if envoi %}
<div class="row" style="padding-top:30px; background-color: rgba(245, 245, 245, 0.986); margin-top: 2em">
<div class="panel panel-success" style="margin: 1em;" >
<div class="panel-heading" style="width:100%">
<h5 class="panel-title">Help to interpret the results</h5>
</div>

{% if envoi %}
<div class="row" style="padding-top:30px; background-color: rgba(245, 245, 245, 0.986); margin-top: 2em">
<div class="panel panel-success" style="margin: 1em;" >
<div class="panel-heading" style="width:100%">
<h5 class="panel-title">Help to interpret the results
</div>
<p style="margin: 10px 10px 10px 10px">
This plot shows the relationship between the number of {{type_txt}} and the number of genomes considered.

<br>The <span style="color: #69b3a2;"><b>green</b></span> and the <span style="color: #5499c7;"><b>blue</b></span> lines are both based on a single random permutation of the selected genomes. The <span style="color: #69b3a2;"><b>green</b></span> line represent the total number of {{type_txt}} present in the first n genomes of the permutation. The <span style="color: #5499c7;"><b>blue</b></span> represents the number of {{type_txt}} shared by the first n genomes of the permutation.

<br>The <span style="color:#FF6347;"><b>red</b></span> line shows the number of {{type_txt}} present in exactly n genomes. This plot do not depend on a permutation and it is possible to click on the points to get more detailed information.
<br>

</p>
</div>
<p style="margin: 10px 10px 10px 10px">
This plot shows the relationship between the number of {{type_txt}} and the number of genomes considered.
<br>
The <span style="color: #69b3a2;"><b>green</b></span> and the <span style="color: #5499c7;"><b>blue</b></span> lines are both based on a single random permutation of the selected genomes. The <span style="color: #69b3a2;"><b>green</b></span> line represent the total number of {{type_txt}} present in the first n genomes of the permutation. The <span style="color: #5499c7;"><b>blue</b></span> represents the number of {{type_txt}} shared by the first n genomes of the permutation.
<br>
The <span style="color:#FF6347;"><b>red</b></span> line shows the number of {{type_txt}} present in exactly n genomes. This plot do not depend on a permutation and it is possible to click on the points to get more detailed information.
<br>
</p>
</div>


<div class="tab-pane active" id="tab1" style="margin: 1em;">
<div class="panel panel-success" style="width:100%; top: 200px; ">
<div style="width: 1000px;" id="rarefaction_plot">
</div>

<div id="plot_type" style="display: flex; justify-content: space-around; width: 900px;">
<div>
<input style="margin-left" value="pangenome" type="radio" id="pangenome" name="plot_type" checked>
<label for="pangenome">Total number of {{type_txt}}</label>
</div>

<div>
<input style="center" type="radio" value="coregenome" id="coregenome" name="plot_type">
<label for="coregenome">Number of shared {{type_txt}}</label>
</div>

<div>
<input style="margin-right" type="radio" value="ortho_distrib" id="ortho_distrib" name="plot_type">
<label for="ortho_distrib">Distribution of {{type_txt}}</label>
</div>
</div>
</div>
</div>

<div id="download_svg">
</div>

{% endif %}
<div class="tab-pane active" id="tab1" style="margin: 1em;">
<div class="panel panel-success" style="width:100%; top: 200px; ">
<div style="width: 1000px;" id="rarefaction_plot"></div>

<div id="plot_type" style="display: flex; justify-content: space-around; width: 900px;">
<div>
<input style="margin-left" value="pangenome" type="radio" id="pangenome" name="plot_type" checked>
<label for="pangenome">Total number of {{type_txt}}</label>
</div>

<div>
<input style="center" type="radio" value="coregenome" id="coregenome" name="plot_type">
<label for="coregenome">Number of shared {{type_txt}}</label>
</div>

<div>
<input style="margin-right" type="radio" value="ortho_distrib" id="ortho_distrib" name="plot_type">
<label for="ortho_distrib">Distribution of {{type_txt}}</label>
</div>
</div>
</div>
</div>

<div id="download_svg"></div>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def safe_replace(string, search_string, replace_string):
'COG Ortholog': ['fam_cog'],
'Comparisons: Antimicrobial Resistance': [
'amr_comparison', 'index_comp_amr', 'entry_list_amr', 'extract_amr',
'plot_heatmap_amr', 'venn_amr'],
'plot_heatmap_amr', 'pan_genome_amr', 'venn_amr'],
'Comparisons: Clusters of Orthologous groups (COGs)': [
'cog_barchart', 'index_comp_cog', 'cog_phylo_heatmap',
'cog_comparison', 'entry_list_cog', 'extract_cog', 'heatmap_COG',
Expand Down
8 changes: 4 additions & 4 deletions webapp/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ class ComparisonIndexView(View, ComparisonViewMixin):
def boxes(self):
boxes = ["entry-list", "extraction", "venn",
"tabular-comparison", "heatmap", "accumulation-rarefaction"]
if self.comp_type == "amr":
boxes = ["entry-list", "extraction", "venn",
"tabular-comparison", "heatmap"]
elif self.comp_type == "orthogroup":
if self.comp_type == "orthogroup":
boxes.remove("entry-list")
elif self.comp_type == "ko":
boxes.append("barcharts")
Expand Down Expand Up @@ -2060,6 +2057,9 @@ def pan_genome(request, type):
elif type == "pfam":
df_hits = db.get_pfam_hits(taxids, search_on="taxid")
type_txt = "PFAM domains"
elif type == "amr":
df_hits = db.get_amr_hit_counts(taxids, search_on="taxid")
type_txt = "AMR genes"
else:
form = venn_form_class()
return render(request, 'chlamdb/pan_genome.html', my_locals(locals()))
Expand Down