##########################################################
# This script demonstrates how to access the OMA Browser #
# using Python. The requires the SOAPpy package to be    #
# installed.                                             #
#                       Adrian Schneider, September 2009 #
#                       schneadr@inf.ethz.ch             #
##########################################################

from SOAPpy import WSDL

# loading the methdos definitions from WSDL
url = 'http://www.omabrowser.org./omabrowser.wsdl'
oma = WSDL.Proxy(url)

# to view the raw XML, uncomment these:
#oma.soapproxy.config.dumpSOAPOut = 1
#oma.soapproxy.config.dumpSOAPIn = 1 

# print all methods with parameters and return values
print 'Available methods:'
for method in oma.methods.keys() :
  print method
  ci = oma.methods[method]
  # list of the function and type 
  # depending of the wsdl...
  for param in ci.inparams :
    print '=> ',param.name.ljust(20) , param.type
  for param in ci.outparams :
    print '<= ',param.name.ljust(20) , param.type
  print


# MapIDs
print '=== MapIDs([HUMAN2293,HUMAN5680,HUMAN9],1) ==='
li = ['HUMAN2293','HUMAN5680','HUMAN9']
res = oma.MapIDs(li,1)
print 'These entries have the following SwissProt IDs:'
for i in range(0, len(li)):
    print li[i].ljust(10),res['OutIDs'][i][0]
print

# ListOrthologs
print '=== ListOrthologs(MOUSE4430) ==='
res = oma.ListOrthologs('MOUSE4430')
print 'This protein has %d orthologs:' % len(res['ID'])
for id in res['ID']:
    print id
print

# IdentifySequence
print '=== IdentifySequence(MGLRIHFVVDPHGWCCMGLI) ==='
res = oma.IdentifySequence('MGLRIHFVVDPHGWCCMGLI')
print 'This sequence can be found in %d proteins:' % len(res['ID'])
for id in res['ID']:
    print id
print

# GetOMAGroup
print '=== GetOMAGroup(77541) ==='
group = oma.GetOMAGroup(77541)
print 'Group 77541 has %d members:' % len(group['ID'])
for id in group['ID']:
    print id
print

# TestOrthology
print '=== TestOrthology(\'HUMAN1\',\'MOUSE16919\') ==='
otype = oma.TestOrthology('HUMAN1','MOUSE16919')
print 'The two proteins are',otype
print

# ListIDTypes
print '=== ListIDTypes() ==='
types = oma.ListIDTypes()
for ti in types['IDType']:
   print ti['TypeNr'],ti['TypeName']
print

# GetMatrixInfo
print '=== GetMatrixInfo() ==='
info = oma.GetMatrixInfo()
print 'OMA version %s with %d groups and %d species' % \
	(info['Name'],info['NumGroups'],info['NumSpecies'])
print

# GetEntry('HUMAN666');
print '=== GetEntry(\'HUMAN1\') ==='
entry = oma.GetEntry(EntryID='HUMAN1')
print 'Organism'.ljust(15), entry['Organism']
print 'Locus'.ljust(15),'Chromosome',entry['Chromosome'],':',entry['Locus']
print 'Sequence'.ljust(15), entry['Sequence']

