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
fe09bec9
Commit
fe09bec9
authored
Dec 10, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
Handle eggnog with multiple functional categories
parent
f0fb2d72
Changes
5
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/apps/catalog/admin/function.py
View file @
fe09bec9
...
...
@@ -25,7 +25,7 @@ class EggNogAdmin(admin.ModelAdmin):
def
get_functional_categories
(
self
,
obj
):
if
obj
.
functional_categories
.
all
():
return
","
.
join
([
str
(
f
)
for
f
in
obj
.
functional_categories
.
all
()])
return
",
"
.
join
([
str
(
f
)
for
f
in
obj
.
functional_categories
.
all
()])
return
'-'
get_functional_categories
.
short_description
=
'Functional categories'
...
...
backend/metagenedb/apps/catalog/management/commands/create_update_eggnog.py
View file @
fe09bec9
...
...
@@ -27,12 +27,11 @@ class ImportEggNog(object):
all_categories
=
EggNogFunctionalCategory
.
objects
.
all
()
if
not
all_categories
:
raise
Exception
(
"You need to create Functional categories first."
)
self
.
functional_cat
=
{
cat
.
category_id
:
cat
for
cat
in
all_categories
}
self
.
functional_cat
_instances
=
{
cat
.
category_id
:
cat
for
cat
in
all_categories
}
def
link_functional_category
(
self
,
eggnog_dict
):
cat_key
=
eggnog_dict
.
get
(
'functional_category'
,
'S'
)
category
=
self
.
functional_cat
.
get
(
cat_key
)
eggnog_dict
.
update
({
'functional_category'
:
category
})
def
add_functional_categories
(
self
,
eggnog
,
functional_category_keys
):
for
key
in
functional_category_keys
:
eggnog
.
functional_categories
.
add
(
self
.
functional_cat_instances
[
key
])
def
load_all
(
self
,
test
=
False
):
self
.
_build_functional_category_dict
()
...
...
@@ -40,8 +39,9 @@ class ImportEggNog(object):
with
open
(
self
.
annotation_file
,
"r"
)
as
file
:
for
line
in
file
:
eggnog_dict
=
self
.
eggnog_parser
.
get_dict
(
line
)
self
.
link_
functional_category
(
eggnog_dict
)
functional_category
_keys
=
eggnog_dict
.
pop
(
'functional_categories'
)
# link later
payload
=
{
k
:
v
for
k
,
v
in
eggnog_dict
.
items
()
if
v
!=
""
}
eggnog
=
None
try
:
eggnog
=
EggNog
(
**
payload
)
eggnog
.
full_clean
()
...
...
@@ -66,6 +66,9 @@ class ImportEggNog(object):
self
.
skipped_errors
.
append
(
validation_error
)
self
.
skipped_ids
.
append
(
payload
.
get
(
'function_id'
))
self
.
skipped_count
+=
1
if
eggnog
is
not
None
:
self
.
add_functional_categories
(
eggnog
,
functional_category_keys
)
eggnog
.
save
()
self
.
processed_count
+=
1
if
self
.
processed_count
%
1000
==
0
:
logger
.
info
(
"%s/%s EggNog processed so far..."
,
self
.
processed_count
,
self
.
total_eggnog_nb
)
...
...
backend/metagenedb/common/utils/parsers/eggnog.py
View file @
fe09bec9
...
...
@@ -13,7 +13,7 @@ class EggNogAnnotationLineParser(object):
try
:
elements
=
line
.
split
(
'
\t
'
)
return
{
'functional_categor
y
'
:
list
(
elements
[
2
]),
'functional_categor
ies
'
:
list
(
elements
[
2
]),
'function_id'
:
elements
[
1
],
'name'
:
elements
[
3
].
rstrip
().
split
(
'.'
)[
0
],
}
...
...
backend/metagenedb/common/utils/parsers/test_eggnog.py
View file @
fe09bec9
...
...
@@ -10,7 +10,7 @@ class TestEggNogAnnotationLineParser(TestCase):
expected_dict
=
{
'function_id'
:
"28H54"
,
'name'
:
"translational termination"
,
'functional_categor
y
'
:
[
"K"
]
'functional_categor
ies
'
:
[
"K"
]
}
test_dict
=
EggNogAnnotationLineParser
.
get_dict
(
ko_line
)
self
.
assertDictEqual
(
test_dict
,
expected_dict
)
...
...
@@ -20,7 +20,7 @@ class TestEggNogAnnotationLineParser(TestCase):
expected_dict
=
{
'function_id'
:
"28H50"
,
'name'
:
""
,
'functional_categor
y
'
:
[
"S"
]
'functional_categor
ies
'
:
[
"S"
]
}
test_dict
=
EggNogAnnotationLineParser
.
get_dict
(
ko_line
)
self
.
assertDictEqual
(
test_dict
,
expected_dict
)
...
...
@@ -30,7 +30,7 @@ class TestEggNogAnnotationLineParser(TestCase):
expected_dict
=
{
'function_id'
:
"28H50"
,
'name'
:
"Glucose-responsive transcription factor that regulates expression of several glucose transporter (HXT) genes in response to glucose"
,
# noqa
'functional_categor
y
'
:
[
"S"
]
'functional_categor
ies
'
:
[
"S"
]
}
test_dict
=
EggNogAnnotationLineParser
.
get_dict
(
ko_line
)
self
.
assertDictEqual
(
test_dict
,
expected_dict
)
...
...
@@ -40,7 +40,7 @@ class TestEggNogAnnotationLineParser(TestCase):
expected_dict
=
{
'function_id'
:
"28H54"
,
'name'
:
"translational termination"
,
'functional_categor
y
'
:
[
"K"
,
"S"
]
'functional_categor
ies
'
:
[
"K"
,
"S"
]
}
test_dict
=
EggNogAnnotationLineParser
.
get_dict
(
ko_line
)
self
.
assertDictEqual
(
test_dict
,
expected_dict
)
...
...
backend/scripts/populate_db/import_igc_data.py
View file @
fe09bec9
...
...
@@ -5,7 +5,13 @@ import os
import
sys
from
itertools
import
islice
from
bioapi
import
MetageneDBCatalogFunctionAPI
,
MetageneDBCatalogGeneAPI
,
MetageneDBCatalogTaxonomyAPI
from
bioapi
import
(
MetageneDBCatalogFunctionAPI
,
MetageneDBCatalogGeneAPI
,
MetageneDBCatalogTaxonomyAPI
,
MetageneDBCatalogKeggOrthologyAPI
,
MetageneDBCatalogEggNogAPI
)
from
requests.exceptions
import
HTTPError
from
slugify
import
slugify
...
...
@@ -19,6 +25,8 @@ class ImportIGCGenes(object):
METAGENEDB_GENE_API
=
MetageneDBCatalogGeneAPI
METAGENEDB_TAXONOMY_API
=
MetageneDBCatalogTaxonomyAPI
METAGENEDB_FUNCTION_API
=
MetageneDBCatalogFunctionAPI
METAGENEDB_KEGG_API
=
MetageneDBCatalogKeggOrthologyAPI
METAGENEDB_EGGNOG_API
=
MetageneDBCatalogEggNogAPI
PHYLUM_COL
=
'taxo_phylum'
GENUS_COL
=
'taxo_genus'
...
...
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