Commit 8d44721b authored by Bertrand  NÉRON's avatar Bertrand NÉRON
Browse files

BUGFIX

fix authentication problem, use restkit BasicAuth flter

fix parser 
taxonomy are not always ending by a dot. the I test the last char of taxonomy before remove the last char

Improvement
add field description in named tuple Gene
parent 5324a8a6
...@@ -26,9 +26,12 @@ def replicon_parser( replicon_data ): ...@@ -26,9 +26,12 @@ def replicon_parser( replicon_data ):
if fields[0] in replicon_db: if fields[0] in replicon_db:
raise KeyError( "duplicate replicon:" + fields[0]) raise KeyError( "duplicate replicon:" + fields[0])
else: else:
replicon_db[ fields[0] ] = Replicon_info( fields[0] , int(fields[1]) , fields[2] , fields[3].split('; ') , fields[4]) try:
#remove ending dot from the last term of taxonnomy replicon_db[ fields[0] ] = Replicon_info( fields[0] , int(fields[1]) , fields[2] , fields[3].split('; ') , fields[4])
if( replicon_db[ fields[0] ].taxonomy[-1].endswith('.') ): except Exception, err:
raise Exception( "Error during parsing line :"+line )
#remove ending dot or semi-colon from the last term of taxonnomy
if( replicon_db[ fields[0] ].taxonomy[-1].endswith('.') or replicon_db[ fields[0] ].taxonomy[-1].endswith(';')):
replicon_db[ fields[0] ].taxonomy[-1] = replicon_db[ fields[0] ].taxonomy[-1][:-1] replicon_db[ fields[0] ].taxonomy[-1] = replicon_db[ fields[0] ].taxonomy[-1][:-1]
return replicon_db return replicon_db
...@@ -43,7 +46,7 @@ def system_parser( system_data ): ...@@ -43,7 +46,7 @@ def system_parser( system_data ):
""" """
system_db = {} system_db = {}
System_info = namedtuple('System_info', 'code, T3SS_family, replicon, genes' ) System_info = namedtuple('System_info', 'code, T3SS_family, replicon, genes' )
Gene = namedtuple( 'Gene', 'code, id, protein_length, strand, begin, end, match, full_score, e_value, best_domain_score, best_domain_evalue, c_value, coverage_profile, match_begin, match_end') Gene = namedtuple( 'Gene', 'code, id, protein_length, strand, begin, end, match, full_score, e_value, best_domain_score, best_domain_evalue, c_value, coverage_profile, match_begin, match_end, name, description')
with open( system_data , 'r' ) as system_file : with open( system_data , 'r' ) as system_file :
for line in system_file: for line in system_file:
...@@ -68,6 +71,8 @@ def system_parser( system_data ): ...@@ -68,6 +71,8 @@ def system_parser( system_data ):
float(fields[12].replace( ',' , '.')) if fields[12] != '-' else None ,# coverage_profile float(fields[12].replace( ',' , '.')) if fields[12] != '-' else None ,# coverage_profile
int(fields[13]) if fields[13] != '-' else None ,# match_begin int(fields[13]) if fields[13] != '-' else None ,# match_begin
int(fields[14]) if fields[14] != '-' else None ,# match_end int(fields[14]) if fields[14] != '-' else None ,# match_end
fields[18] if fields[18] else None, # name
fields[19] if fields[19] else None, # description
) )
if fields[16] in system_db: if fields[16] in system_db:
if gene.code in system_db[ fields[16] ]: if gene.code in system_db[ fields[16] ]:
...@@ -111,19 +116,20 @@ def fill_db( server_uri, db_name, user, passwd, replicon_db , system_db , force_ ...@@ -111,19 +116,20 @@ def fill_db( server_uri, db_name, user, passwd, replicon_db , system_db , force_
from couchdbkit.client import Server from couchdbkit.client import Server
from couchdbkit.exceptions import ResourceNotFound from couchdbkit.exceptions import ResourceNotFound
from couchdbkit.resource import CouchdbResource from couchdbkit.resource import CouchdbResource
from urllib2 import urlparse from restkit import Resource, BasicAuth
import restkit.errors
result = urlparse.urlparse( server_uri ) auth = BasicAuth(user , passwd )
if result.scheme == 'http': resource = CouchdbResource( server_uri , filters=[auth])
server_uri = result.netloc
elif result.scheme == '':
server_uri = path
else:
raise RuntimeError( "Unsupported protocol for server: "+result.scheme )
resource = CouchdbResource( "http://%s:%s@%s"%( user , passwd , server_uri ) )
server = Server( resource_instance= resource ) server = Server( resource_instance= resource )
secreton_db = server.get_or_create_db( db_name ) try:
secreton_db = server.get_or_create_db( db_name )
except restkit.errors.Unauthorized , err:
print "Bad Authentication"
sys.exit(1)
except Exception, err:
print >> sys.stderr , err
sys.exit(2)
system_codes = system_db.keys() system_codes = system_db.keys()
system_codes.sort() system_codes.sort()
for syst_code in system_codes: for syst_code in system_codes:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment