diff --git a/src/parser/parser.py b/src/parser/parser.py index 05f6b1ea17bd80be509ca3dd43faa44adb6b8838..58cbde1232df4d68923caefdbc8fdf80e96eed95 100755 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -26,9 +26,12 @@ def replicon_parser( replicon_data ): if fields[0] in replicon_db: raise KeyError( "duplicate replicon:" + fields[0]) else: - replicon_db[ fields[0] ] = Replicon_info( fields[0] , int(fields[1]) , fields[2] , fields[3].split('; ') , fields[4]) - #remove ending dot from the last term of taxonnomy - if( replicon_db[ fields[0] ].taxonomy[-1].endswith('.') ): + try: + replicon_db[ fields[0] ] = Replicon_info( fields[0] , int(fields[1]) , fields[2] , fields[3].split('; ') , fields[4]) + 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] return replicon_db @@ -43,7 +46,7 @@ def system_parser( system_data ): """ system_db = {} 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 : for line in system_file: @@ -68,6 +71,8 @@ def system_parser( system_data ): float(fields[12].replace( ',' , '.')) if fields[12] != '-' else None ,# coverage_profile int(fields[13]) if fields[13] != '-' else None ,# match_begin 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 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_ from couchdbkit.client import Server from couchdbkit.exceptions import ResourceNotFound from couchdbkit.resource import CouchdbResource - from urllib2 import urlparse + from restkit import Resource, BasicAuth + import restkit.errors - result = urlparse.urlparse( server_uri ) - if result.scheme == 'http': - 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 ) ) + auth = BasicAuth(user , passwd ) + resource = CouchdbResource( server_uri , filters=[auth]) 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.sort() for syst_code in system_codes: