Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
a37b5522
Commit
a37b5522
authored
Dec 16, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
Start having static stats table
parent
366e21e1
Pipeline
#20116
passed with stages
in 2 minutes and 31 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/api/catalog/urls.py
View file @
a37b5522
...
...
@@ -57,6 +57,7 @@ api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='k
api_router
.
register
(
r
'eggnogs'
,
views
.
EggNOGViewSet
,
basename
=
'eggnogs'
)
api_router
.
register
(
r
'genes'
,
views
.
GeneViewSet
,
basename
=
'genes'
)
api_router
.
register
(
r
'taxonomy'
,
views
.
TaxonomyViewSet
,
basename
=
'taxonomy'
)
api_router
.
register
(
r
'statistics'
,
views
.
StatisticsViewSet
,
basename
=
'statistics'
)
urlpatterns
=
[
...
...
backend/metagenedb/api/catalog/views/__init__.py
View file @
a37b5522
from
.function
import
EggNOGViewSet
,
KeggOrthologyViewSet
,
FunctionViewSet
# noqa
from
.gene
import
GeneViewSet
# noqa
from
.statistics
import
StatisticsViewSet
# noqa
from
.taxonomy
import
TaxonomyViewSet
# noqa
backend/metagenedb/api/catalog/views/statistics.py
0 → 100644
View file @
a37b5522
from
django.shortcuts
import
get_object_or_404
from
rest_framework
import
viewsets
from
rest_framework.response
import
Response
from
metagenedb.apps.catalog.models
import
Statistics
from
metagenedb.apps.catalog.serializers
import
StatisticsSerializer
class
StatisticsViewSet
(
viewsets
.
ViewSet
):
"""
A simple ViewSet for listing or retrieving statistics.
"""
lookup_field
=
'stats_id'
def
list
(
self
,
request
):
queryset
=
Statistics
.
objects
.
all
()
serializer
=
StatisticsSerializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
retrieve
(
self
,
request
,
stats_id
=
None
):
queryset
=
Statistics
.
objects
.
all
()
stats
=
get_object_or_404
(
queryset
,
stats_id
=
stats_id
)
serializer
=
StatisticsSerializer
(
stats
)
return
Response
(
serializer
.
data
)
backend/metagenedb/apps/catalog/migrations/0020_statistics.py
0 → 100644
View file @
a37b5522
# Generated by Django 3.0 on 2019-12-16 10:59
import
django.contrib.postgres.fields.jsonb
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'catalog'
,
'0019_get_back_original_name'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Statistics'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'stats_id'
,
models
.
SlugField
(
max_length
=
400
,
unique
=
True
)),
(
'body'
,
django
.
contrib
.
postgres
.
fields
.
jsonb
.
JSONField
()),
],
),
]
backend/metagenedb/apps/catalog/models/__init__.py
View file @
a37b5522
from
.function
import
EggNOG
,
EggNogFunctionalCategory
,
Function
,
KeggOrthology
# noqa
from
.gene
import
Gene
,
GeneFunction
# noqa
from
.statistics
import
Statistics
# noqa
from
.taxonomy
import
Taxonomy
# noqa
backend/metagenedb/apps/catalog/models/statistics.py
0 → 100644
View file @
a37b5522
from
django.db
import
models
from
django.contrib.postgres.fields
import
JSONField
class
Statistics
(
models
.
Model
):
"""
Model for the different static statistics that can be computed in a daily manner about the catalog
"""
stats_id
=
models
.
SlugField
(
max_length
=
400
,
db_index
=
True
,
unique
=
True
)
body
=
JSONField
()
backend/metagenedb/apps/catalog/operations/__init__.py
0 → 100644
View file @
a37b5522
backend/metagenedb/apps/catalog/operations/statistics.py
0 → 100644
View file @
a37b5522
from
metagenedb.apps.catalog.models
import
Gene
class
GeneStatistics
:
model
=
Gene
@
staticmethod
def
count_has_function
():
return
GeneStatistics
.
model
.
objects
.
filter
(
functions__isnull
=
False
).
distinct
().
count
()
@
staticmethod
def
count_has_taxonomy
():
return
GeneStatistics
.
model
.
objects
.
filter
(
taxonomy__isnull
=
False
).
count
()
backend/metagenedb/apps/catalog/serializers/__init__.py
View file @
a37b5522
from
.function
import
EggNOGSerializer
,
FunctionSerializer
,
KeggOrthologySerializer
# noqa
from
.gene
import
GeneSerializer
# noqa
from
.statistics
import
StatisticsSerializer
# noqa
from
.taxonomy
import
TaxonomySerializer
# noqa
backend/metagenedb/apps/catalog/serializers/statistics.py
0 → 100644
View file @
a37b5522
from
rest_framework
import
serializers
from
metagenedb.apps.catalog.models
import
Statistics
class
StatisticsSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Statistics
fields
=
(
'stats_id'
,
'body'
)
frontend/src/views/Stats.vue
View file @
a37b5522
...
...
@@ -169,10 +169,7 @@ export default {
});
},
getGeneCountsFunctions
()
{
axios
.
get
(
'
/api/catalog/v1/genes
'
,
{
params
:
{
no_functions
:
false
,
},
axios
.
get
(
'
/api/catalog/v1/statistics/genestatistics-count-has-function
'
,
{
headers
:
{
Accept
:
'
application/json
'
,
},
...
...
@@ -181,7 +178,7 @@ export default {
this
.
geneCountFunctions
=
{
class
:
"
secondary
"
,
icon
:
"
bar_chart
"
,
text
:
response
.
data
.
count
,
text
:
response
.
data
.
body
.
count
,
title
:
"
Functions annotation
"
,
};
})
...
...
@@ -260,9 +257,6 @@ export default {
doughnut
:
Doughnut
,
},
watch
:
{
// taxLevel(val) {
// this.getTaxoCounts();
// },
stopAt
(
val
)
{
this
.
getGeneLength
();
},
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment