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
b1fac06e
Commit
b1fac06e
authored
Sep 15, 2020
by
Kenzo-Hugo Hillion
♻
Browse files
add property to Taxonomy to retrieve one line taxonomy description
parent
8c35c9e0
Pipeline
#37427
failed with stages
in 17 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/apps/catalog/factory/taxonomy.py
View file @
b1fac06e
...
...
@@ -40,6 +40,8 @@ class DbGenerator:
rank
=
rank
,
parent
=
getattr
(
self
,
"last_tax"
,
None
)
)
else
:
self
.
last_tax
=
models
.
Taxonomy
.
objects
.
get
(
tax_id
=
desc
[
'tax_id'
])
self
.
created_ids
.
add
(
desc
[
'tax_id'
])
self
.
last_tax
.
build_hierarchy
()
...
...
backend/metagenedb/apps/catalog/management/commands/create_light_db.py
View file @
b1fac06e
...
...
@@ -11,6 +11,7 @@ from metagenedb.apps.catalog.models import (
from
metagenedb.apps.catalog.management.commands.compute_stats
import
(
ComputeStatistics
,
ComputeCounts
,
ComputeGeneLength
,
ComputeTaxonomyRepartition
,
ComputeTaxonomyPresence
)
from
metagenedb.apps.catalog.management.commands.compute_stats
import
clean_db
as
clean_db_stats
logging
.
basicConfig
(
format
=
'[%(asctime)s] %(levelname)s:%(name)s:%(message)s'
)
logger
=
logging
.
getLogger
()
...
...
@@ -37,7 +38,7 @@ def create_genes_db():
def
compute_stats
():
ComputeStatistics
(
'all'
).
clean_db
()
clean_db
_stats
()
for
gene_source
in
[
'all'
,
'virgo'
,
'igc'
]:
ComputeCounts
(
gene_source
).
all
()
ComputeGeneLength
(
gene_source
).
all
()
...
...
backend/metagenedb/apps/catalog/models/statistics.py
View file @
b1fac06e
from
django.db
import
models
from
django.contrib.postgres.fields
import
JSONField
class
Statistics
(
models
.
Model
):
...
...
@@ -8,7 +7,7 @@ class Statistics(models.Model):
"""
stats_id
=
models
.
SlugField
(
max_length
=
400
,
db_index
=
True
,
unique
=
True
)
body
=
JSONField
()
body
=
models
.
JSONField
()
class
Meta
:
verbose_name_plural
=
"Statistics"
backend/metagenedb/apps/catalog/models/taxonomy.py
View file @
b1fac06e
from
django.db
import
models
from
django.contrib.postgres.fields
import
JSONField
class
Taxonomy
(
models
.
Model
):
...
...
@@ -52,7 +51,7 @@ class Taxonomy(models.Model):
on_delete
=
models
.
SET_NULL
,
null
=
True
,
blank
=
True
,
)
hierarchy
=
JSONField
(
null
=
True
)
hierarchy
=
models
.
JSONField
(
null
=
True
)
def
__str__
(
self
):
return
f
"
{
self
.
name
}
"
...
...
@@ -73,6 +72,32 @@ class Taxonomy(models.Model):
self
.
save
()
return
hierarchy
def
_compute_one_line_detailed_taxonomy
(
self
)
->
str
:
default_item
=
{
'name'
:
''
}
if
self
.
hierarchy
is
None
:
self
.
build_hierarchy
()
if
self
.
hierarchy
.
get
(
'species'
,
None
)
is
None
:
s
=
''
else
:
s
=
self
.
hierarchy
.
get
(
'species'
)[
'name'
].
split
()[
-
1
]
return
"k__{k}; p__{p}; c__{c}; o__{o}; f__{f}; g__{g}; s__{s}"
.
format
(
k
=
self
.
hierarchy
.
get
(
'kingdom'
,
self
.
hierarchy
.
get
(
'superkingdom'
,
default_item
))[
'name'
],
p
=
self
.
hierarchy
.
get
(
'phylum'
,
default_item
)[
'name'
],
c
=
self
.
hierarchy
.
get
(
'class'
,
default_item
)[
'name'
],
o
=
self
.
hierarchy
.
get
(
'order'
,
default_item
)[
'name'
],
f
=
self
.
hierarchy
.
get
(
'family'
,
default_item
)[
'name'
],
g
=
self
.
hierarchy
.
get
(
'genus'
,
default_item
)[
'name'
],
s
=
s
)
@
property
def
one_line_detailed_taxonomy
(
self
)
->
str
:
if
getattr
(
self
,
'_one_line_detailed_taxonomy'
,
None
)
is
None
:
self
.
_one_line_detailed_taxonomy
=
self
.
_compute_one_line_detailed_taxonomy
()
return
self
.
_one_line_detailed_taxonomy
class
Meta
:
verbose_name_plural
=
"Taxonomy"
ordering
=
[
'-tax_id'
]
Write
Preview
Markdown
is supported
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