Skip to content

Commit

Permalink
Added pangenomic class column to the locus tag table on the genome pa…
Browse files Browse the repository at this point in the history
…ge and added phylogroup info to the info panel.
  • Loading branch information
pascalaldo committed Dec 20, 2024
1 parent 1c5737c commit aee829e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
52 changes: 52 additions & 0 deletions gene_function/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,58 @@
class GeneInfo:
objects = database.MongoDBObjects("pankb_gene_info")

def get_gene_info_and_pangenomic_class_pipeline(gene_match):
return [
{"$match": gene_match},
{
"$lookup": {
"from": "pankb_gene_annotations",
"let": {
"q_gene": "$gene",
"q_pangenome_analysis": "$pangenome_analysis",
},
"pipeline": [
{
"$match": {
"$expr": {
"$and": [
{"$eq": ["$gene", "$$q_gene"]},
{
"$eq": [
"$pangenome_analysis",
"$$q_pangenome_analysis",
]
},
]
}
}
}
],
"as": "pangenomic_class",
}
},
{
"$set": {
"pangenomic_class": {
"$ifNull": [
{"$arrayElemAt": ["$pangenomic_class.pangenomic_class", 0]},
"-",
]
}
}
},
]

def get_gene_info_and_pangenomic_class(genome_match, projection=None):
pipeline = GeneInfo.get_gene_info_and_pangenomic_class_pipeline(genome_match)
if isinstance(projection, list):
projection = {p: 1 for p in projection}
if not "_id" in projection:
projection["_id"] = 0
if projection:
pipeline.append({"$project": projection})
return GeneInfo.objects.aggregate(pipeline)


# Model for the Genome Info table content
class GenomeInfo:
Expand Down
5 changes: 3 additions & 2 deletions gene_function/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ def genome_info(request):
genome_info_dict = _get_genome_and_isolation_info(filter_params)

# Obtain the gene info: ----
gene_info = GeneInfo.objects.find(
gene_info = GeneInfo.get_gene_info_and_pangenomic_class(
{"pangenome_analysis": species, "genome_id": genome_id},
[
"gene",
"locus_tag",
"pangenome_analysis",
"genome_id",
"pangenomic_class",
"original_locus_tag",
"original_gene",
"original_exact_match",
Expand All @@ -229,7 +230,7 @@ def genome_info(request):
"end_position",
"nucleotide_seq",
"aminoacid_seq",
],
]
)
gene_info = list(gene_info)

Expand Down
5 changes: 5 additions & 0 deletions templates/components/panel_locustags_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<th class="text-center">Genome ID</th>
{% else %}
<th class="text-center">Gene</th>
<th class="text-center">Class</th>
{% endif %}
<th class="text-center">Protein</th>
<th class="text-center">Start Position</th>
Expand All @@ -46,6 +47,7 @@
<th class="text-center">Genome ID</th>
{% else %}
<th class="text-center">Gene</th>
<th class="text-center">Class</th>
{% endif %}
<th class="text-center">Protein</th>
<th class="text-center">Start Position</th>
Expand Down Expand Up @@ -116,6 +118,9 @@
return '<a href="{% url 'gene_info' %}?species={{request.GET.species|safe}}&gene=' + encodeURIComponent(data) + '">' + data + '</a>';
},
},
{
data: 'pangenomic_class',
},
{% endif %}
{
data: 'protein',
Expand Down
5 changes: 4 additions & 1 deletion templates/gene_function/info_panel_genome_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ <h6 class="card-subtitle mb-2 text-body-secondary display-6 pt-1"><a style="colo
<dl class="row g-1 fs-3">
<dt class="col-sm-12">Strain (<a href="https://www.ncbi.nlm.nih.gov/datasets/genome/{{dataGenome.genome_id|safe}}" target="_blank">NCBI</a>)</dt>
<dd class="col-sm-12">{{ dataGenome.strain }}</dd>

<dt class="col-sm-6">Phylogroup</dt>
<dd class="col-sm-6">{{ dataGenome.phylo_group }}</dd>

<dt class="col-sm-12">Isolation Source</dt>
<dd class="col-sm-12">{{ dataGenome.isolation_source }}</dd>
<dt class="col-sm-12">Isolation Source Categories</dt>
<dd class="col-sm-12">
<ol class="breadcrumb" style="--bs-breadcrumb-divider: '>';">
{% for category in dataGenome.iso_cat %}
Expand Down

0 comments on commit aee829e

Please sign in to comment.