# HG changeset patch # User jbrayet # Date 1442923327 14400 # Node ID 2f3462ac56aafc39217bf1adf6dee84056d9ae7b # Parent 945c5b1b93929e3f1594715e31a049adb2a51b78 Uploaded diff -r 945c5b1b9392 -r 2f3462ac56aa dyadAnalysis_wrapper.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dyadAnalysis_wrapper.py Tue Sep 22 08:02:07 2015 -0400 @@ -0,0 +1,209 @@ +#! /usr/bin/python +# -*- coding: utf8 -*- + +"""#dyad 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 spaced dyads in a set of DNA sequences. +# +###########################################################' +# +#usage: dyad-analysis_soap.py [-h] -sequence_file -length +# -organism -spacing +# [-stats ] [-type ] -server +# +#optional arguments: +# -h, --help show this help message and exit +# -sequence_file , --sequence_file +# Input sequence (FASTA file). +# -length , --length +# Dyad length. +# -organism , --organism +# Organism. +# -spacing , --spacing +# Spacing between elements of the dyads. +# -stats , --stats +# List of statistics to return. Supported:occ, mseq, +# freq, proba, ratio, zscore, like, pos, rank. +# -type , --type +# Four types are accepted: dr (direct repeats: the +# second element is the same as the first one); ir +# (inverted repeats: the second element is the revers +# complement of the first one); rep (repeats: direct and +# inverted repeats are evaluated); any +# -server , --server +# +#Version 0.1 - 16/04/2015 +# +###########################################################'""" +__author__ = 'Jocelyn Brayet' +dyadAnalysisVersion = '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.dyad_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 spaced dyads in a set of DNA sequences.', epilog='Version '+dyadAnalysisVersion) + + ########### 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='Dyad length.', required=True) + parser.add_argument('-organism', '--organism', metavar='', type=str, nargs=1, help='Organism.', required=True) + parser.add_argument('-spacing', '--spacing', metavar='', type=int, nargs=1, help='Spacing between elements of the dyads.', 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) + parser.add_argument('-type', '--type', metavar='', type=str, nargs=1, help='Four types are accepted: dr (direct repeats: the second element is the same as the first one); ir (inverted repeats: the second element is the revers complement of the first one); rep (repeats: direct and inverted repeats are evaluated); any', 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) + spacing = testNone(args.spacing) + stats = testNone(args.stats) + typeValue = testNone(args.type) + 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)' % ( + dyadAnalysisVersion, + os.path.basename( __file__ ), + platform.python_version(), + platform.system() + ) + + httpHeaders = {'User-agent': userAgent} + client.set_options(headers=httpHeaders) + client.set_options(timeout=300) + + + dyadAnalysisRequest = { + + 'output' : 'both', + 'format' : 'fasta', + 'sequence' : sequence_file, + 'length' : length, + 'organism' : organism, + 'spacing' : spacing, + 'stats' : stats, + 'type' : typeValue + + } + + + result = call_run_service(rsat_service, dyadAnalysisRequest) + + + print url + + print "###############################################" + print "Command performed on server" + print result.command + print "###############################################" + print "Result" + print result.server + + nameFile = "dyad_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) + + + + + +