Mercurial > repos > galaxyp > unipept
comparison unipept.py @ 1:b65ee881ca64 draft
planemo upload for repository http://unipept.ugent.be/apidocs commit e91b0fe16bf468b34884508652359b91847d1f95
author | galaxyp |
---|---|
date | Tue, 22 Jan 2019 20:58:28 -0500 |
parents | b33376bf2290 |
children | dca8a1fe0bf3 |
comparison
equal
deleted
inserted
replaced
0:b33376bf2290 | 1:b65ee881ca64 |
---|---|
181 def best_match(peptide,matches): | 181 def best_match(peptide,matches): |
182 if not matches: | 182 if not matches: |
183 return None | 183 return None |
184 elif len(matches) == 1: | 184 elif len(matches) == 1: |
185 return matches[0].copy() | 185 return matches[0].copy() |
186 else: | 186 elif 'taxon_rank' in matches[0]: |
187 # find the most specific match (peptide is always the first column order field) | 187 # find the most specific match (peptide is always the first column order field) |
188 for col in reversed(pept2lca_extra_column_order[1:]): | 188 for col in reversed(pept2lca_extra_column_order[1:]): |
189 col_id = col+"_id" if options.extra else col | 189 col_id = col+"_id" if options.extra else col |
190 for match in matches: | 190 for match in matches: |
191 if 'taxon_rank' in match and match['taxon_rank'] == col: | 191 if 'taxon_rank' in match and match['taxon_rank'] == col: |
192 return match.copy() | 192 return match.copy() |
193 if col_id in match and match[col_id]: | 193 if col_id in match and match[col_id]: |
194 return match.copy() | 194 return match.copy() |
195 else: | |
196 return sorted(matches, key=lambda x: len(x['peptide']))[-1].copy() | |
195 return None | 197 return None |
196 | 198 |
197 def get_taxon_json(resp): | 199 def get_taxon_json(resp): |
198 found_keys = set() | 200 found_keys = set() |
199 for i,pdict in enumerate(resp): | 201 for i,pdict in enumerate(resp): |
278 for ec in pdict['ec']: | 280 for ec in pdict['ec']: |
279 child = None | 281 child = None |
280 protein_count = ec['protein_count'] | 282 protein_count = ec['protein_count'] |
281 ec_number = ec['ec_number'] | 283 ec_number = ec['ec_number'] |
282 for ec_id in get_ids(ec_number): | 284 for ec_id in get_ids(ec_number): |
283 child = get_node(ec_id,ec_id,child,seq) | 285 ec_name = str(ec_id) |
286 ## if len(ec_id) == 3: | |
287 ## ec_name = '%s\n%s\n%s' %(str(ec_id), ec_name_dict[str(ec_id[0])], ec_name_dict[str(ec_id)]) | |
288 child = get_node(ec_id,ec_name,child,seq) | |
284 seq = None | 289 seq = None |
285 if child: | 290 if child: |
286 get_node(0,'-.-.-.-',child,None) | 291 get_node(0,'-.-.-.-',child,None) |
287 return root | 292 return root |
288 | 293 |
497 post_data.append(("extra","true")) | 502 post_data.append(("extra","true")) |
498 if options.domains: | 503 if options.domains: |
499 post_data.append(("domains","true")) | 504 post_data.append(("domains","true")) |
500 post_data += [('input[]', x) for x in trypticPeptides[idx[i]:idx[i+1]]] | 505 post_data += [('input[]', x) for x in trypticPeptides[idx[i]:idx[i+1]]] |
501 if options.debug: print >> sys.stdout, "post_data: %s\n" % (str(post_data)) | 506 if options.debug: print >> sys.stdout, "post_data: %s\n" % (str(post_data)) |
502 params = '&'.join(['%s=%s' % (i[0],i[1]) for i in post_data]) | 507 headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'} |
503 #headers = {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'} | 508 ## headers = {'Accept': 'application/json'} |
504 headers = {'Accept': 'application/json'} | |
505 url = '%s/%s' % (options.url.rstrip('/'),options.unipept) | 509 url = '%s/%s' % (options.url.rstrip('/'),options.unipept) |
506 if options.get: | 510 if options.get: |
511 params = '&'.join(['%s=%s' % (i[0],i[1]) for i in post_data]) | |
507 url = '%s.json?%s' % (url,params) | 512 url = '%s.json?%s' % (url,params) |
508 req = urllib2.Request( url ) | 513 req = urllib2.Request( url ) |
509 else: | 514 else: |
510 url = '%s.json' % (url) | 515 url = '%s.json' % (url) |
511 req = urllib2.Request( url, headers = headers, data = urllib.urlencode(post_data) ) | 516 req = urllib2.Request( url, headers = headers, data = urllib.urlencode(post_data) ) |
544 else: | 549 else: |
545 for key,match in keyToMatch.iteritems(): | 550 for key,match in keyToMatch.iteritems(): |
546 match['tryptic_peptide'] = match['peptide'] | 551 match['tryptic_peptide'] = match['peptide'] |
547 match['peptide'] = peptide | 552 match['peptide'] = peptide |
548 peptideMatches.append(match) | 553 peptideMatches.append(match) |
549 elif options.unipept in ['pept2lca']: | 554 elif options.unipept in ['pept2lca', 'peptinfo']: |
550 ## should be one response per trypticPeptide for pep2lca | 555 ## should be one response per trypticPeptide for pep2lca |
551 respMap = {v['peptide']:v for v in unipept_resp} | 556 respMap = {v['peptide']:v for v in unipept_resp} |
552 ## map resp back to peptides | 557 ## map resp back to peptides |
553 for peptide in peptides: | 558 for peptide in peptides: |
554 matches = list() | 559 matches = list() |