annotate sicer_wrapper.py @ 3:5c2cc3b58c7d draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
author devteam
date Wed, 28 Oct 2020 23:36:25 +0000
parents 82a8234e03f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
1 #!/usr/bin/env python
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
2 # Dan Blankenberg
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
3
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
4 """
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
5 A wrapper script for running SICER (spatial clustering approach for the identification of ChIP-enriched regions) region caller.
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
6 """
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
7
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
8 import optparse
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
9 import os
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
10 import shutil
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
11 import subprocess
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
12 import sys
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
13 import tempfile
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
14
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
15 CHUNK_SIZE = 2**20 # 1mb
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
16
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
17 # HACK! FIXME: allow using all specified builds, would currently require hacking SICER's "GenomeData.py" on the fly.
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
18 VALID_BUILDS = ['mm8', 'mm9', 'hg18', 'hg19', 'dm2', 'dm3', 'sacCer1', 'pombe', 'rn4', 'tair8']
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
19
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
20
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
21 def cleanup_before_exit(tmp_dir):
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
22 if tmp_dir and os.path.exists(tmp_dir):
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
23 shutil.rmtree(tmp_dir)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
24
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
25
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
26 def open_file_from_option(filename, mode='rb'):
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
27 if filename:
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
28 return open(filename, mode=mode)
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
29 return None
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
30
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
31
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
32 def add_one_to_file_column(filename, column, split_char="\t", startswith_skip=None):
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
33 with tempfile.NamedTemporaryFile(mode='w+b', delete=False) as tmp_out:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
34 with open(filename) as fh:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
35 tmp_path = tmp_out.name
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
36 for line in fh:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
37 if startswith_skip and line.startswith(startswith_skip):
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
38 tmp_out.write(line)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
39 else:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
40 fields = line.rstrip('\n\r').split(split_char)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
41 if len(fields) <= column:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
42 tmp_out.write(line)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
43 else:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
44 fields[column] = str(int(fields[column]) + 1)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
45 tmp_out.write("%s\n" % (split_char.join(fields)))
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
46 shutil.move(tmp_path, filename)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
47
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
48
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
49 def __main__():
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
50 parser = optparse.OptionParser()
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
51 parser.add_option('', '--stdout', dest='stdout', action='store', type="string", default=None, help='If specified, the output of stdout will be written to this file.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
52 parser.add_option('', '--fix_off_by_one_errors', dest='fix_off_by_one_errors', action='store_true', default=False, help='If specified, fix off-by-one errors in output files')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
53 # inputs
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
54 parser.add_option('-b', '--bed_file', dest='bed_file', action='store', type="string", default=None, help='Input ChIP BED file.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
55 parser.add_option('-c', '--control_file', dest='control_file', action='store', type="string", default=None, help='Input control BED file.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
56 parser.add_option('-d', '--dbkey', dest='dbkey', action='store', type="string", default=None, help='Input dbkey.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
57 parser.add_option('-r', '--redundancy_threshold', dest='redundancy_threshold', action='store', type="int", default=1, help='Redundancy Threshold: The number of copies of identical reads allowed in a library.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
58 parser.add_option('-w', '--window_size', dest='window_size', action='store', type="int", default=200, help='Window size: resolution of SICER algorithm. For histone modifications, one can use 200 bp')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
59 parser.add_option('-f', '--fragment_size', dest='fragment_size', action='store', type="int", default=150, help='Fragment size: is for determination of the amount of shift from the beginning of a read to the center of the DNA fragment represented by the read. FRAGMENT_SIZE=150 means the shift is 75.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
60 parser.add_option('-e', '--effective_genome_fraction', dest='effective_genome_fraction', action='store', type="float", default=0.74, help='Effective genome fraction: Effective Genome as fraction of the genome size. It depends on read length.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
61 parser.add_option('-g', '--gap_size', dest='gap_size', action='store', type="int", default=600, help='Gap size: needs to be multiples of window size. Namely if the window size is 200, the gap size should be 0, 200, 400, 600, ... .')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
62 parser.add_option('-o', '--error_cut_off', dest='error_cut_off', action='store', type="string", default="0.1", help='Error Cut off: FDR or E-value') # read as string to construct names properly
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
63 # outputs
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
64 parser.add_option('', '--redundancy_removed_test_bed_output_file', dest='redundancy_removed_test_bed_output_file', action='store', type="string", default=None, help='test-1-removed.bed: redundancy_removed test bed file')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
65 parser.add_option('', '--redundancy_removed_control_bed_output_file', dest='redundancy_removed_control_bed_output_file', action='store', type="string", default=None, help='control-1-removed.bed: redundancy_removed control bed file')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
66 parser.add_option('', '--summary_graph_output_file', dest='summary_graph_output_file', action='store', type="string", default=None, help='test-W200.graph: summary graph file for test-1-removed.bed with window size 200, in bedGraph format.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
67 parser.add_option('', '--test_normalized_wig_output_file', dest='test_normalized_wig_output_file', action='store', type="string", default=None, help='test-W200-normalized.wig: the above file normalized by library size per million and converted into wig format. This file can be uploaded to the UCSC genome browser')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
68 parser.add_option('', '--score_island_output_file', dest='score_island_output_file', action='store', type="string", default=None, help='test-W200-G600.scoreisland: an intermediate file for debugging usage.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
69 parser.add_option('', '--islands_summary_output_file', dest='islands_summary_output_file', action='store', type="string", default=None, help='test-W200-G600-islands-summary: summary of all candidate islands with their statistical significance.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
70 parser.add_option('', '--significant_islands_summary_output_file', dest='significant_islands_summary_output_file', action='store', type="string", default=None, help='test-W200-G600-islands-summary-FDR.01: summary file of significant islands with requirement of FDR=0.01.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
71 parser.add_option('', '--significant_islands_output_file', dest='significant_islands_output_file', action='store', type="string", default=None, help='test-W200-G600-FDR.01-island.bed: delineation of significant islands in "chrom start end read-count-from-redundancy_removed-test.bed" format')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
72 parser.add_option('', '--island_filtered_output_file', dest='island_filtered_output_file', action='store', type="string", default=None, help='test-W200-G600-FDR.01-islandfiltered.bed: library of raw redundancy_removed reads on significant islands.')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
73 parser.add_option('', '--island_filtered_normalized_wig_output_file', dest='island_filtered_normalized_wig_output_file', action='store', type="string", default=None, help='test-W200-G600-FDR.01-islandfiltered-normalized.wig: wig file for the island-filtered redundancy_removed reads.')
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
74 (options, args) = parser.parse_args()
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
75
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
76 # check if valid build
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
77 assert options.dbkey in VALID_BUILDS, ValueError("The specified build ('%s') is not available for this tool." % options.dbkey)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
78
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
79 # everything will occur in this temp directory
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
80 tmp_dir = tempfile.mkdtemp()
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
81
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
82 # link input files into tmp_dir and build command line
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
83 bed_base_filename = 'input_bed_file'
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
84 bed_filename = '%s.bed' % bed_base_filename
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
85 os.symlink(options.bed_file, os.path.join(tmp_dir, bed_filename))
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
86 if options.control_file is not None:
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
87 cmd = "SICER.sh"
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
88 else:
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
89 cmd = "SICER-rb.sh"
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
90 cmd = '%s "%s" "%s"' % (cmd, tmp_dir, bed_filename)
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
91 if options.control_file is not None:
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
92 control_base_filename = 'input_control_file'
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
93 control_filename = '%s.bed' % control_base_filename
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
94 os.symlink(options.control_file, os.path.join(tmp_dir, control_filename))
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
95 cmd = '%s "%s"' % (cmd, control_filename)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
96 cmd = '%s "%s" "%s" "%i" "%i" "%i" "%f" "%i" "%s"' % (cmd, tmp_dir, options.dbkey, options.redundancy_threshold, options.window_size, options.fragment_size, options.effective_genome_fraction, options.gap_size, options.error_cut_off)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
97
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
98 # set up stdout and stderr output options
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
99 stdout = open_file_from_option(options.stdout, mode='wb')
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
100 with tempfile.NamedTemporaryFile(dir=tmp_dir) as stderr:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
101 return_code = subprocess.call(args=cmd, stdout=stdout, stderr=stderr, shell=True, cwd=tmp_dir)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
102
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
103 if return_code:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
104 try:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
105 stderr_target = sys.stderr.buffer
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
106 except AttributeError:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
107 # Python 2
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
108 stderr_target = sys.stderr
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
109 else:
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
110 stderr_target = stdout
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
111 stderr_target.write("\nAdditionally, these warnings were reported:\n")
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
112 stderr.flush()
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
113 stderr.seek(0)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
114 while True:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
115 chunk = stderr.read(CHUNK_SIZE)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
116 if chunk:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
117 stderr_target.write(chunk)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
118 else:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
119 break
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
120 if return_code:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
121 cleanup_before_exit(tmp_dir)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
122 raise Exception("Error running: %s" % cmd)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
123
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
124 try:
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
125 # move files to where they belong
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
126 shutil.move(os.path.join(tmp_dir, '%s-%i-removed.bed' % (bed_base_filename, options.redundancy_threshold)), options.redundancy_removed_test_bed_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
127 shutil.move(os.path.join(tmp_dir, '%s-W%i.graph' % (bed_base_filename, options.window_size)), options.summary_graph_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
128 if options.fix_off_by_one_errors:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
129 add_one_to_file_column(options.summary_graph_output_file, 2)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
130 shutil.move(os.path.join(tmp_dir, '%s-W%i-normalized.wig' % (bed_base_filename, options.window_size)), options.test_normalized_wig_output_file)
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
131 if options.control_file is not None:
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
132 shutil.move(os.path.join(tmp_dir, '%s-%i-removed.bed' % (control_base_filename, options.redundancy_threshold)), options.redundancy_removed_control_bed_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
133 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i.scoreisland' % (bed_base_filename, options.window_size, options.gap_size)), options.score_island_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
134 if options.fix_off_by_one_errors:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
135 add_one_to_file_column(options.score_island_output_file, 2)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
136 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-islands-summary' % (bed_base_filename, options.window_size, options.gap_size)), options.islands_summary_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
137 if options.fix_off_by_one_errors:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
138 add_one_to_file_column(options.islands_summary_output_file, 2)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
139 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-islands-summary-FDR%s' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.significant_islands_summary_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
140 if options.fix_off_by_one_errors:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
141 add_one_to_file_column(options.significant_islands_summary_output_file, 2)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
142 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-FDR%s-island.bed' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.significant_islands_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
143 if options.fix_off_by_one_errors:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
144 add_one_to_file_column(options.significant_islands_output_file, 2)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
145 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-FDR%s-islandfiltered.bed' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.island_filtered_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
146 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-FDR%s-islandfiltered-normalized.wig' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.island_filtered_normalized_wig_output_file)
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
147 else:
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
148 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-E%s.scoreisland' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.score_island_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
149 if options.fix_off_by_one_errors:
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
150 add_one_to_file_column(options.score_island_output_file, 2)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
151 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-E%s-islandfiltered.bed' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.island_filtered_output_file)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
152 shutil.move(os.path.join(tmp_dir, '%s-W%i-G%i-E%s-islandfiltered-normalized.wig' % (bed_base_filename, options.window_size, options.gap_size, options.error_cut_off)), options.island_filtered_normalized_wig_output_file)
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
153 finally:
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
154 cleanup_before_exit(tmp_dir)
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
155
0
82a8234e03f2 Imported from capsule None
devteam
parents:
diff changeset
156
3
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
157 if __name__ == "__main__":
5c2cc3b58c7d "planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sicer commit 0cbb1b33c232da498a31902aa5afcdc97971a74b"
devteam
parents: 0
diff changeset
158 __main__()