Mercurial > repos > jetbrains > span
comparison span_wrapper.py @ 2:5b99943c4627 draft
Span version https://github.com/JetBrains-Research/galaxy-applications/commit/cbbba255d66a4775cc35caf5cb85665396fdcd2a
| author | jetbrains |
|---|---|
| date | Sun, 18 Nov 2018 08:20:27 -0500 |
| parents | 1f0c4f0a9c3b |
| children | 4130e95bd6c8 |
comparison
equal
deleted
inserted
replaced
| 1:dfb1e66235c5 | 2:5b99943c4627 |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 import os | 3 import os |
| 4 import shutil | |
| 5 import subprocess | |
| 4 import sys | 6 import sys |
| 5 import subprocess | 7 |
| 6 argv = sys.argv[1:] | 8 argv = sys.argv[1:] |
| 7 print 'Arguments {0}'.format(argv) | 9 print 'Arguments {0}'.format(argv) |
| 8 | 10 |
| 9 SPAN_JAR = os.environ.get("SPAN_JAR") | 11 SPAN_JAR = os.environ.get("SPAN_JAR") |
| 10 # span.jar from Docker container | |
| 11 # SPAN_JAR = "/root/span.jar" | |
| 12 print 'Using SPAN Peak Analyzer distributive file {0}'.format(SPAN_JAR) | 12 print 'Using SPAN Peak Analyzer distributive file {0}'.format(SPAN_JAR) |
| 13 | 13 |
| 14 # #if $action.action_selector | 14 # #if str($action.action_selector) == "model" |
| 15 # #if str($control.control_selector) == "with_control" | 15 # #if $control.control_selector |
| 16 # span_wrapper.py model with_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${control.control_file}" | 16 # span_wrapper.py model with_control |
| 17 # "${genome_identifier}" "${genome_file}" | |
| 18 # "${treatment_identifier}" "${treatment_file}" | |
| 19 # "${bin}" "${action.model_file}" | |
| 20 # "${control_identifier}" "${control.control_file}" | |
| 17 # #else | 21 # #else |
| 18 # span_wrapper.py model without_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" | 22 # span_wrapper.py model without_control |
| 23 # "${genome_identifier}" "${genome_file}" | |
| 24 # "${treatment_identifier}" "${treatment_file}" | |
| 25 # "${bin}" "${action.model_file}" | |
| 19 # #end if | 26 # #end if |
| 20 # #else | 27 # #else |
| 21 # #if $control.control_selector | 28 # #if $control.control_selector |
| 22 # span_wrapper.py peaks with_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${control.control_file}" "${fdr}" "${gap}" "${action.peaks_file}" | 29 # span_wrapper.py peaks with_control |
| 30 # "${genome_identifier}" "${genome_file}" | |
| 31 # "${treatment_identifier}" "${treatment_file}" | |
| 32 # "${bin}" "${action.model_file}" | |
| 33 # "${control_identifier}" "${control.control_file}" | |
| 34 # "${fdr}" "${gap}" "${action.peaks_file}" | |
| 23 # #else | 35 # #else |
| 24 # span_wrapper.py peaks without_control "${genome}" "${treatment_file}" "${bin}" "${action.model_file}" "${fdr}" "${gap}" "${action.peaks_file}" | 36 # span_wrapper.py peaks with_control |
| 37 # "${genome_identifier}" "${genome_file}" | |
| 38 # "${treatment_identifier}" "${treatment_file}" | |
| 39 # "${bin}" "${action.model_file}" | |
| 40 # "${fdr}" "${gap}" "${action.peaks_file}" | |
| 25 # #end if | 41 # #end if |
| 26 # #end if | 42 # #end if |
| 27 | 43 |
| 28 # See http://artyomovlab.wustl.edu/aging/span.html for command line options | 44 # See https://research.jetbrains.org/groups/biolabs/tools/span-peak-analyzer for command line options |
| 29 action = argv[0] | 45 action = argv[0] |
| 30 control = argv[1] | 46 control = argv[1] |
| 47 | |
| 48 working_dir = os.path.abspath('.') | |
| 49 print 'WORKING DIRECTORY: {}'.format(working_dir) | |
| 50 | |
| 51 | |
| 52 def link(name, f): | |
| 53 """ SPAN uses file extension to detect input type, so original names are necessary, instead of Galaxy .dat files""" | |
| 54 result = os.path.join(working_dir, name) | |
| 55 os.symlink(f, result) | |
| 56 return result | |
| 57 | |
| 58 | |
| 31 if action == 'model': | 59 if action == 'model': |
| 32 if control == 'with_control': | 60 if control == 'with_control': |
| 33 (chrom_sizes, treatment_file, bin, model_file, control_file) = argv[2:] | 61 (chrom_sizes, chrom_sizes_file, |
| 62 treatment, treatment_file, | |
| 63 bin, model_file, | |
| 64 control, control_file) = argv[2:] | |
| 34 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {}'.format( | 65 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {}'.format( |
| 35 SPAN_JAR, chrom_sizes, treatment_file, control_file, bin | 66 SPAN_JAR, |
| 67 link(chrom_sizes, chrom_sizes_file), | |
| 68 link(treatment, treatment_file), | |
| 69 link(control, control_file), | |
| 70 bin | |
| 36 ) | 71 ) |
| 37 print "MODEL FILE" + model_file | |
| 38 elif control == 'without_control': | 72 elif control == 'without_control': |
| 39 (chrom_sizes, treatment_file, bin, model_file) = argv[2:] | 73 (chrom_sizes, chrom_sizes_file, |
| 74 treatment, treatment_file, | |
| 75 bin, model_file) = argv[2:] | |
| 40 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {}'.format( | 76 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {}'.format( |
| 41 SPAN_JAR, argv[2], argv[3], argv[4] | 77 SPAN_JAR, |
| 78 link(chrom_sizes, chrom_sizes_file), | |
| 79 link(treatment, treatment_file), | |
| 80 bin | |
| 42 ) | 81 ) |
| 43 print "MODEL FILE" + model_file | |
| 44 else: | 82 else: |
| 45 raise Exception("Unknown control option {}".format(control)) | 83 raise Exception("Unknown control option {}".format(control)) |
| 46 | 84 |
| 47 elif action == "peaks": | 85 elif action == "peaks": |
| 48 if control == 'with_control': | 86 if control == 'with_control': |
| 49 (chrom_sizes, treatment_file, bin, model_file, control_file, fdr, gap, peaks_file) = argv[2:] | 87 (chrom_sizes, chrom_sizes_file, |
| 88 treatment, treatment_file, | |
| 89 bin, model_file, | |
| 90 control, control_file, | |
| 91 fdr, gap, peaks_file) = argv[2:] | |
| 50 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {} --fdr {} --gap {} --peaks {}'.format( | 92 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --control {} --bin {} --fdr {} --gap {} --peaks {}'.format( |
| 51 SPAN_JAR, chrom_sizes, treatment_file, control_file, bin, fdr, gap, peaks_file | 93 SPAN_JAR, |
| 94 link(chrom_sizes, chrom_sizes_file), | |
| 95 link(treatment, treatment_file), | |
| 96 link(control, control_file), | |
| 97 bin, fdr, gap, | |
| 98 os.path.join(working_dir, peaks_file) | |
| 52 ) | 99 ) |
| 53 print "MODEL FILE" + model_file | |
| 54 elif control == 'without_control': | 100 elif control == 'without_control': |
| 55 (chrom_sizes, treatment_file, bin, model_file, fdr, gap, peaks_file) = argv[2:] | 101 (chrom_sizes, chrom_sizes_file, |
| 102 treatment, treatment_file, | |
| 103 bin, model_file, | |
| 104 fdr, gap, peaks_file) = argv[2:] | |
| 56 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {} --fdr {} --gap {} --peaks {}'.format( | 105 cmd = 'java -jar {} analyze --chrom.sizes {} --treatment {} --bin {} --fdr {} --gap {} --peaks {}'.format( |
| 57 SPAN_JAR, chrom_sizes, treatment_file, bin, fdr, gap, peaks_file | 106 SPAN_JAR, |
| 107 link(chrom_sizes, chrom_sizes_file), | |
| 108 link(treatment, treatment_file), | |
| 109 bin, fdr, gap, | |
| 110 os.path.join(working_dir, peaks_file) | |
| 58 ) | 111 ) |
| 59 print "MODEL FILE" + model_file | |
| 60 else: | 112 else: |
| 61 raise Exception("Unknown control option {}".format(control)) | 113 raise Exception("Unknown control option {}".format(control)) |
| 62 else: | 114 else: |
| 63 raise Exception("Unknown action command {}".format(action)) | 115 raise Exception("Unknown action command {}".format(action)) |
| 64 | 116 |
| 65 | 117 |
| 66 print 'Launching SPAN: {0}'.format(cmd) | 118 print 'Launching SPAN: {}'.format(cmd) |
| 119 print 'Model file: {}'.format(model_file) | |
| 120 try: | |
| 121 print 'Peaks file: {}'.format(peaks_file) | |
| 122 except NameError: | |
| 123 pass | |
| 124 | |
| 67 subprocess.check_call(cmd, cwd=None, shell=True) | 125 subprocess.check_call(cmd, cwd=None, shell=True) |
| 126 | |
| 127 # Move model to the the working dir with given name | |
| 128 fit_dir = os.path.join(working_dir, 'fit') | |
| 129 model_original = os.path.join(fit_dir, os.listdir(fit_dir)[0]) | |
| 130 shutil.move(model_original, os.path.join(working_dir, model_file)) | |
| 131 | |
| 132 # Move log file | |
| 133 logs_dir = os.path.join(working_dir, 'logs') | |
| 134 log_original = os.path.join(logs_dir, os.listdir(logs_dir)[0]) | |
| 135 shutil.move(log_original, os.path.join(working_dir, "span.log")) |
