changeset 6:70500fd87b60 draft

Advanced options: threads and memory configuration
author jetbrains
date Wed, 21 Nov 2018 10:31:58 -0500
parents d87ecbc477d8
children caaea0a5c425
files span.xml span_wrapper.py
diffstat 2 files changed, 57 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/span.xml	Wed Nov 21 06:29:41 2018 -0500
+++ b/span.xml	Wed Nov 21 10:31:58 2018 -0500
@@ -1,4 +1,4 @@
-<tool id="span" name="SPAN" version="0.7.1.4518">
+<tool id="span" name="SPAN" version="0.7.1.4518a">
     <description>Semi-supervised Peak Analyzer for ChIP-Seq data</description>
     <requirements>
         <requirement type="package" version="0.7.1.4518">package_span_jar</requirement>
@@ -11,27 +11,35 @@
     <command interpreter="python">
 #if str($action.action_selector) == "model"
     #if str($control_file) != 'None':
-        span_wrapper.py model_with_control
+        span_wrapper.py
+            "${advanced_options.memory}" "${advanced_options.threads}"
+            model_with_control
             "${genome_file.name}" "${genome_file}"
             "${treatment_file.name}" "${treatment_file}"
             "${control_file.name}" "${control_file}"
             "${bin}"
     #else
-        span_wrapper.py model_without_control
+        span_wrapper.py
+            "${advanced_options.memory}" "${advanced_options.threads}"
+            model_without_control
             "${genome_file.name}" "${genome_file}"
             "${treatment_file.name}" "${treatment_file}"
             "${bin}"
     #end if
 #else
     #if str($control_file) != 'None':
-        span_wrapper.py peaks_with_control
+        span_wrapper.py
+            "${advanced_options.memory}" "${advanced_options.threads}"
+            peaks_with_control
             "${genome_file.name}" "${genome_file}"
             "${treatment_file.name}" "${treatment_file}"
             "${control_file.name}" "${control_file}"
             "${bin}"
             "${action.fdr}" "${action.gap}"
     #else
-        span_wrapper.py peaks_without_control
+        span_wrapper.py
+            "${advanced_options.memory}" "${advanced_options.threads}"
+            peaks_without_control
             "${genome_file.name}" "${genome_file}"
             "${treatment_file.name}" "${treatment_file}"
             "${bin}"
@@ -57,21 +65,29 @@
                 <option value="peaks">Compute SPAN model and produce peaks file</option>
             </param>
             <when value="peaks">
-                <param name="fdr" size="5" type="float" value="0.0001" label="FDR" argument="--fdr"
+                <param name="fdr" size="5" type="float" value="0.0001" min="0" label="FDR" argument="--fdr"
                        help="Minimum FDR cutoff to call significant regions, default value is 1.0E-6.
                        SPAN reports p- and q- values for the null hypothesis that a given bin is not enriched with a histone modification.
                        Peaks are formed from a list of truly (in the FDR sense) enriched bins for the analyzed biological condition by thresholding the
                        Q-value with a cutoff FDR and merging spatially close peaks using GAP option to broad ones. This is equivalent to controlling FDR.
                        q-values are are calculated from p-values using Benjamini-Hochberg procedure."/>
-                <param name="gap" size="5" type="integer" value="5" label="GAP" argument="--gap"
+                <param name="gap" size="3" type="integer" value="5" min="0" label="GAP" argument="--gap"
                        help="Gap size to merge spatially close peaks. Useful for wide histone modifications.
                        Default value is 5, i.e. peaks separated by 5*BIN distance or less are merged."/>
             </when>
         </conditional>
 
-        <param name="bin" size="5" type="integer" value="200" label="Bin size" argument="--bin"
+        <param name="bin" size="5" type="integer" value="200" min="50" label="Bin size" argument="--bin"
                help="Peak analysis is performed on read coverage tiled into consequent bins, with size being configurable.
                Default value is 200bp, approximately the length of one nucleosome."/>
+
+        <section name="advanced_options" title="Advanced Options">
+            <param name="memory" size="6" type="integer" value="2048" min="1024"
+                   label="Memory limit in megabytes" help="Default value is 2048 megabytes"/>
+            <param name="threads" argument="--threads" size="2" type="integer" value="2" min="1"
+                   label="Threads number"
+                   help="Default value is 2 threads. SPAN utilizes both multithreading and specialized processor extensions like SSE2, AVX, etc."/>
+        </section>
     </inputs>
     <outputs>
         <data name="model.span" format="span" from_work_dir="*.span"
--- a/span_wrapper.py	Wed Nov 21 06:29:41 2018 -0500
+++ b/span_wrapper.py	Wed Nov 21 10:31:58 2018 -0500
@@ -11,37 +11,10 @@
 SPAN_JAR = os.environ.get("SPAN_JAR")
 print 'Using SPAN Peak Analyzer distributive file {0}'.format(SPAN_JAR)
 
-# #if str($action.action_selector) == "model"
-#     #if str($control_file) != 'None':
-#         span_wrapper.py model_with_control
-#             "${genome_identifier}" "${genome_file}"
-#             "${treatment_identifier}" "${treatment_file}"
-#             "${control_identifier}" "${control_file}"
-#             "${bin}"
-#
-#     #else
-#         span_wrapper.py model without_control
-#             "${genome_identifier}" "${genome_file}"
-#             "${treatment_identifier}" "${treatment_file}"
-#             "${bin}"
-#     #end if
-# #else
-#     #if str($control_file) != 'None':
-#         span_wrapper.py peaks_with_control
-#             "${genome_identifier}" "${genome_file}"
-#             "${treatment_identifier}" "${treatment_file}"
-#             "${control_identifier}" "${control_file}"
-#             "${bin}"
-#             "${action.fdr}" "${action.gap}"
-#     #else
-#         span_wrapper.py peaks_without_control
-#             "${genome_identifier}" "${genome_file}"
-#             "${treatment_identifier}" "${treatment_file}"
-#             "${bin}"
-#             "${action.fdr}" "${action.gap}"
-#     #end if
-# #end if
-action = argv[0]
+MEMORY = argv[0]
+THREADS = argv[1]
+ACTION = argv[2]
+argv = argv[3:]
 
 working_dir = os.path.abspath('.')
 print 'WORKING DIRECTORY: {}'.format(working_dir)
@@ -55,54 +28,64 @@
     return result
 
 
-if action == 'model_with_control':
+if ACTION == 'model_with_control':
     (chrom_sizes, chrom_sizes_file,
      treatment, treatment_file,
      control, control_file,
-     bin) = argv[1:]
-    cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {}'.format(
-        SPAN_JAR,
+     bin) = argv
+    cmd = 'java -Xmx{}m -jar {} analyze --threads {} ' \
+          '--chrom.sizes {} --treatment {} --control {} --bin {}'.format(
+        MEMORY, SPAN_JAR, THREADS,
         link(chrom_sizes, chrom_sizes_file),
         link(treatment, treatment_file),
         link(control, control_file),
         bin)
-elif action == 'model_without_control':
+
+elif ACTION == 'model_without_control':
     (chrom_sizes, chrom_sizes_file,
      treatment, treatment_file,
-     bin) = argv[1:]
-    cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {}'.format(
-        SPAN_JAR,
+     bin) = argv
+    cmd = 'java -Xmx{}m -jar {} analyze --threads {} ' \
+          '--chrom.sizes {} --treatment {} --bin {}'.format(
+        MEMORY, SPAN_JAR, THREADS,
         link(chrom_sizes, chrom_sizes_file),
         link(treatment, treatment_file),
         bin)
-elif action == "peaks_with_control":
+
+elif ACTION == "peaks_with_control":
     (chrom_sizes, chrom_sizes_file,
      treatment, treatment_file,
      control, control_file,
      bin,
-     fdr, gap) = argv[1:]
-    cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} ' \
-          '--bin {} --fdr {} --gap {} --peaks {}'.format(
-        SPAN_JAR,
+     fdr, gap) = argv
+    cmd = 'java -Xmx{}m -jar {} analyze --threads {} ' \
+          '--chrom.sizes {} --treatment {} --control {} --bin {} --fdr {} --gap {} --peaks {}'.format(
+        MEMORY, SPAN_JAR, THREADS,
         link(chrom_sizes, chrom_sizes_file),
         link(treatment, treatment_file),
         link(control, control_file),
         bin, fdr, gap,
         os.path.join(working_dir, 'result.peak'))
-elif action == 'peaks_without_control':
+
+elif ACTION == 'peaks_without_control':
     (chrom_sizes, chrom_sizes_file,
      treatment, treatment_file,
      bin,
-     fdr, gap) = argv[1:]
-    cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} -' \
-          '-bin {} --fdr {} --gap {} --peaks {}'.format(
-        SPAN_JAR,
+     fdr, gap) = argv
+    cmd = 'java -Xmx{}m -jar {} analyze --threads {} ' \
+          '--chrom.sizes {} --treatment {} -bin {} --fdr {} --gap {} --peaks {}'.format(
+        MEMORY, SPAN_JAR, THREADS,
         link(chrom_sizes, chrom_sizes_file),
         link(treatment, treatment_file),
         bin, fdr, gap,
         os.path.join(working_dir, 'result.peak'))
+    (chrom_sizes, chrom_sizes_file,
+     treatment, treatment_file,
+     bin,
+     fdr, gap) = argv
+
 else:
-    raise Exception("Unknown action command {}".format(action))
+    raise Exception("Unknown action command {}".format(ACTION))
 
 print 'Launching SPAN: {}'.format(cmd)
 subprocess.check_call(cmd, cwd=None, shell=True)