changeset 0:32e3e166ced7

Initial
author Saket Choudhary <saketkc@gmail.com>
date Wed, 20 Nov 2013 01:02:52 +0530
parents
children 3fe64fec66e4
files tools/mutationassesor_web/README.rst tools/mutationassesor_web/mutation_assesor.py tools/mutationassesor_web/mutation_assesor.xml tools/mutationassesor_web/tool_dependencies.xml
diffstat 4 files changed, 167 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/mutationassesor_web/README.rst	Wed Nov 20 01:02:52 2013 +0530
@@ -0,0 +1,34 @@
+Galaxy wrapper for the CHASM webservice at CRAVAT(v2.0)
+===================================================
+
+This tool is copyright 2013 by Saket Choudhary, Indian Institute of Technology Bombay
+All rights reserved. MIT licensed.
+
+Licence (MIT)
+=============
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+Citations
+===========
+
+
+If you use this Galaxy tool in work leading to a scientific publication please cite:
+
+Reva B, Antipin Y, Sander C. Nucleic Acids Research (2011) "Predicting the Functional Impact of Protein Mutations: Application to Cancer Genomics"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/mutationassesor_web/mutation_assesor.py	Wed Nov 20 01:02:52 2013 +0530
@@ -0,0 +1,100 @@
+import sys
+sys.path.insert(0, '/home/saket/requests-new-urllib3-api/requests/packages/')
+sys.path.insert(0, '/home/saket/requests-new-urllib3-api')
+
+
+import requests
+from functools import wraps
+import tempfile, shutil,time
+import os,csv
+#__url__="http://mutationassessor.org/?cm=var&var=%s&frm=txt&fts=all"
+__url__="http://mutationassessor.org"
+def stop_err( msg ):
+    sys.stderr.write( '%s\n' % msg )
+    sys.exit()
+
+def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None):
+
+    """Retry calling the decorated function using an exponential backoff.
+
+    http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
+    original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
+
+    :param ExceptionToCheck: the exception to check. may be a tuple of
+        exceptions to check
+    :type ExceptionToCheck: Exception or tuple
+    :param tries: number of times to try (not retry) before giving up
+    :type tries: int
+    :param delay: initial delay between retries in seconds
+    :type delay: int
+    :param backoff: backoff multiplier e.g. value of 2 will double the delay
+        each retry
+    :type backoff: int
+    :param logger: logger to use. If None, print
+    :type logger: logging.Logger instance
+    """
+    def deco_retry(f):
+
+        @wraps(f)
+
+        def f_retry(*args, **kwargs):
+            mtries, mdelay = tries, delay
+            while mtries > 1:
+                try:
+                    return f(*args, **kwargs)
+                except ExceptionToCheck, e:
+                    #msg = "%s, Retrying in %d seconds..." % (str(e), mdelay)
+                    msg = "Retrying in %d seconds..." %  (mdelay)
+                    if logger:
+                        logger.warning(msg)
+                    else:
+                        #print msg
+                        pass
+                    time.sleep(mdelay)
+                    mtries -= 1
+                    mdelay *= backoff
+            return f(*args, **kwargs)
+
+        return f_retry  # true decorator
+
+    return deco_retry
+def main(params):
+    with open(params[0],"r") as f:
+        for i,sequence in enumerate(f):
+            #print sequence
+            sequence=sequence.replace("\t",",").replace(" ",",")
+            call=requests.get((__url__)%(sequence))
+            with open(params[1],"a") as w:
+                text = call.content.replace("\\t","\t")
+                if i>1:
+                    text_split=text.split("\n")
+                    text="\t".join(text_split[1])
+                w.write(text)
+            time.sleep(1)
+    return True
+
+def main_web(params):
+    tmp_dir = tempfile.mkdtemp()
+    path = os.path.join(tmp_dir,"csv_file")
+    in_txt = csv.reader(open(params[0],"rb"), delimiter="\t")
+    with open(path,"wb") as fp:
+        out_csv = csv.writer(fp,delimiter=",")
+        out_csv.writerows(in_txt)
+    fh = open(path,"rb")
+    readfile=fh.read()
+    fh.close()
+    payload = {"vars":readfile,"tableQ":"","protres":""}
+    request = requests.post(__url__,data=payload)
+    response = request.text
+    temp_file = os.path.join(tmp_dir,"int_file")
+    with open(temp_file,"wb") as w:
+        w.write(response)
+
+    in_txt = csv.reader(open(temp_file,"rb"), delimiter=",")
+    with open(params[1],"wb") as fp:
+        out_csv = csv.writer(fp,delimiter="\t")
+        out_csv.writerows(in_txt)
+    shutil.rmtree(tmp_dir)
+    return True
+if __name__=="__main__":
+    main_web(sys.argv[1:])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/mutationassesor_web/mutation_assesor.xml	Wed Nov 20 01:02:52 2013 +0530
@@ -0,0 +1,26 @@
+<tool id="mutationassesor_web" name="MutationAssesor">
+    <description>MutationAssesor web service</description>
+    <command interpreter="python">
+        mutation_assesor.py $input $output
+    </command>
+    <inputs>
+        <param name="input" format="txt" type="data" label="Input variants" />
+    </inputs>
+    <outputs>
+        <data name="output" format="tabular"/>
+    </outputs>
+    <help>
+
+        **What it does**
+
+        The server predicts the functional impact of amino-acid substitutions in proteins, such as mutations discovered
+        in cancer or missense polymorphisms. The functional impact is assessed based on evolutionary conservation of
+        the affected amino acid in protein homologs.
+        The method has been validated on a large set (60k) of disease associated (OMIM) and polymorphic variants
+
+        **Citation**
+        If you use this Galaxy tool in work leading to a scientific publication please cite:
+        Reva B, Antipin Y, Sander C. Nucleic Acids Research (2011) "Predicting the Functional Impact of Protein Mutations: Application to Cancer Genomics"
+    </help>
+</tool>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/mutationassesor_web/tool_dependencies.xml	Wed Nov 20 01:02:52 2013 +0530
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<tool_dependency>
+     <package name="requests" version="2.0.1">
+         <repository toolshed="http://testtoolshed.g2.bx.psu.edu" name="package_requests_2_0" owner="saketkc"/>
+    </package>
+</tool_dependency>
+