Mercurial > repos > jbrayet > rsat
diff compareMatrices_wrapper.py @ 29:b34046b02556 draft
Uploaded
author | jbrayet |
---|---|
date | Tue, 22 Sep 2015 08:02:35 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compareMatrices_wrapper.py Tue Sep 22 08:02:35 2015 -0400 @@ -0,0 +1,177 @@ +#! /usr/bin/python +# -*- coding: utf8 -*- +"""#Compare Matrices - 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/>. +# +###########################################################' +# +#Client to download compare matrices results from RSAT server. +# +###########################################################'""" + +__author__ = 'Jocelyn Brayet' +compareMatricesVersion = '0.1 - 14/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(service, args): + """ + Run job in RSAT server. + service -> RSAT web service + args -> web service request + """ + + result = rsat_service.compare_matrices(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 + +###########################################################' +# server dictionary +serverDict = { + + "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__': + + parser = argparse.ArgumentParser(description='Client to download compare matrices results from RSAT server.', epilog='Version '+compareMatricesVersion) + + + ########### compare matrices arguments #################### + + parser.add_argument('-matrix_1', '--matrix_1', metavar='<MATRIX_1>', type=argparse.FileType('r'), nargs=1, help='The first input containing one or several matrices.', required=True) + parser.add_argument('-matrix_2', '--matrix_2', metavar='<MATRIX_2>', type=argparse.FileType('r'), nargs=1, help='The second input containing one or several matrices.', required=True) + parser.add_argument('-format1', '--format1', metavar='<FORMAT_1>', type=str, nargs=1, help='Martix format for the first input. Supported fields: tab, cb, consensus, gibbs, meme, assembly.', required=True) + parser.add_argument('-format2', '--format2', metavar='<FORMAT_2>', type=str, nargs=1, help='Martix format for the second input. Supported fields: tab, cb, consensus, gibbs, meme, assembly.', required=True) + parser.add_argument('-returnResults', '--returnResults', metavar='<RETURN_RESULTS>', type=str, nargs=1, help='List of fields to return (only valid for the formats "profiles" and "matches").', required=False) + #parser.add_argument('-rc', '--rc', metavar='<RC>', type=int, nargs=1, help='Convert the matrix to its reverse complement if value = 1.', required=False) + #parser.add_argument('-decimals', '--decimals', metavar='<DECIMALS>', type=int, nargs=1, help='Number of decimals to print for real matrices (frequencies, weights, information) or to compute score distributions.', required=False) + + ########### galaxy arguments ############################## + parser.add_argument('-server', '--server', metavar='<SERVEUR>', type=str, nargs=1, required=True) + parser.add_argument('-outGalaxy', '--outGalaxy', metavar='<OUT_GALAXY>', type=str, nargs=1, required=True) + ########################################################### + + args = parser.parse_args() + + matrix_1 = args.matrix_1[0].read() + matrix_2 = args.matrix_2[0].read() + serverValue = testNone(args.server) + format1 = testNone(args.format1) + format2 = testNone(args.format2) + returnValue = testNone(args.returnResults) + outGalaxyValue = testNone(args.outGalaxy) + #returnTypeValue = testNone(args.return_type) + #permValue = testNone(args.perm) + #rcValue = testNone(args.rc) + #decimalsValue = testNone(args.decimals) + + ###########################################################' + ## Create the SOAP client to request the RSAT service + + + # Load Client class from suds + # Define URL for RSAT services + url = serverDict[serverValue] + # Create the client + client = Client(url) + + # Need service interface to perform requests + rsat_service = client.service + + #print client + + # Define client header + userAgent = 'RSAT-Client/v%s (%s; Python %s; %s)' % ( + compareMatricesVersion, + os.path.basename( __file__ ), + platform.python_version(), + platform.system() + ) + + httpHeaders = {'User-agent': userAgent} + client.set_options(headers=httpHeaders) + client.set_options(timeout=300) + + + compareMatricesRequest = { + + 'output' : 'both', + 'matrix_1' : matrix_1, + 'matrix_2' : matrix_2, + 'format1' : format1, + 'format2' : format2, + 'return' : returnValue + + } + + + result = call_run_service(rsat_service, compareMatricesRequest) + + + print url + + print "###############################################" + print "Command performed on server" + print result.command + print "###############################################" + print "Result" + print result.server + + nameFile = "test_compare_matrices" + + urlResult=result.server.replace("$RSAT/public_html/",url.replace("web_services/RSATWS.wsdl",""))+"/.tab" + + urllib.urlretrieve(urlResult, nameFile) + + os.popen("cp "+nameFile+" "+outGalaxyValue) + + + + +