Mercurial > repos > jbrayet > rsat
view supported-motif-databases_soap.py @ 52:a1d369ead6d7 draft default tip
Uploaded
author | jbrayet |
---|---|
date | Tue, 29 Sep 2015 08:25:39 -0400 |
parents | 8e5a92e5917e |
children |
line wrap: on
line source
#! /usr/bin/python # -*- coding: utf8 -*- """#supported motif databases soap - developed by Jocelyn Brayet <jocelyn.brayet@curie.fr> #Copyright (C) 2015 Institut Curie # #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program. If not, see <http://www.gnu.org/licenses/>. # ###########################################################' # #Recup motif databases to each RSAT server and create loc files for Galaxy. # ###########################################################' # # List RSAT suppported motif databases. # # #usage: supported-motif-databases_soap.py [-h] -galaxyPath <GALAXY_PATH> # #optional arguments: # -h, --help show this help message and exit # -galaxyPath <GALAXY_PATH>, --galaxyPath <GALAXY_PATH> # Galaxy tool_data_path directory (e.i. /myGalaxy # /galaxy-dist/tool-data) # #Version 0.1 - 27/05/2015 # ###########################################################'""" __author__ = 'Jocelyn Brayet' supportedMotifDatabasesVersion = '0.1 - 27/05/2015' ###########################################################' ## Import import argparse import os import urllib from suds.client import Client import platform ###########################################################' ################################ functions ############################################################ ## Define a function to make a service perform the desired request using provided arguments def call_run_service(rsat_service, args): """ Run job in RSAT server. service -> RSAT web service args -> web service request """ result = rsat_service.supported_motif_databases(args) return result def testNone(argument): """ Test if argument is None or not. argument -> argument give by user """ if not argument is None: variable = argument[0] else: variable = "" return variable def recupMotifDatabases(srv,request,dicServ): """ Recup RSAT organisms in each RSAT server. srv -> server key in server dictionary request -> job request dicServ -> server dictionary """ # Create the client client = Client(serverDict[srv]) # Need service interface to perform requests rsat_service = client.service print client # Define client header userAgent = 'RSAT-Client/v%s (%s; Python %s; %s)' % ( supportedMotifDatabasesVersion, os.path.basename( __file__ ), platform.python_version(), platform.system() ) httpHeaders = {'User-agent': userAgent} client.set_options(headers=httpHeaders) client.set_options(timeout=300) result = call_run_service(rsat_service, request) ###########################################################' ## Display request results print '###############################################' print 'Command performed on server' print '' print result.command print '' print '###############################################' print 'Result' print '' print result.client return(result.client) ###########################################################' ###########################################################' # server dictionary serverDict = { #http://protists.rsat.eu/ "fr_ens":"http://rsat01.biologie.ens.fr/rsa-tools/web_services/RSATWS.wsdl", "fr_mrs":"http://rsat-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl", "fr_ro":"http://rsat.sb-roscoff.fr/web_services/RSATWS.wsdl", "fr_mrs_2":"http://pedagogix-tagc.univ-mrs.fr/rsat/web_services/RSATWS.wsdl", "es":"http://floresta.eead.csic.es/rsat/web_services/RSATWS.wsdl", "mx":"http://embnet.ccg.unam.mx/rsa-tools/web_services/RSATWS.wsdl" } if __name__ == '__main__': # Create the parser parser = argparse.ArgumentParser(description='List RSAT suppported motif databases.', epilog='Version '+supportedMotifDatabasesVersion) # List desired arguments #parser.add_argument('-r', '--return_param', metavar='<RETURN_PARAM>', type=str, nargs=1, help='Return fields. Supported: name,format,file,descr,version,url.', required=True) parser.add_argument('-galaxyPath', '--galaxyPath', metavar='<GALAXY_PATH>', type=str, nargs=1, help='Galaxy tool_data_path directory (e.i. /myGalaxy/galaxy-dist/tool-data)', required=True) # Parse command line args = parser.parse_args() # Get values to be used #output_return = testNone(args.return_param) galaxyPath = testNone(args.galaxyPath) for srv in serverDict: functionResult="" reslutsTab=list() finalTab=list() supportedMotifDatabasesRequest = { 'output' : 'client', 'return' : 'name' } functionResult=recupMotifDatabases(srv,supportedMotifDatabasesRequest,serverDict) reslutsTab=str(functionResult).split("\n") del reslutsTab[-1] resultsFile = open(galaxyPath+"/"+"RSAT_motif_databases_"+srv+".loc","w") for value in reslutsTab: if not value.startswith("#"): resultsFile.write(value+"\n") resultsFile.close()