Mercurial > repos > jbrayet > rsat
view supported-organisms_soap.py @ 52:a1d369ead6d7 draft default tip
Uploaded
author | jbrayet |
---|---|
date | Tue, 29 Sep 2015 08:25:39 -0400 |
parents | 79ff213cef3e |
children |
line wrap: on
line source
#! /usr/bin/python # -*- coding: utf8 -*- """#supported organisms 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 organisms to each RSAT server and create loc files for Galaxy. # ###########################################################' # # Client to have list RSAT suppported organisms. # # #usage: supported-organisms_soap.py [-h] -f <OUTPUT_FORMAT> -galaxyPath <GALAXY_PATH> # # #optional arguments: # -h, --help show this help message and exit # -f <OUTPUT_FORMAT>, --format <OUTPUT_FORMAT> # Output format. Supported: html_list, html_table, # array, text, keys, names, sizes, full, tree, # html_tree. # -galaxyPath <GALAXY_PATH>, --galaxyPath <GALAXY_PATH> # Galaxy tool_data_path directory (e.i. /myGalaxy # /galaxy-dist/tool-data) # #Version 0.1 - 15/04/2015 # ###########################################################'""" __author__ = 'Jocelyn Brayet' supportedOrganismsVersion = '0.1 - 15/04/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_organisms(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 recupOrganisms(srv,request,dicServ,path): """ 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 # Define client header userAgent = 'RSAT-Client/v%s (%s; Python %s; %s)' % ( supportedOrganismsVersion, 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 resultsFile = open(path+"/"+"RSAT_organisms_"+srv+".loc","w") resultsFile.write(result.client) resultsFile.close() ###########################################################' ###########################################################' # 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='Client to download supported-organisms results from RSAT server.', epilog='Version '+supportedOrganismsVersion) # List desired arguments parser.add_argument('-f', '--format', metavar='<OUTPUT_FORMAT>', type=str, nargs=1, help='Output format. Supported: html_list, html_table, array, text, keys, names, sizes, full, tree, html_tree.', 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_format = testNone(args.format) galaxyPath = testNone(args.galaxyPath) supportedOrganismsRequest = { 'output' : 'client', 'format' : output_format } for srv in serverDict: recupOrganisms(srv,supportedOrganismsRequest,serverDict,galaxyPath)