changeset 0:fb0ee82f686d draft

Uploaded
author immport-devteam
date Mon, 27 Feb 2017 12:56:34 -0500
parents
children f70f75e89890
files flowcl/getOntology.R flowcl/getOntology.py flowcl/getOntology.xml flowcl/static/flowtools/css/flowCL.css flowcl/static/flowtools/js/flowcl_table.js flowcl/static/images/flowtools/flowcl_graph.png flowcl/static/images/flowtools/flowcl_summary.png flowcl/templates/flowCL.template flowcl/test-data/flowCL_res.pdf flowcl/test-data/flowCL_run_summary.txt flowcl/test-data/flowCL_table.txt flowcl/test-data/out.html
diffstat 12 files changed, 532 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/getOntology.R	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,28 @@
+# Cell Ontology Module for Galaxy
+# FlowCL
+######################################################################
+#                  Copyright (c) 2016 Northrop Grumman.
+#                          All rights reserved.
+######################################################################
+# 
+# Version 1
+# Cristel Thomas
+#
+#
+
+library(flowCL)
+library(base)
+
+getOntology <- function(output_file, markers) {
+  res <- flowCL(markers, ResetArch = TRUE)
+  if (length(res) == 6) {
+    report <- capture.output(res$Table)
+    sink(output_file)
+    cat(report, sep = "\n")
+    sink()
+  }
+}
+
+args <- commandArgs(trailingOnly = TRUE)
+markers <- paste(args[3:length(args)], collapse="")
+getOntology(args[2], markers)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/getOntology.py	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,135 @@
+#!/usr/bin/env python
+######################################################################
+#                  Copyright (c) 2016 Northrop Grumman.
+#                          All rights reserved.
+######################################################################
+from __future__ import print_function
+import sys
+import os
+
+from collections import defaultdict
+from argparse import ArgumentParser
+from jinja2 import Environment, FileSystemLoader
+
+
+def generate_flowCL_query(list_markers, list_types):
+    if (len(list_markers) != len(list_types)):
+        return("pb with headers")
+    query = []
+    # go through both lists, remove fsc/ssc
+    for i in range(0, len(list_markers)):
+        if not list_markers[i].startswith("FSC") and not list_markers[i].startswith("SSC"):
+            query.append(list_markers[i].upper())
+            query.append(list_types[i])
+    # return concatenated string
+    return("".join(query))
+
+
+def run_flowCL(phenotype, output_file, output_dir, tool_dir):
+    os.mkdir(output_dir)
+    tool = "/".join([tool_dir, "getOntology.R"])
+    output_txt = "".join([output_dir, "/flowCL_run_summary.txt"])
+    output_table = "".join([output_dir, "/flowCL_table.txt"])
+    output_pdf = "".join([output_dir, "/flowCL_res.pdf"])
+    run_command = " ". join(["Rscript --slave --vanilla", tool, "--args", output_txt, phenotype])
+    os.system(run_command)
+
+    table = defaultdict(list)
+    labels = []
+    nb_match = 0
+    if os.path.isfile(output_txt):
+        with open(output_txt, "r") as txt:
+            check = txt.readline().strip()
+            if (not check):
+                sys.exit(2)
+            else:
+                i = -1
+                for lines in txt:
+                    data = lines.strip("\n").split("\"")
+                    if data[0].strip():
+                        labels.append(data[0].strip())
+                        i += 1
+                        if data[0].startswith("Score"):
+                            count_matches = data[1].split(") ")
+                            nb_match = len(count_matches) - 1
+                    table[i].append(data[1])
+    else:
+        sys.stderr.write("There are no results with this query. Please check your markers if you believe there should be.")
+        sys.exit(2)
+
+    with open(output_table, "w") as tbl:
+        tbl.write("1\t2\nQuery\t" + phenotype + "\n")
+        for j in table:
+            newline = " ".join(table[j])
+            for k in range(1, nb_match + 1):
+                cur_stg = "".join([str(k+1), ")"])
+                new_stg = "".join(["<br>", cur_stg])
+                newline = newline.replace(cur_stg, new_stg)
+
+            if labels[j] == "Cell ID":
+                cls = newline.split(" ")
+                for m in range(0, len(cls)):
+                    if cls[m].startswith("CL"):
+                        cl_id = cls[m].replace("_", ":")
+                        link = "".join(['<a href="http://www.immport-labs.org/immport-ontology/public/home/home/', cl_id, '" target="_blank">'])
+                        cls[m] = "".join([link, cls[m], "</a>"])
+                newline = " ".join(cls)
+            tbl.write("\t".join([labels[j], newline]) + "\n")
+
+    get_graph = " ".join(["mv flowCL_results/*.pdf", output_pdf])
+    os.system(get_graph)
+
+    env = Environment(loader=FileSystemLoader(tool_dir + "/templates"))
+    template = env.get_template("flowCL.template")
+
+    real_directory = output_dir.replace("/job_working_directory", "")
+    context = {'outputDirectory': real_directory}
+    overview = template.render(**context)
+    with open(output_file, "w") as outf:
+        outf.write(overview)
+    return
+
+
+if __name__ == "__main__":
+    parser = ArgumentParser(
+             prog="getOntology",
+             description="runs flowCL on a set of markers.")
+
+    parser.add_argument(
+            '-m',
+            dest="markers",
+            required=True,
+            action='append',
+            help="marker queries.")
+
+    parser.add_argument(
+            '-y',
+            dest="marker_types",
+            required=True,
+            action='append',
+            help="marker queries.")
+
+    parser.add_argument(
+            '-o',
+            dest="output_file",
+            required=True,
+            help="Name of the output html file.")
+
+    parser.add_argument(
+            '-d',
+            dest="output_dir",
+            required=True,
+            help="Path to the html supporting directory")
+
+    parser.add_argument(
+            '-t',
+            dest="tool_dir",
+            required=True,
+            help="Path to the tool directory")
+
+    args = parser.parse_args()
+
+    markers = [m.strip() for m in args.markers]
+    query = generate_flowCL_query(markers, args.marker_types)
+    run_flowCL(query, args.output_file, args.output_dir, args.tool_dir)
+    sys.exit(0)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/getOntology.xml	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,102 @@
+<tool id="get_cell_ontology" name="Explore cell ontology" version="1.0">
+  <description>given a phenotype using flowCL.</description>
+  <requirements>
+    <requirement type="package" version="2.8">jinja2</requirement>
+    <requirement type="package" version="3.2.3">r</requirement>
+    <requirement type="package" version="1.11.1">bioconductor-flowcl</requirement>
+  </requirements>
+ <stdio>
+    <exit_code range="2" level="fatal" description="There was a problem running flowCL. You might want to check your marker names - See stderr for more details." />
+    <exit_code range="3:" level="fatal" description="See stderr for more details." />
+  </stdio>
+  <command><![CDATA[
+      python $__tool_directory__/getOntology.py -o "${html_file}" -d "${html_file.files_path}" -t $__tool_directory__ -m "${marker1}" -y "${type1}"
+      #for $mrkrs in $Markers
+        -m "${mrkrs.markername}"
+        -y "${mrkrs.markertype}"
+      #end for
+  ]]>
+  </command>
+  <inputs>
+    <param name="marker1" type="text" label="First marker"/>
+    <param name="type1" type="select" label="First marker type">
+      <option value="+">+</option>
+      <option value="-">-</option>
+      <option value="lo">lo</option>
+      <option value="lo">low</option>
+      <option value="lo">dim</option>
+      <option value="lo">--</option>
+      <option value="hi">hi</option>
+      <option value="hi">high</option>
+      <option value="hi">bri</option>
+      <option value="hi">bright</option>
+      <option value="hi">++</option>
+    </param>
+    <repeat name="Markers" title="Marker">
+      <param name="markername" type="text" label="Add marker"/>
+      <param name="markertype" type="select" label="Marker type">
+        <option value="+">+</option>
+        <option value="-">-</option>
+        <option value="lo">lo</option>
+        <option value="lo">low</option>
+        <option value="lo">dim</option>
+        <option value="lo">--</option>
+        <option value="hi">hi</option>
+        <option value="hi">high</option>
+        <option value="hi">bri</option>
+        <option value="hi">bright</option>
+        <option value="hi">++</option>
+      </param>
+    </repeat>
+  </inputs>
+  <outputs>
+    <data format="html" name="html_file" label="flowCL run"/>
+  </outputs>
+  <tests>
+    <test>
+      <param name="marker1" value="CD4"/>
+      <param name="type1" value="+"/>
+      <output name="html_file" file="out.html">
+        <extra_files type="file" name="flowCL_res.pdf" value="flowCL_res.pdf" compare="contains"/>
+        <extra_files type="file" name="flowCL_run_summary.txt" value="flowCL_run_summary.txt"/>
+        <extra_files type="file" name="flowCL_table.txt" value="flowCL_table.txt"/>
+      </output>
+    </test>
+  </tests>
+ <help><![CDATA[
+   This tool uses flowCL to find the most likely match to a given set a markers.
+
+-----
+
+**Input**
+
+Type in the marker names and select the expression level in the drop-down menu.
+
+**Output**
+
+A summary of the ouptut of flowCL is captured in a txt file. For more details, please refer to the flowCL documentation.
+
+**Graphical output**
+
+FlowCL generates a plot for the most likely matches to ontology.
+
+-----
+
+**Example**
+
+*Output summary*
+
+The CL terms hyperlink to their representation in the Immport Cell Ontology browser.
+
+.. image:: static/images/flowcl_summary.png
+
+*Graphical output*
+
+.. image:: static/flowtools/flowcl_graph.png
+
+  ]]>
+  </help>
+  <citations>
+    <citation type="doi">10.1093/bioinformatics/btu807</citation>
+  </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/static/flowtools/css/flowCL.css	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,43 @@
+/*
+** DataTables config
+*/
+div.dt-buttons {
+    float: right;
+}
+
+th {
+    font-size:16px;
+    text-align: left;
+}
+
+body td {
+    max-width: 50px;
+    font-size: 14px;
+    overflow: hidden;
+    text-overflow: ellipsis; 
+}
+
+.cltable thead {
+    display:none;
+}
+
+.cltable td {
+    max-width: 40px;
+    word-break: break-all;
+    word-wrap: break-word;
+}
+
+.firstcol {
+    width: 160px;
+}
+
+.smallcols {
+    width: 100px;
+}
+
+div.dataTables_wrapper {
+    width: 95%;
+    margin: 0 auto;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/static/flowtools/js/flowcl_table.js	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,28 @@
+// Copyright (c) 2016 Northrop Grumman.
+// All rights reserved.
+
+var flowcl_table = './flowCL_table.txt';
+
+var displayFlowCLTable = function(){
+  d3.tsv(flowcl_table, function(error, data){
+    if (error){
+      alert("Problem retrieving data");
+      return;
+    }
+    var fclHTML = '<table id="flowcltable" class="cltable display compact" cellspacing="0" width="100%"/>';
+    $('#flowcl').html(fclHTML);
+
+    var fclTableData = $.extend(true, [], data);
+    var fclTable = $('#flowcltable').DataTable({
+      columns: [
+        {"data":"1", className: 'firstcol'},
+        {"data":"2"}
+      ],
+      dom: 't',
+      data: fclTableData,
+      buttons: [
+        'copy', 'pdfHtml5','csvHtml5'
+      ]
+    });
+  });
+};
Binary file flowcl/static/images/flowtools/flowcl_graph.png has changed
Binary file flowcl/static/images/flowtools/flowcl_summary.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/templates/flowCL.template	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+<head lang="en">
+<title>Flow CL Results</title>
+<meta charset="UTF-8">
+<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<link rel="stylesheet" href="/static/flowtools/bootstrap/css/bootstrap.css"/>
+<link rel="stylesheet" href="/static/flowtools/select2/select2.min.css"/>
+<link rel="stylesheet" href="/static/flowtools/css/flowCL.css"/>
+<link rel="stylesheet" href="/static/flowtools/datatables/datatables.min.css"/>
+<link rel="stylesheet" href="/static/flowtools/datatables/Buttons-1.1.2/css/buttons.dataTables.min.css"/>
+<link rel="stylesheet" href="/static/flowtools/datatables/Select-1.1.2/css/select.dataTables.min.css"/>
+<script src="/static/flowtools/jquery-1.11.3.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/bootstrap/js/bootstrap.js" type="text/javascript"></script>
+<script src="/static/flowtools/select2/select2.full.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/d3/d3.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/datatables/datatables.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/js/flowcl_table.js" type="text/javascript"></script>
+
+<style>
+#input{font-family:Calibri,Arial}
+table.dataTable tbody td.dt-body-right {
+    text-align: right;
+}
+#div{padding:5px;width:150px;height:100px;text-align:center}
+table{width:100%;border:0px solid;border-collapse:collapse;text-align:left;}
+th{background-color:#3e6db0;color:#fff;padding:5px}
+</style>
+</head>
+
+<body>
+<div class="container-fluid">
+    <div class="row" style="padding-bottom:10px;min-height:500px;">
+        <div class="col-md-12">
+            <ul class="nav nav-tabs tabs-main">
+                <li class="homeTab active" data-value="flowcl"><a href="#flowcl" data-toggle="tab">FlowCL Results Summary</a></li>
+                <li class="homeTab" data-value="graph"><a href="#graph" data-toggle="tab">Graphical Representation</a></li>
+            </ul>
+
+            <div class="tab-content">
+                <div class="tab-pane active" id="flowcl" style="min-height:500px;">
+                    <div class="row">
+                        <div id="flowcl"/>
+                    </div>
+                </div>
+            </div>
+            <div class="tab-pane" id="graph" style="height:800px;">
+                <embed src="./flowCL_res.pdf" width="100%" height="100%" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html">
+            </div>
+        </div>
+    </div>
+</div>
+
+
+</div>
+</div>
+
+
+<script>
+var summaryLoaded = false;
+
+$().ready(function() {
+    $(document).on('shown.bs.tab','a[data-toggle="tab"]', function(e) {
+      var tab = e.target.getAttribute("href");
+      if (tab == '#flowcl') {
+        if (summaryLoaded) {
+            return true;
+        }
+        summaryLoaded = true;
+        displayFlowCLTable();
+      }
+    });
+
+    summaryLoaded = true;
+    displayFlowCLTable();
+});
+</script>
+</body>
+</html>
Binary file flowcl/test-data/flowCL_res.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/test-data/flowCL_run_summary.txt	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,24 @@
+                      [,1]                                                                   
+Short marker names    "CD4+"                                                                 
+Ontology marker names "CD4 molecule"                                                         
+Experiment markers    "CD4"                                                                  
+Ontology exper. names "CD4 molecule"                                                         
+Successful Match?     "No"                                                                   
+Marker ID             "1) PR_000001004 2) PR_000001004 3) PR_000001004 4) PR_000001004 5)"   
+                      "PR_000001004 + more"                                                  
+Marker Label          "1) CD4 molecule 2) CD4 molecule 3) CD4 molecule 4) CD4 molecule 5)"   
+                      "CD4 molecule + more"                                                  
+Marker Key            "1) { } CD4+ ( ) [ alpha-beta T cell receptor complex+, T cell"        
+                      "receptor co-receptor CD8+ ] 2) { } CD4+ ( ) [ alpha-beta T cell"      
+                      "receptor complex+, T cell receptor co-receptor CD8+ ] 3) { } CD4+ ( )"
+                      "[ alpha-beta T cell receptor complex+, T cell receptor co-receptor"   
+                      "CD8+ ] 4) { } CD4+ ( ) [ T-cell surface glycoprotein CD8 alpha"       
+                      "chain-, alpha-beta T cell receptor complex+ ] 5) { } CD4+ ( ) [ T"    
+                      "cell receptor co-receptor CD8-, alpha-beta T cell receptor complex+," 
+                      "CD3+ ] + more"                                                        
+Score (Out of 1)      "1) 0.333 2) 0.333 3) 0.333 4) 0.333 5) 0.25 + more"                   
+Cell ID               "1) CL_0000809 2) CL_0002427 3) CL_0002428 4) CL_0000810 5) CL_0000492"
+                      "+ more"                                                               
+Cell Label            "1) double-positive, alpha-beta thymocyte 2) resting double-positive"  
+                      "thymocyte 3) double-positive blast 4) CD4-positive, alpha-beta"       
+                      "thymocyte 5) CD4-positive helper T cell + more"                       
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/test-data/flowCL_table.txt	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,12 @@
+1	2
+Short marker names	CD4+
+Ontology marker names	CD4 molecule
+Experiment markers	CD4
+Ontology exper. names	CD4 molecule
+Successful Match?	No
+Marker ID	1) PR_000001004 <br>2) PR_000001004 <br>3) PR_000001004 <br>4) PR_000001004 <br>5) PR_000001004 + more
+Marker Label	1) CD4 molecule <br>2) CD4 molecule <br>3) CD4 molecule <br>4) CD4 molecule <br>5) CD4 molecule + more
+Marker Key	1) { } CD4+ ( ) [ alpha-beta T cell receptor complex+, T cell receptor co-receptor CD8+ ] <br>2) { } CD4+ ( ) [ alpha-beta T cell receptor complex+, T cell receptor co-receptor CD8+ ] <br>3) { } CD4+ ( ) [ alpha-beta T cell receptor complex+, T cell receptor co-receptor CD8+ ] <br>4) { } CD4+ ( ) [ T-cell surface glycoprotein CD8 alpha chain-, alpha-beta T cell receptor complex+ ] <br>5) { } CD4+ ( ) [ T cell receptor co-receptor CD8-, alpha-beta T cell receptor complex+, CD3+ ] + more
+Score (Out of 1)	1) 0.333 <br>2) 0.333 <br>3) 0.333 <br>4) 0.333 <br>5) 0.25 + more
+Cell ID	1) <a href="http://www.immport-labs.org/immport-ontology/public/home/home/CL:0000809" target="_blank">CL_0000809</a> <br>2) <a href="http://www.immport-labs.org/immport-ontology/public/home/home/CL:0002427" target="_blank">CL_0002427</a> <br>3) <a href="http://www.immport-labs.org/immport-ontology/public/home/home/CL:0002428" target="_blank">CL_0002428</a> <br>4) <a href="http://www.immport-labs.org/immport-ontology/public/home/home/CL:0000810" target="_blank">CL_0000810</a> <br>5) <a href="http://www.immport-labs.org/immport-ontology/public/home/home/CL:0000492" target="_blank">CL_0000492</a> + more
+Cell Label	1) double-positive, alpha-beta thymocyte <br>2) resting double-positive thymocyte <br>3) double-positive blast <br>4) CD4-positive, alpha-beta thymocyte <br>5) CD4-positive helper T cell + more
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flowcl/test-data/out.html	Mon Feb 27 12:56:34 2017 -0500
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+<head lang="en">
+<title>Flow CL Results</title>
+<meta charset="UTF-8">
+<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<link rel="stylesheet" href="/static/flowtools/bootstrap/css/bootstrap.css"/>
+<link rel="stylesheet" href="/static/flowtools/select2/select2.min.css"/>
+<link rel="stylesheet" href="/static/flowtools/css/flowCL.css"/>
+<link rel="stylesheet" href="/static/flowtools/datatables/datatables.min.css"/>
+<link rel="stylesheet" href="/static/flowtools/datatables/Buttons-1.1.2/css/buttons.dataTables.min.css"/>
+<link rel="stylesheet" href="/static/flowtools/datatables/Select-1.1.2/css/select.dataTables.min.css"/>
+<script src="/static/flowtools/jquery-1.11.3.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/bootstrap/js/bootstrap.js" type="text/javascript"></script>
+<script src="/static/flowtools/select2/select2.full.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/d3/d3.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/datatables/datatables.min.js" type="text/javascript"></script>
+<script src="/static/flowtools/js/flowcl_table.js" type="text/javascript"></script>
+
+<style>
+#input{font-family:Calibri,Arial}
+table.dataTable tbody td.dt-body-right {
+    text-align: right;
+}
+#div{padding:5px;width:150px;height:100px;text-align:center}
+table{width:100%;border:0px solid;border-collapse:collapse;text-align:left;}
+th{background-color:#3e6db0;color:#fff;padding:5px}
+</style>
+</head>
+
+<body>
+<div class="container-fluid">
+    <div class="row" style="padding-bottom:10px;min-height:500px;">
+        <div class="col-md-12">
+            <ul class="nav nav-tabs tabs-main">
+                <li class="homeTab active" data-value="flowcl"><a href="#flowcl" data-toggle="tab">FlowCL Results Summary</a></li>
+                <li class="homeTab" data-value="graph"><a href="#graph" data-toggle="tab">Graphical Representation</a></li>
+            </ul>
+
+            <div class="tab-content">
+                <div class="tab-pane active" id="flowcl" style="min-height:500px;">
+                    <div class="row">
+                        <div id="flowcl"/>
+                    </div>
+                </div>
+            </div>
+            <div class="tab-pane" id="graph" style="height:800px;">
+                <embed src="./flowCL_res.pdf" width="100%" height="100%" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html"> 
+            </div>
+        </div>
+    </div>
+</div>
+
+
+</div>
+</div>
+
+
+<script>
+var summaryLoaded = false;
+
+$().ready(function() {
+    $(document).on('shown.bs.tab','a[data-toggle="tab"]', function(e) {
+      var tab = e.target.getAttribute("href");
+      if (tab == '#flowcl') {
+        if (summaryLoaded) {
+            return true;
+        }
+        summaryLoaded = true;
+        displayFlowCLTable();
+      }
+    });
+
+    summaryLoaded = true;
+    displayFlowCLTable();
+});
+</script>
+</body>
+</html>
\ No newline at end of file