Previous changeset 1:dfb1e66235c5 (2018-11-15) Next changeset 3:4130e95bd6c8 (2018-11-19) |
Commit message:
Span version https://github.com/JetBrains-Research/galaxy-applications/commit/cbbba255d66a4775cc35caf5cb85665396fdcd2a |
modified:
span.xml span_wrapper.py |
removed:
README.md |
b |
diff -r dfb1e66235c5 -r 5b99943c4627 README.md --- a/README.md Thu Nov 15 11:30:01 2018 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 |
[ |
@@ -1,3 +0,0 @@ -Release version -=============== -Release is just a `span` snapshot from [https://github.com/JetBrains-Research/galaxy-applications](https://github.com/JetBrains-Research/galaxy-applications) \ No newline at end of file |
b |
diff -r dfb1e66235c5 -r 5b99943c4627 span.xml --- a/span.xml Thu Nov 15 11:30:01 2018 -0500 +++ b/span.xml Sun Nov 18 08:20:27 2018 -0500 |
[ |
b'@@ -1,8 +1,7 @@\n <tool id="span" name="SPAN" version="0.7.1.4272">\n- <description>ChIP-Seq analysis</description>\n+ <description>Semi-supervised Peak Analyzer for ChIP-Seq data</description>\n <requirements>\n <requirement type="package" version="0.7.1.4272">package_span_jar</requirement>\n- <!--<container type="docker">biolabs/span</container>-->\n </requirements>\n <stdio>\n <!-- Wrapper ensures anything other than zero is an error -->\n@@ -10,31 +9,58 @@\n <exit_code range=":-1"/>\n </stdio>\n <command interpreter="python">\n+#import re\n+#set treatment_identifier = re.sub(\'[^\\w\\-\\.]\', \'_\', str($treatment_file.element_identifier))\n+#set genome_identifier = re.sub(\'[^\\w\\-\\.]\', \'_\', str($genome_file.element_identifier))\n+\n+#if $control.control_selector\n+ #set control_identifier = re.sub(\'[^\\w\\-\\.]\', \'_\', str($control.control_file.element_identifier))\n+#end if\n+\n #if str($action.action_selector) == "model"\n #if $control.control_selector\n- span_wrapper.py model with_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${control.control_file}"\n+ span_wrapper.py model with_control\n+ "${genome_identifier}" "${genome_file}"\n+ "${treatment_identifier}" "${treatment_file}"\n+ "${bin}" "${action.model_file}"\n+ "${control_identifier}" "${control.control_file}"\n #else\n- span_wrapper.py model without_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}"\n+ span_wrapper.py model without_control\n+ "${genome_identifier}" "${genome_file}"\n+ "${treatment_identifier}" "${treatment_file}"\n+ "${bin}" "${action.model_file}"\n #end if\n #else\n #if $control.control_selector\n- span_wrapper.py peaks with_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${control.control_file}" "${fdr}" "${gap}" "${action.peaks_file}"\n+ span_wrapper.py peaks with_control\n+ "${genome_identifier}" "${genome_file}"\n+ "${treatment_identifier}" "${treatment_file}"\n+ "${bin}" "${action.model_file}"\n+ "${control_identifier}" "${control.control_file}"\n+ "${action.fdr}" "${action.gap}" "${action.peaks_file}"\n #else\n- span_wrapper.py peaks without_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${fdr}" "${gap}" "${action.peaks_file}"\n+ span_wrapper.py peaks without_control\n+ "${genome_identifier}" "${genome_file}"\n+ "${treatment_identifier}" "${treatment_file}"\n+ "${bin}" "${action.model_file}"\n+ "${action.fdr}" "${action.gap}" "${action.peaks_file}"\n #end if\n #end if\n </command>\n <inputs>\n <param name="treatment_file" type="data" format="bam" label="Treatment BAM"\n- description="Treatment BAM reads to process"/>\n- <param name="genome" type="data" format="chrom.sizes" label="Genome chrom.sizes"\n- description="Genome build chrom.sizes file"/>\n+ description="Treatment BAM reads to process" argument="--treatment"\n+ help="Treatment BAM reads to process"/>\n+ <param name="genome_file" type="data" format="chrom.sizes" label="Genome chrom.sizes"\n+ description="Genome build chrom.sizes file" argument="--chrom.sizes"\n+ help="Genome build chrom.sizes file"/>\n \n <conditional name="control">\n <param name="control_selector" type="boolean" label="Control available" value="false"/>\n <when value="true">\n <param name="control_file" type="data" format="bam" label="Control BAM"\n- description="Control BAM reads to process"/>\n+ description="Control BAM reads to process" argument="--control"\n+ help="Control BAM reads to process"/>\n </when>\n </conditional>\n \n@@ -44,26 +70,107 '..b'procedure."/>\n+ <param name="gap" size="5" type="integer" value="5" label="GAP" argument="--gap"\n+ help="Gap size to merge spatially close peaks. Useful for wide histone modifications.\n+ Default value is 5, i.e. peaks separated by 5*BIN distance or less are merged."/>\n+ <param name="peaks_file" type="text" value="result.peak" label="Peaks file name" argument="--peaks"/>\n </when>\n </conditional>\n \n- <param name="bin" size="5" type="integer" value="200" label="Bin size"/>\n+ <param name="bin" size="5" type="integer" value="200" label="Bin size" argument="--bin"\n+ help="Peak analysis is performed on read coverage tiled into consequent bins, with size being configurable.\n+ Default value is 200bp, approximately the length of one nucleosome."/>\n </inputs>\n <outputs>\n- <data name="${action.model_file}" format="span" label="SPAN model file"/>\n- <data name="${action.peaks_file}" format="bed" label="SPAN peaks file">\n+ <data name="SPAN model file" format="span" from_work_dir="*.span" label="SPAN model file ${action.model_file} on ${on_string}"/>\n+ <data name="SPAN peaks file" format="bed" from_work_dir="*.peak" label="SPAN peaks file ${action.peaks_file} on ${on_string}">\n <filter>action[\'action_selector\'] == "peaks"</filter>\n </data>\n+ <data name="SPAN log file" format="txt" from_work_dir="*.log" label="SPAN log file on ${on_string}"/>\n </outputs>\n- <help>\n- SPAN Semi-supervised Peak Analyzer is a tool for analyzing ChIP-seq data.\n- Details: http://artyomovlab.wustl.edu/aging/span.html\n- </help>\n+ <help><![CDATA[\n+.. class:: infomark\n+\n+**What it does**\n+\n+SPAN Semi-supervised Peak Analyzer is a tool for analyzing ChIP-seq data.\n+\n+-----\n+\n+**Inputs**\n+\n+*-t, --treatment <Path>* **Required.** ChIP-seq treatment file. bam, bed or .bed.gz file; If multiple files are given, treated as replicates.\n+\n+*--chrom.sizes, --cs <Path>* **Required.** Chromosome sizes path, can be downloaded at http://hgdownload.cse.ucsc.edu/goldenPath/<build>/bigZips/<build>.chrom.sizes\n+\n+*-c, --control <Path>* Control file. bam, bed or bed.gz file; Single control file or separate file per each treatment file required.\n+\n+*--fragment <Integer>* Fragment size, read length if not given\n+\n+*-b, --bin <Integer>* Bin size\n+\n+*-f, --fdr <Double>* Fdr value\n+\n+*-g, --gap <Integer>* Gap size to merge peaks\n+\n+*-p, --peaks <Path>* Path to result peaks file in ENCODE broadPeak (BED 6+3) format\n+\n+\n+-----\n+\n+**Outputs**\n+\n+This tool produces a SPAN binary model file and/or peaks in ENCODE broadPeak (BED 6+3) format.\n+\n+Peak file columns contain the following data:\n+\n+* **1st**: chromosome name\n+* **2nd**: start position of peak\n+* **3rd**: end position of peak\n+* **4th**: name of peak\n+* **5th**: integer score for display in genome browser (e.g. UCSC)\n+* **6th**: strand, either "." (=no strand) or "+" or "-"\n+* **7th**: fold-change\n+* **8th**: -log10pvalue\n+* **9th**: -log10qvalue\n+\n+-----\n+\n+**SPAN workflow**\n+\n+* Convert raw reads to tags using *FRAGMENT* parameter.\n+* Compute coverage for all genome tiled into bins of *BIN* base pairs.\n+* Fit 3-state hidden Markov model that classifies bins as ZERO states with no coverage, LOW states of non-specific binding, and HIGH states of the specific binding.\n+* Compute posterior HIGH state probability of each bin.\n+* Trained model is saved into *.span* binary format.\n+* Peaks are computed using trained model and *FDR* and *GAP* parameters.\n+\n+------\n+\n+**Citation**\n+\n+If you use this tool in Galaxy, please cite XXX, et al. *In preparation.*\n+\n+-----\n+\n+**More Information**\n+\n+* Project home page: https://research.jetbrains.org/groups/biolabs/tools/span-peak-analyzer\n+* Study cases: https://artyomovlab.wustl.edu/aging\n+\n+]]></help>\n </tool>\n' |
b |
diff -r dfb1e66235c5 -r 5b99943c4627 span_wrapper.py --- a/span_wrapper.py Thu Nov 15 11:30:01 2018 -0500 +++ b/span_wrapper.py Sun Nov 18 08:20:27 2018 -0500 |
[ |
@@ -1,67 +1,135 @@ #!/usr/bin/env python import os +import shutil +import subprocess import sys -import subprocess + argv = sys.argv[1:] print 'Arguments {0}'.format(argv) SPAN_JAR = os.environ.get("SPAN_JAR") -# span.jar from Docker container -# SPAN_JAR = "/root/span.jar" print 'Using SPAN Peak Analyzer distributive file {0}'.format(SPAN_JAR) -# #if $action.action_selector -# #if str($control.control_selector) == "with_control" -# span_wrapper.py model with_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${control.control_file}" +# #if str($action.action_selector) == "model" +# #if $control.control_selector +# span_wrapper.py model with_control +# "${genome_identifier}" "${genome_file}" +# "${treatment_identifier}" "${treatment_file}" +# "${bin}" "${action.model_file}" +# "${control_identifier}" "${control.control_file}" # #else -# span_wrapper.py model without_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" +# span_wrapper.py model without_control +# "${genome_identifier}" "${genome_file}" +# "${treatment_identifier}" "${treatment_file}" +# "${bin}" "${action.model_file}" # #end if # #else # #if $control.control_selector -# span_wrapper.py peaks with_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${control.control_file}" "${fdr}" "${gap}" "${action.peaks_file}" +# span_wrapper.py peaks with_control +# "${genome_identifier}" "${genome_file}" +# "${treatment_identifier}" "${treatment_file}" +# "${bin}" "${action.model_file}" +# "${control_identifier}" "${control.control_file}" +# "${fdr}" "${gap}" "${action.peaks_file}" # #else -# span_wrapper.py peaks without_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${fdr}" "${gap}" "${action.peaks_file}" +# span_wrapper.py peaks with_control +# "${genome_identifier}" "${genome_file}" +# "${treatment_identifier}" "${treatment_file}" +# "${bin}" "${action.model_file}" +# "${fdr}" "${gap}" "${action.peaks_file}" # #end if # #end if -# See http://artyomovlab.wustl.edu/aging/span.html for command line options +# See https://research.jetbrains.org/groups/biolabs/tools/span-peak-analyzer for command line options action = argv[0] control = argv[1] + +working_dir = os.path.abspath('.') +print 'WORKING DIRECTORY: {}'.format(working_dir) + + +def link(name, f): + """ SPAN uses file extension to detect input type, so original names are necessary, instead of Galaxy .dat files""" + result = os.path.join(working_dir, name) + os.symlink(f, result) + return result + + if action == 'model': if control == 'with_control': - (chrom_sizes, treatment_file, bin, model_file, control_file) = argv[2:] + (chrom_sizes, chrom_sizes_file, + treatment, treatment_file, + bin, model_file, + control, control_file) = argv[2:] cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {}'.format( - SPAN_JAR, chrom_sizes, treatment_file, control_file, bin + SPAN_JAR, + link(chrom_sizes, chrom_sizes_file), + link(treatment, treatment_file), + link(control, control_file), + bin ) - print "MODEL FILE" + model_file elif control == 'without_control': - (chrom_sizes, treatment_file, bin, model_file) = argv[2:] + (chrom_sizes, chrom_sizes_file, + treatment, treatment_file, + bin, model_file) = argv[2:] cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {}'.format( - SPAN_JAR, argv[2], argv[3], argv[4] + SPAN_JAR, + link(chrom_sizes, chrom_sizes_file), + link(treatment, treatment_file), + bin ) - print "MODEL FILE" + model_file else: raise Exception("Unknown control option {}".format(control)) elif action == "peaks": if control == 'with_control': - (chrom_sizes, treatment_file, bin, model_file, control_file, fdr, gap, peaks_file) = argv[2:] + (chrom_sizes, chrom_sizes_file, + treatment, treatment_file, + bin, model_file, + control, control_file, + fdr, gap, peaks_file) = argv[2:] cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {} --fdr {} --gap {} --peaks {}'.format( - SPAN_JAR, chrom_sizes, treatment_file, control_file, bin, fdr, gap, peaks_file + SPAN_JAR, + link(chrom_sizes, chrom_sizes_file), + link(treatment, treatment_file), + link(control, control_file), + bin, fdr, gap, + os.path.join(working_dir, peaks_file) ) - print "MODEL FILE" + model_file elif control == 'without_control': - (chrom_sizes, treatment_file, bin, model_file, fdr, gap, peaks_file) = argv[2:] + (chrom_sizes, chrom_sizes_file, + treatment, treatment_file, + bin, model_file, + fdr, gap, peaks_file) = argv[2:] cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {} --fdr {} --gap {} --peaks {}'.format( - SPAN_JAR, chrom_sizes, treatment_file, bin, fdr, gap, peaks_file + SPAN_JAR, + link(chrom_sizes, chrom_sizes_file), + link(treatment, treatment_file), + bin, fdr, gap, + os.path.join(working_dir, peaks_file) ) - print "MODEL FILE" + model_file else: raise Exception("Unknown control option {}".format(control)) else: raise Exception("Unknown action command {}".format(action)) -print 'Launching SPAN: {0}'.format(cmd) +print 'Launching SPAN: {}'.format(cmd) +print 'Model file: {}'.format(model_file) +try: + print 'Peaks file: {}'.format(peaks_file) +except NameError: + pass + subprocess.check_call(cmd, cwd=None, shell=True) + +# Move model to the the working dir with given name +fit_dir = os.path.join(working_dir, 'fit') +model_original = os.path.join(fit_dir, os.listdir(fit_dir)[0]) +shutil.move(model_original, os.path.join(working_dir, model_file)) + +# Move log file +logs_dir = os.path.join(working_dir, 'logs') +log_original = os.path.join(logs_dir, os.listdir(logs_dir)[0]) +shutil.move(log_original, os.path.join(working_dir, "span.log")) |