示例#1
0
def GetWikiPaths4IDs(idList,SC):
    # Function that uses a list of IDs and a systm code as input and
    # returns a string with all the WikiPathways where th IDs exist (including the new lines) as tab separated fields:
    # No, ID, Species, Pathway ID, Pathway Name

    # Load SOAPpy and dependent modules (fpconst) and access the remote
    # SOAP server through a proxy class, SOAPProxy - see:
    # (http://diveintopython.org/soap_web_services/first_steps.html)

    from SOAPpy import SOAPProxy
    url = 'http://www.wikipathways.org/wpi/webservice/webservice.php'
    namespace = 'http://www.wikipathways.org/webservice'
    server = SOAPProxy(url, namespace)

    # Define the order of args: needed for this service
    server.config.argsOrdering = {'findPathwaysByXref': ('ids', 'codes') }
    
    index=1 # index of the result lines
    print_output = '' # output of the function
    # For each ID findPathwaysByXref (multiple args; returns list of dictionary references)
    for gi in idList:
        # checking any erors
        try:
            probeset_containing = server.findPathwaysByXref(codes=SC, ids=gi)
            NoPaths = len(probeset_containing)
            #Loops through a list of dictionary items if results
            if NoPaths > 0 :
                for object in probeset_containing:
                    #calls select dictionary keys to print out values            
                    print_output += str(int(index))+'\t'+str(gi)+'\t'+str(object['species'])+'\t'+str(object['id'])+'\t'+str(object['name'])+'\n'
                    index+=1
            else:
                print gi, "can't be found in WikiPathways!"
        except:
            #pass # if error do nothing
            print gi, 'has', NoPaths, 'pathways but it can be processed!'
    return print_output
示例#2
0
# Print out function for query results (see code below function first)
def printOutput(ws_output):
    #Loops through a list of dictionary items
    index=1
    for object in ws_output:
        #calls select dictionary keys to print out values
        print_output = '   '+str(index)+')'+'species:'+object['species']+'\t '
        print_output+= 'id:'+object['id']+'\t '+'name:'+object['name']
        print print_output
        index+=1

# Load SOAPpy and dependent modules (fpconst) and access the remote
# SOAP server through a proxy class, SOAPProxy - see:
# (http://diveintopython.org/soap_web_services/first_steps.html)
from SOAPpy import SOAPProxy      
url = 'http://www.wikipathways.org/wpi/webservice/webservice.php'
namespace = 'http://www.wikipathways.org/webservice'
server = SOAPProxy(url, namespace)

# Define the order of args: needed for this service
server.config.argsOrdering = {'findPathwaysByXref': ('ids', 'codes') }

# findPathwaysByXref (multiple args; returns list of dictionary references)
sc = 'S'; gi = 'P00488'
probeset_containing = server.findPathwaysByXref(codes=sc, ids=gi )
print '\nPathways containing the gene ID "%s" for system code "%s"' % (gi,sc) 
printOutput(probeset_containing)