Skip to content
GitLab
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
7f863a0d
Commit
7f863a0d
authored
Dec 09, 2019
by
Kenzo-Hugo Hillion
♻
Browse files
add eggnog line parser
parent
a68b6d27
Changes
3
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/common/utils/parsers/__init__.py
View file @
7f863a0d
from
.eggnog
import
EggNogAnnotationLineParser
# noqa
from
.igc
import
IGCLineParser
# noqa
from
.kegg
import
KEGGLineParser
# noqa
from
.ncbi_taxonomy
import
NCBITaxonomyLineParser
# noqa
backend/metagenedb/common/utils/parsers/eggnog.py
0 → 100644
View file @
7f863a0d
import
logging
_LOGGER
=
logging
.
getLogger
(
__name__
)
class
EggNogAnnotationLineParser
(
object
):
@
staticmethod
def
ko_list
(
line
):
"""
Parse line from Eggnog annotations.tsv file to return organized dict
"""
try
:
elements
=
line
.
split
(
'
\t
'
)
return
{
'functional_category'
:
elements
[
2
],
'function_id'
:
elements
[
1
],
'name'
:
elements
[
3
],
}
except
Exception
:
_LOGGER
.
error
(
f
"Could not parse:
{
line
.
rstrip
()
}
. Are you sure it comes from eggnog annotations.tsv?"
)
raise
backend/metagenedb/common/utils/parsers/test_eggnog.py
0 → 100644
View file @
7f863a0d
from
unittest
import
TestCase
from
metagenedb.common.utils.parsers
import
EggNogAnnotationLineParser
class
TestEggNogAnnotationLineParser
(
TestCase
):
def
test_ko_list
(
self
):
ko_line
=
"1
\t
28H54
\t
K
\t
translational termination"
expected_dict
=
{
'function_id'
:
"28H54"
,
'name'
:
"translational termination"
,
'functional_category'
:
"K"
}
test_dict
=
EggNogAnnotationLineParser
.
ko_list
(
ko_line
)
self
.
assertDictEqual
(
test_dict
,
expected_dict
)
def
test_ko_list_wrong_format
(
self
):
ko_line
=
"This is a wrong line format, with; information and tab"
with
self
.
assertRaises
(
Exception
)
as
context
:
# noqa
EggNogAnnotationLineParser
.
ko_list
(
ko_line
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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