changeset 0:9135dad96527 draft default tip

planemo upload
author lnguyen
date Fri, 15 Sep 2017 09:55:49 -0400
parents
children
files link2reactome.py link2reactome.xml template.html test-data/UnipIDs.txt test-data/reactome_invalide_ids.txt test-data/reactome_output.html
diffstat 5 files changed, 277 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/link2reactome.py	Fri Sep 15 09:55:49 2017 -0400
@@ -0,0 +1,91 @@
+import os
+import re
+import json
+import argparse
+
+CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
+
+def id_valid(identifiers):
+    res = []
+    remove = []
+    for id in identifiers:
+        id = id.split(";")[0]
+        if re.match("^[A-Za-z0-9_-]*$", id):
+            res.append(id)
+        else:
+            remove.append(id)
+    return res, remove
+    
+def isnumber(format, n):
+    float_format = re.compile("^[\-]?[1-9][0-9]*\.?[0-9]+$")
+    int_format = re.compile("^[\-]?[1-9][0-9]*$")
+    test = ""
+    if format == "int":
+        test = re.match(int_format, n)
+    elif format == "float":
+        test = re.match(float_format, n)
+    if test:
+        return True
+    else:
+        return False
+
+def data_json(identifiers):
+    trash = []
+    if identifiers[1] == "list":
+        ids = "\n".join(id_valid(identifiers[0].split())[0])
+        #print(ids)
+        #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids)
+        json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids).read()
+        if len(id_valid(identifiers[0].split())[1]) > 0:
+            trash = id_valid(identifiers[0].split())[1]
+    #elif identifiers[1] == "file":
+        #file = open(identifiers[0]).readlines()
+        #ids = "\n".join(id_valid(file)[0])
+        #print(ids)
+        #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids)
+        #json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids).read()
+        #if len(id_valid(file)[1]) > 0:
+            #trash = id_valid(file)[1]
+    elif identifiers[1] == "mq_file":
+        header = identifiers[2]
+        mq = open(identifiers[0]).readlines()
+        if isnumber("int", identifiers[3].replace("c", "")):
+            if header == "true":
+                idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq[1:]]
+            else:
+                idens = [x.split("\t")[int(identifiers[3].replace("c", ""))-1] for x in mq]
+            ids = "\n".join(id_valid(idens)[0])
+            #print(ids)
+            #print("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids)
+            json_string = os.popen("curl -H \"Content-Type: text/plain\" -d \"$(printf '%s')\" -X POST --url www.reactome.org/AnalysisService/identifiers/projection/\?pageSize\=1\&page\=1" % ids).read()
+            if len(id_valid(idens)[1]) > 0:
+                trash = id_valid(idens)[1]
+    print(json_string)
+    return json_string, trash
+
+def write_output(filename, json_string, trash_file, trash):
+    template = open(os.path.join(CURRENT_DIR, "template.html"))
+    output = open(filename, "w")
+    for line in template:
+        if "{token}" in line:
+            line = line.replace("{token}", json.loads(json_string)["summary"]["token"])
+        output.write(line)
+    template.close()
+    output.close()
+    
+    trash_out = open(trash_file, "w")
+    trash_out.write("\n".join(trash))
+    trash_out.close()
+
+def options():
+    parser = argparse.ArgumentParser()
+    argument = parser.add_argument("--json", nargs="+", required=True)
+    argument = parser.add_argument("--output", default="output.html")
+    argument = parser.add_argument("--trash", default="trash.txt")
+    args = parser.parse_args()
+    filename = args.output
+    json_string, trash = data_json(args.json)
+    write_output(filename, json_string, args.trash, trash)
+
+if __name__ == "__main__":
+    options()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/link2reactome.xml	Fri Sep 15 09:55:49 2017 -0400
@@ -0,0 +1,65 @@
+<tool id="link2reactome" name="Analyse your data with Reactome" version="0.1.0">
+    <description>Map your IDs list (Uniprot, Gene name) via analysis tools from Reactome database and visualize directly pathways in which your proteins are involved.
+    </description>
+    <requirements>
+    </requirements>
+    <stdio>
+        <exit_code range="1:" />
+    </stdio>
+    <command><![CDATA[
+        #if $opt.input == "text"
+            python $__tool_directory__/link2reactome.py --json "$opt.list" "list" --output "$output" --trash "$trash"
+        ##else if $opt.input == "file"
+            ##python /projet/galaxydev/galaxy/tools/proteore_uc1/tools/reactome/link2reactome.py --json "$opt.idfile" "file" --output "$output" --trash "$trash"
+        #else if $opt.input == "mq"
+            python $__tool_directory__/link2reactome.py --json "$opt.mq_file" "mq_file" $opt.header $opt.ncol --output "$output" --trash "$trash"
+        #end if
+        
+    ]]></command>
+    <inputs>
+        <conditional name="opt">
+            <param name="input" type="select" label="Input identifiers" multiple="False" >
+                <option value="text">Copy/paste your list of IDs </option>
+                <!--option value="file">Choose a single-column file </option-->
+		        <option value="mq">Choose a multiple-columns file </option>
+            </param>
+            <when value="text" >
+                <param name="list" type="text" label="Enter list of identifiers" />
+            </when>
+            <!--when value="file" >
+                <param name="idfile" type="data" format="txt" label="Choose a single-column file" />
+            </when-->
+            <when value="mq" >
+                <param name="mq_file" type="data" format="txt, tabular" label="Choose a multiple-columns file" help="Input file is a tab-delimited file containing different information of proteins, such as an output of MaxQuant software" />
+                <param name="header" type="boolean" checked="true" truevalue="true" falsevalue="false" label="Does your input file contain header?" />
+		        <param type="text" name="ncol" value="c1" label="Please specify the column where you would like to apply the comparison" help ='For example, fill in "c1" if you want to filter the first column' />
+            </when>
+            
+        </conditional>
+    </inputs>
+    <outputs>
+        <data name="output" format="html" label="" />
+        <data name="trash" format="tabular" label="Invalid identifiers" />
+    </outputs>
+    <tests>
+        <test>
+            <conditional name="opt" >
+                <param name="input" value="mq" />
+                <param name="mq_file" value="UnipIDs.txt" />
+                <param name="header" value="false" />
+                <param name="ncol" value="c1" />
+            </conditional>
+            <output name="output" file="reactome_output.html" ftype="html" />
+            <output name="trash" file="reactome_invalide_ids.txt" ftype="tab" />
+        </test>
+    </tests>
+    <help><![CDATA[
+Reactome software provides service of creating diagram representing the relations between the biological processes. This tool allows linking to Reactome web service with pre-loaded data from a list of IDs, a file containing IDs or from a column of a complexed file.
+
+**For the rows that have more than 1 ID, only the first one is taken into account**
+
+**This tool only accepts letters (a-z or A-Z), numbers (0-9) and 3 characters "." "-" "_" for IDs. If there is ID containing other than these characters, it will be removed from the queue and placed in "Invalid identifiers" file**
+    ]]></help>
+    <citations>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/template.html	Fri Sep 15 09:55:49 2017 -0400
@@ -0,0 +1,48 @@
+<html>
+
+  <head>
+
+    <title>Connection to the Reactome Analysis Service</title>
+    
+    <style>
+        body {
+            margin: 40px;
+            background-color: #ffffff;
+            text-align: center;
+            }
+        h1 {
+            color: #19334d;
+            }
+        p {
+            margin-top: 40px;
+            }
+        button {
+            background-color: #ccddff;
+            border: 2px solid #19334d;
+            border-radius: 4px;
+            color: black;
+            padding: 16px 32px;
+            margin: 4px 2px;
+            cursor: pointer;
+            }
+    </style>
+
+  </head>
+
+  <body>
+
+    <h1>Connection to the Reactome Analysis Service</h1>
+
+    <p>Please click the button to execute the analysis:</p>
+
+    <form action="http://www.reactome.org/PathwayBrowser/#/DTAB=AN&ANALYSIS={token}" target="_blank">
+    
+    <button>Analyse</button>
+
+    </form>
+
+    <br> <br>
+
+  </body>
+
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/UnipIDs.txt	Fri Sep 15 09:55:49 2017 -0400
@@ -0,0 +1,25 @@
+P04637
+P08246
+P63244
+P10275
+P00533
+Q14524
+P05067
+P35555
+P35222
+O95273
+P00451
+P38398
+Q05086
+Q12802
+P68871
+P04585
+Q96EB6
+Q9NYL2
+P31749
+P01137
+Q5S007
+Q08379
+P02649
+P35498
+P12931
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/reactome_output.html	Fri Sep 15 09:55:49 2017 -0400
@@ -0,0 +1,48 @@
+<html>
+
+  <head>
+
+    <title>Connection to the Reactome Analysis Service</title>
+    
+    <style>
+        body {
+            margin: 40px;
+            background-color: #ffffff;
+            text-align: center;
+            }
+        h1 {
+            color: #19334d;
+            }
+        p {
+            margin-top: 40px;
+            }
+        button {
+            background-color: #ccddff;
+            border: 2px solid #19334d;
+            border-radius: 4px;
+            color: black;
+            padding: 16px 32px;
+            margin: 4px 2px;
+            cursor: pointer;
+            }
+    </style>
+
+  </head>
+
+  <body>
+
+    <h1>Connection to the Reactome Analysis Service</h1>
+
+    <p>Please click the button to execute the analysis:</p>
+
+    <form action="http://www.reactome.org/PathwayBrowser/#/DTAB=AN&ANALYSIS=MjAxNzA4MzAwODM0MDRfMTMxNQ%3D%3D" target="_blank">
+    
+    <button>Analyse</button>
+
+    </form>
+
+    <br> <br>
+
+  </body>
+
+</html>