Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
capsuledb
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gem
capsuledb
Commits
78395393
Commit
78395393
authored
9 years ago
by
Bertrand NÉRON
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into secreton-2
parents
21886a47
3a592942
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/parser/parser.py
+43
-46
43 additions, 46 deletions
src/parser/parser.py
with
43 additions
and
46 deletions
src/parser/parser.py
+
43
−
46
View file @
78395393
...
...
@@ -5,7 +5,7 @@ Created on 27 dec. 2011
@author: Bertrand Néron
"""
from
__future__
import
print_function
from
collections
import
namedtuple
from
couchdbkit.client
import
Server
from
couchdbkit.exceptions
import
ResourceNotFound
...
...
@@ -26,7 +26,7 @@ def replicon_parser(replicon_data):
:rtype: dict
"""
replicon_db
=
{}
Replicon_info
=
namedtuple
(
'
Replicon_info
'
,
'
name,
ncbi_id,
taxid, strain, taxonomy, type
'
)
Replicon_info
=
namedtuple
(
'
Replicon_info
'
,
(
'
name
'
,
'
taxid
'
,
'
strain
'
,
'
taxonomy
'
,
'
type
'
)
)
with
open
(
replicon_data
,
'
r
'
)
as
replicon_file
:
for
line
in
replicon_file
:
if
not
line
.
startswith
(
'
#
'
):
...
...
@@ -51,7 +51,6 @@ def replicon_parser(replicon_data):
raise
Exception
(
"
Error during parsing line : {0} : {1}
"
.
format
(
line
,
err
))
return
replicon_db
def
system_parser
(
system_data
):
"""
:param system_data: the path of secretion system information file
...
...
@@ -63,7 +62,9 @@ def system_parser(system_data):
System_info
=
namedtuple
(
'
System_info
'
,
'
code, predicted_system, system_status, replicon, genes
'
)
Gene
=
namedtuple
(
'
Gene
'
,
'
code, id, protein_length, strand, begin, end, match, score, i-evalue, coverage, match_begin, match_end, name, description
'
)
(
'
code
'
,
'
id
'
,
'
protein_length
'
,
'
strand
'
,
'
begin
'
,
'
end
'
,
'
match
'
,
'
score
'
,
'
i_evalue
'
,
'
coverage
'
,
'
match_begin
'
,
'
match_end
'
,
'
name
'
,
'
description
'
)
)
with
open
(
system_data
,
'
r
'
)
as
system_file
:
for
line
in
system_file
:
...
...
@@ -181,9 +182,9 @@ def fill_db(server_uri, db_name, user, passwd, replicon_db, system_db, force_upd
secretion_system
.
genes
=
genes
secreton_db
.
save_doc
(
secretion_system
,
force_update
=
force_update
)
if
__name__
==
'
__main__
'
:
from
optparse
import
OptionParser
,
OptionGroup
import
argparse
import
sys
import
getpass
...
...
@@ -197,60 +198,56 @@ if __name__ == '__main__':
parse a file containing replicon informations and a file containing system informations
and fill a couchDB data base with these informations
"""
parser
=
OptionParser
(
usage
=
usage
)
server_opt
=
OptionGroup
(
parser
,
"
Server Options
"
)
server_opt
.
add_option
(
"
-S
"
,
"
--server
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
server_url
"
,
help
=
"
the url of the couchDB server (with the port)
"
)
server_opt
.
add_option
(
"
-d
"
,
"
--database
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
db_name
"
,
help
=
"
the name of the data base
"
)
parser
.
add_option_group
(
server_opt
)
parsing_opt
=
OptionGroup
(
parser
,
"
Parsing Options
"
)
parsing_opt
.
add_option
(
"
-r
"
,
"
--replicon
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
replicon_path
"
,
help
=
"
the path to the replicon file to parse
"
)
parsing_opt
.
add_option
(
"
-s
"
,
"
--system
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
system_path
"
,
help
=
"
the path to the system secretion file to parse
"
)
parsing_opt
.
add_option
(
"
-f
"
,
"
--force_update
"
,
action
=
"
store_true
"
,
dest
=
"
force_update
"
,
default
=
False
,
help
=
""
)
parser
.
add_option_group
(
parsing_opt
)
parser
=
argparse
.
ArgumentParser
(
usage
=
usage
)
server_opt
=
parser
.
add_argument_group
(
title
=
"
Server Options
"
)
server_opt
.
add_argument
(
"
-S
"
,
"
--server
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
server_url
"
,
help
=
"
the url of the couchDB server (with the port)
"
)
server_opt
.
add_argument
(
"
-d
"
,
"
--database
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
db_name
"
,
help
=
"
the name of the data base
"
)
parsing_opt
=
parser
.
add_argument_group
(
title
=
"
Parsing Options
"
)
parsing_opt
.
add_argument
(
"
-r
"
,
"
--replicon
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
replicon_path
"
,
help
=
"
the path to the replicon file to parse
"
)
parsing_opt
.
add_argument
(
"
-s
"
,
"
--system
"
,
action
=
"
store
"
,
type
=
"
string
"
,
dest
=
"
system_path
"
,
help
=
"
the path to the system secretion file to parse
"
)
parsing_opt
.
add_argument
(
"
-f
"
,
"
--force_update
"
,
action
=
"
store_true
"
,
dest
=
"
force_update
"
,
default
=
False
,
help
=
"
insert document even if there is already a document with the same id (replace it)
"
)
options
,
args
=
parser
.
parse_args
()
if
not
options
.
server_url
:
print
>>
sys
.
stderr
,
"
You must specify a server url
"
print
(
"
You must specify a server url
"
,
file
=
sys
.
stderr
)
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
if
not
options
.
db_name
:
print
>>
sys
.
stderr
,
"
You must specify a data base name
"
print
(
"
You must specify a data base name
"
,
file
=
sys
.
stderr
)
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
if
not
options
.
replicon_path
:
print
>>
sys
.
stderr
,
"
You must specify the path to the replicon information file
"
print
(
"
You must specify the path to the replicon information file
"
,
file
=
sys
.
stderr
)
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
if
not
options
.
system_path
:
print
>>
sys
.
stderr
,
"
You must specify the path to the secretion system information file
"
print
(
"
You must specify the path to the secretion system information file
"
,
file
=
sys
.
stderr
)
parser
.
print_help
(
sys
.
stderr
)
sys
.
exit
(
1
)
replicon_db
=
replicon_parser
(
options
.
replicon_path
)
system_db
=
system_parser
(
options
.
system_path
)
...
...
@@ -261,11 +258,11 @@ if __name__ == '__main__':
fill_db
(
options
.
server_url
,
options
.
db_name
,
user
,
password
,
replicon_db
,
system_db
,
force_update
=
options
.
force_update
)
break
except
restkit
.
errors
.
Unauthorized
,
err
:
print
>>
sys
.
stderr
,
"
Bad authentication, try again
"
except
restkit
.
errors
.
Unauthorized
as
err
:
print
(
"
Bad authentication, try again
"
,
file
=
sys
.
stderr
)
try_again
+=
1
if
try_again
>
2
:
sys
.
exit
(
"
Authentication failure
"
)
except
Exception
,
err
:
print
>>
sys
.
stderr
,
err
print
(
err
,
file
=
sys
.
stderr
)
sys
.
exit
(
2
)
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment