changeset 0:7404ab872276

First Commit
author Saket Choudhary <saketkc@gmail.com>
date Wed, 20 Nov 2013 00:02:12 +0530
parents
children 71992fffae10
files tools/transFIC/README.rst tools/transFIC/tool_dependencies.xml tools/transFIC/transFIC_web.py tools/transFIC/transFIC_web.xml
diffstat 4 files changed, 216 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/transFIC/README.rst	Wed Nov 20 00:02:12 2013 +0530
@@ -0,0 +1,35 @@
+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:
+
+Gonzalez-Perez A, Deu-Pons J and Lopez-Bigas N. Improving the prediction of the functional impact of cancer mutations by baseline tolerance transformation
+Genome Medicine 2012. 4:89 doi:10.1186/gm390s
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/transFIC/tool_dependencies.xml	Wed Nov 20 00:02:12 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>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/transFIC/transFIC_web.py	Wed Nov 20 00:02:12 2013 +0530
@@ -0,0 +1,143 @@
+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
+import pycurl
+import os
+from os.path import getsize
+import argparse
+import sys
+import cStringIO
+from functools import wraps
+import tempfile, shutil,time
+
+__url__="http://bg.upf.edu/transfic/taskService"
+def stop_err( msg ):
+    sys.stderr.write( '%s\n' % msg )
+    sys.exit()
+
+def retry(ExceptionToCheck, tries=14, 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
+
+class TransficUploader:
+    def __init__(self):
+
+        self.c = pycurl.Curl()
+        self.c.setopt(pycurl.URL, __url__)
+        self.c.setopt(pycurl.UPLOAD, 1)
+        #c.setopt(pycurl.USERPWD, 'saket.kumar:whatsinaname.')
+        self.c.setopt(pycurl.PROXY, 'http://saket.kumar:whatsinaname.@netmon.iitb.ac.in:80/')
+        #c.setopt(pycurl.PROXYPORT, 80)
+        #c.setopt(pycurl.PROXYTYPE_HTTP,1)
+        #self.c.setopt(pycurl.VERBOSE, 1)
+        self.c.setopt(pycurl.HTTPHEADER, ['Expect:'])
+        #c.setopt(pycurl.HTTPPROXYTUNNEL, 1)
+        self.c.setopt(pycurl.UPLOAD, 1)
+        #c.perform()
+        self.c.setopt(pycurl.NOPROGRESS, 1);
+        #curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L);
+        self.c.setopt(pycurl.USERAGENT, "curl/7.27.0");
+        #curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
+        #curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
+        self.c.setopt(pycurl.SSL_VERIFYPEER, 1);
+        self.c.setopt(pycurl.CUSTOMREQUEST, "PUT")
+        #curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
+        self.c.setopt(pycurl.TCP_NODELAY, 1);
+        self.buf = cStringIO.StringIO()
+        self.c.setopt(self.c.WRITEFUNCTION, self.buf.write)
+
+
+    def upload_file(self,filepath):
+        f = open(filepath)
+        self.c.setopt(pycurl.INFILE, f)
+        self.c.setopt(pycurl.INFILESIZE, getsize(filepath))
+        #print f.read()
+
+    def run(self):
+        self.c.perform()
+
+    def get_url(self):
+        return self.buf.getvalue().strip()
+
+    @retry(requests.exceptions.HTTPError)
+    def result_exists(self,url ):
+        #url="http://www.cravat.us/results/%s/%s.zip" %(job_id,job_id)
+        download_request = requests.request("GET", url)
+        if download_request.status_code==404 or download_request==500:
+            raise requests.HTTPError()
+        elif "Task status is : error" in download_request.text:
+            stop_err("No SNVs found!")
+        else:
+            return url
+    @retry(requests.exceptions.HTTPError)
+    def download_result(self, url,outpath):
+        tmp_dir = tempfile.mkdtemp()
+        r = requests.get( url, stream=True )
+        if r.status_code == 500:
+            raise requests.HTTPError()
+        else:
+            path = os.path.join( tmp_dir,"results.csv")
+            with open(path, 'wb') as f:
+                for chunk in r.iter_content(128):
+                    f.write(chunk)
+        shutil.move(path,outpath)
+        shutil.rmtree(tmp_dir)
+
+
+
+def main(params):
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--input",type=str,required=True)
+    parser.add_argument("--output",type=str,required=True)
+    args = parser.parse_args(params)
+    uploader = TransficUploader();
+    uploader.upload_file(args.input)
+    uploader.run()
+    url = uploader.get_url()
+    url = uploader.result_exists(url)
+    download = uploader.download_result(url,args.output)
+if __name__=="__main__":
+    main(sys.argv[1:])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/transFIC/transFIC_web.xml	Wed Nov 20 00:02:12 2013 +0530
@@ -0,0 +1,31 @@
+<tool id="transFIC_web" name="TransFIC">
+    <description>TransFIC web service</description>
+    <command interpreter="python">
+        transFIC_web.py --input $input --output $output
+    </command>
+    <inputs>
+        <param name="input" format="text" type="data" label="Inout Variants"/>
+    </inputs>
+    <outputs>
+        <data name="output" format="tabular"/>
+    </outputs>
+    <help>
+        **What it does**
+        TransFIC stands for TRANsformed Functional Impact for Cancer.
+        It is a method to transform Functional Impact Scores taking into account the differences in basal
+        tolerance to germline SNVs of genes that belong to different functional classes. This transformation
+        allows to use the scores provided by well-known tools (e.g. SIFT, Polyphen2, MutationAssessor)
+        to rank the functional impact of cancer somatic mutations.Mutations with greater transFIC are more likely to be cancer drivers.
+        TransFIC takes as input the Functional Impact Score of a somatic mutation provided by one of the aforementioned tools.
+        It then compares that score to the distribution of scores of germline SNVs observed in genes with similar functional annotations (for instance genes with the same molecular function as provided by the Gene Ontologies). The score is thus transformed using the Zscore formula. The result is that mutations in genes that are less tolerant to germline SNVs are amplified,
+        while the scores of mutations on relatively tolerant genes are decreased.
+
+
+        **Citation**
+        If you use this Galaxy tool in work leading to scientific publication please cite:
+
+        Gonzalez-Perez A, Deu-Pons J and Lopez-Bigas N. Improving the prediction of the functional impact of cancer mutations by baseline tolerance transformation
+        Genome Medicine 2012. 4:89 doi:10.1186/gm390s
+    </help>
+</tool>
+