# HG changeset patch # User jbrayet # Date 1442923336 14400 # Node ID d72401de2a411114236a77195b879e28a706120b # Parent 2f3462ac56aafc39217bf1adf6dee84056d9ae7b Uploaded diff -r 2f3462ac56aa -r d72401de2a41 oligoAnalysis_wrapper.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/oligoAnalysis_wrapper.py Tue Sep 22 08:02:16 2015 -0400 @@ -0,0 +1,191 @@ +#! /usr/bin/python +# -*- coding: utf8 -*- + +"""#oligo analysis soap - developed by Jocelyn Brayet +#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 . +# +###########################################################' +# +#Analysis of oligomer occurrences in nucleotidic of peptidic sequences. +# +###########################################################' +# +# Client to have list RSAT oligo analysis. +# +# +#usage: oligo-analysis_soap.py [-h] -sequence_file -length +# -organism -server +# +#optional arguments: +# -h, --help show this help message and exit +# -sequence_file , --sequence_file +# Input sequence (FASTA file). +# -length , --length +# Oligomer length. +# -organism , --organism +# Organism. +# -stats , --stats +# List of statistics to return. Supported:occ, mseq, +# freq, proba, ratio, zscore, like, pos, rank. +# -server , --server +# +#Version 0.1 - 16/04/2015 +# +# +###########################################################'""" +__author__ = 'Jocelyn Brayet' +oligoAnalysisVersion = '0.1 - 16/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.oligo_analysis(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='Analysis of oligomer occurrences in nucleotidic of peptidic sequences.', epilog='Version '+oligoAnalysisVersion) + + ########### compare matrices arguments #################### + + parser.add_argument('-sequence_file', '--sequence_file', metavar='', type=argparse.FileType('r'), nargs=1, help='Input sequence (FASTA file).', required=True) + parser.add_argument('-length', '--length', metavar='', type=int, nargs=1, help='Oligomer length.', required=True) + parser.add_argument('-organism', '--organism', metavar='', type=str, nargs=1, help='Organism.', required=True) + parser.add_argument('-stats', '--stats', metavar='', type=str, nargs=1, help='List of statistics to return. Supported:occ, mseq, freq, proba, ratio, zscore, like, pos, rank.', required=False) + + ########### galaxy arguments ############################## + parser.add_argument('-server', '--server', metavar='', type=str, nargs=1, required=True) + parser.add_argument('-outGalaxy', '--outGalaxy', metavar='', type=str, nargs=1, required=True) + ########################################################### + + args = parser.parse_args() + + sequence_file = args.sequence_file[0].read() + serverValue = testNone(args.server) + length = testNone(args.length) + organism = testNone(args.organism) + stats = testNone(args.stats) + outGalaxyValue = testNone(args.outGalaxy) + + ###########################################################' + ## 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)' % ( + oligoAnalysisVersion, + os.path.basename( __file__ ), + platform.python_version(), + platform.system() + ) + + httpHeaders = {'User-agent': userAgent} + client.set_options(headers=httpHeaders) + client.set_options(timeout=300) + + + oligoAnalysisRequest = { + + 'output' : 'both', + 'format' : 'fasta', + 'sequence' : sequence_file, + 'length' : length, + 'organism' : organism, + 'stats' : stats + + } + + + result = call_run_service(rsat_service, oligoAnalysisRequest) + + + print url + + print "###############################################" + print "Command performed on server" + print result.command + print "###############################################" + print "Result" + print result.server + + nameFile = "oligo-analysis_results.txt" + + urlResult=result.server.replace("$RSAT/public_html/",url.replace("web_services/RSATWS.wsdl","")) + + print urlResult + + urllib.urlretrieve(urlResult, nameFile) + + os.popen("cp "+nameFile+" "+outGalaxyValue) + + +