Skip to content

Commit

Permalink
Add more info to taxon info page about gene objects. Closes #83
Browse files Browse the repository at this point in the history
  • Loading branch information
elserj committed Jul 19, 2024
1 parent a7a13dc commit 7de8da3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion taxon/templates/taxon/taxon.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<h2>Taxonomy: {{ taxon.name }}</h2>
<br>
{% if gene_count %}
<ul><h5>{{ gene_count }} genes in database</h5></ul>
<ul><h5>{{ gene_count }} objects in database</h5></ul>
{% endif %}
<div class="card">
<div class="card-body">
Expand Down Expand Up @@ -44,6 +44,18 @@ <h4 class="card-title">Parent</h4>
</div>
</div>
{% endif %}
{% if objects_by_type %}
<div class="card">
<div class="card-body">
<h4 class="card-title">Objects by type:</h4>
{% for type, count in objects_by_type.items %}
{{ type }} - {{ count }}
<br>
{% endfor %}

</div>
</div>
{% endif %}
</div>
<div id="taxon_padding" style="alignment: center; width: 15%"></div>
{% if latest_annotations %}
Expand Down
15 changes: 14 additions & 1 deletion taxon/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# views import
from curate.views import HomeView

# choices import
import curate.choices as choices


# forms import
from .forms import TaxonomyImportDocumentForm, TaxonomyAddForm

Expand Down Expand Up @@ -92,7 +96,16 @@ def get_context_data(self, **kwargs):
if gene_count > 0:
context['gene_count'] = gene_count

# Get the 10 latest unique genes that have annotations
# Get the gene objects by type with counts
objects_by_type = Gene.objects.filter(species=taxon).values('gene_type').annotate(Count('gene_type'))
object_type_dict = {e.value: e.name for e in choices.GeneType}
objects_with_label = {}
for obj in objects_by_type:
objects_with_label[object_type_dict[obj['gene_type']]] = obj['gene_type__count']
if objects_by_type.count() > 0:
context['objects_by_type'] = objects_with_label

# Get the 10 latest unique genes that have annotations
# First get the last 100, hopefully there are 10 unique genes in there
# If using postgres, could just use a "distinct(db_obj_id)" to the 1st query
# Since using mysql, have to manually find the 10 unique genes and do another query
Expand Down

0 comments on commit 7de8da3

Please sign in to comment.