diff 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
line wrap: on
line diff
--- a/unipept.py	Wed Oct 24 14:45:18 2018 -0400
+++ b/unipept.py	Tue Jan 22 20:58:28 2019 -0500
@@ -183,7 +183,7 @@
       return None
     elif len(matches) == 1:
       return matches[0].copy()
-    else:
+    elif 'taxon_rank' in matches[0]:
       # find the most specific match (peptide is always the first column order field)
       for col in reversed(pept2lca_extra_column_order[1:]):
         col_id = col+"_id" if options.extra else col
@@ -192,6 +192,8 @@
             return match.copy()
           if col_id in match and match[col_id]:
             return match.copy()
+    else:
+      return sorted(matches, key=lambda x: len(x['peptide']))[-1].copy()
     return None
 
   def get_taxon_json(resp):
@@ -280,7 +282,10 @@
           protein_count = ec['protein_count']
           ec_number = ec['ec_number']
           for ec_id in get_ids(ec_number):
-            child = get_node(ec_id,ec_id,child,seq)
+            ec_name = str(ec_id)
+            ## if len(ec_id) == 3:
+            ##   ec_name = '%s\n%s\n%s' %(str(ec_id), ec_name_dict[str(ec_id[0])],  ec_name_dict[str(ec_id)])
+            child = get_node(ec_id,ec_name,child,seq)
             seq = None
           if child:
             get_node(0,'-.-.-.-',child,None)
@@ -499,11 +504,11 @@
       post_data.append(("domains","true"))
     post_data += [('input[]', x) for x in trypticPeptides[idx[i]:idx[i+1]]]
     if options.debug: print >> sys.stdout, "post_data: %s\n" % (str(post_data))
-    params = '&'.join(['%s=%s' % (i[0],i[1]) for i in post_data])
-    #headers = {'Content-Type': 'application/x-www-form-urlencoded',  'Accept': 'application/json'}
-    headers = {'Accept': 'application/json'}
+    headers = {'Content-Type': 'application/x-www-form-urlencoded',  'Accept': 'application/json'}
+    ## headers = {'Accept': 'application/json'}
     url = '%s/%s' % (options.url.rstrip('/'),options.unipept)
     if options.get:
+      params = '&'.join(['%s=%s' % (i[0],i[1]) for i in post_data])
       url = '%s.json?%s' % (url,params)
       req = urllib2.Request( url )
     else:
@@ -546,7 +551,7 @@
           match['tryptic_peptide'] = match['peptide']
           match['peptide'] = peptide
           peptideMatches.append(match)
-  elif options.unipept in ['pept2lca']:
+  elif options.unipept in ['pept2lca', 'peptinfo']:
     ## should be one response per trypticPeptide for pep2lca
     respMap = {v['peptide']:v for v in unipept_resp}
     ## map resp back to peptides