annotate bismark_wrapper.py @ 15:0b656f8c5637 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit ec1f38df34e6862abd0b8e7cc0521e25f9933567
author bgruening
date Thu, 01 Aug 2019 10:47:13 -0400
parents 7bffcb6fc81d
children a4504327c890
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
2
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
3 import argparse
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
4 import fileinput
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
5 import logging
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
6 import math
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
7 import os
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
8 import shutil
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
9 import subprocess
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
10 import sys
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
11 import tempfile
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
12 from glob import glob
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
13
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
14
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
15 def stop_err(logger, msg):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
16 logger.critical(msg)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
17 sys.exit(1)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
18
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
19
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
20 def log_subprocess_output(logger, pipe):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
21 for line in iter(pipe.readline, b''):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
22 logger.debug(line.decode().rstrip())
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
23
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
24
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
25 def __main__():
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
26 # Parse Command Line
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
27 parser = argparse.ArgumentParser(description='Wrapper for the bismark bisulfite mapper.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
28 parser.add_argument('-p', '--num-threads', dest='num_threads',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
29 type=int, default=4, help='Use this many threads to align reads. The default is 4.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
30
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
31 # input options
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
32 parser.add_argument('--own-file', dest='own_file', help='')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
33 parser.add_argument('-D', '--indexes-path', dest='index_path',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
34 help='Indexes directory; location of .ebwt and .fa files.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
35 parser.add_argument('-O', '--output', dest='output')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
36
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
37 parser.add_argument('--output-report-file', dest='output_report_file')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
38 parser.add_argument('--suppress-header', dest='suppress_header', action="store_true")
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
39
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
40 parser.add_argument('--mate-paired', dest='mate_paired', action='store_true', help='Reads are mate-paired',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
41 default=False)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
42
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
43 parser.add_argument('-1', '--mate1', dest='mate1',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
44 help='The forward reads file in Sanger FASTQ or FASTA format.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
45 parser.add_argument('-2', '--mate2', dest='mate2',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
46 help='The reverse reads file in Sanger FASTQ or FASTA format.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
47 parser.add_argument('--sort-bam', dest='sort_bam', action="store_true")
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
48
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
49 parser.add_argument('--output-unmapped-reads', dest='output_unmapped_reads',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
50 help='Additional output file with unmapped reads (single-end).')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
51 parser.add_argument('--output-unmapped-reads-l', dest='output_unmapped_reads_l',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
52 help='File name for unmapped reads (left, paired-end).')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
53 parser.add_argument('--output-unmapped-reads-r', dest='output_unmapped_reads_r',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
54 help='File name for unmapped reads (right, paired-end).')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
55
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
56 parser.add_argument('--output-suppressed-reads', dest='output_suppressed_reads',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
57 help='Additional output file with suppressed reads (single-end).')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
58 parser.add_argument('--output-suppressed-reads-l', dest='output_suppressed_reads_l',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
59 help='File name for suppressed reads (left, paired-end).')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
60 parser.add_argument('--output-suppressed-reads-r', dest='output_suppressed_reads_r',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
61 help='File name for suppressed reads (right, paired-end).')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
62 parser.add_argument('--stdout', dest='output_stdout',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
63 help='File name for the standard output of bismark.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
64
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
65 parser.add_argument('--single-paired', dest='single_paired',
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
66 help='The single-end reads file in Sanger FASTQ or FASTA format.')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
67
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
68 parser.add_argument('--fastq', action='store_true', help='Query filetype is in FASTQ format')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
69 parser.add_argument('--fasta', action='store_true', help='Query filetype is in FASTA format')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
70 parser.add_argument('--phred64-quals', dest='phred64', action="store_true")
10
7bffcb6fc81d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 23685f742f0b5cd5de871c285d247d560485b11b
bgruening
parents: 8
diff changeset
71 parser.add_argument('--non-directional', dest='non_directional', action="store_true")
8
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
72
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
73 parser.add_argument('--skip-reads', dest='skip_reads', type=int)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
74 parser.add_argument('--qupto', type=int)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
75
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
76 # paired end options
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
77 parser.add_argument('-I', '--minins', dest='min_insert')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
78 parser.add_argument('-X', '--maxins', dest='max_insert')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
79 parser.add_argument('--no-mixed', dest='no_mixed', action="store_true")
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
80 parser.add_argument('--no-discordant', dest='no_discordant', action="store_true")
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
81
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
82 # parse general options
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
83 # default 20
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
84 parser.add_argument('--seed-len', dest='seed_len', type=int)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
85 # default 15
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
86 parser.add_argument('--seed-extention-attempts', dest='seed_extention_attempts', type=int)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
87 # default 0
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
88 parser.add_argument('--seed-mismatches', dest='seed_mismatches', type=int)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
89 # default 2
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
90 parser.add_argument('--max-reseed', dest='max_reseed', type=int)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
91 """
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
92 # default 70
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
93 parser.add_argument( '--maqerr', dest='maqerr', type=int )
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
94 """
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
95
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
96 """
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
97 The number of megabytes of memory a given thread is given to store path
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
98 descriptors in --best mode. Best-first search must keep track of many paths
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
99 at once to ensure it is always extending the path with the lowest cumulative
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
100 cost. Bowtie tries to minimize the memory impact of the descriptors, but
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
101 they can still grow very large in some cases. If you receive an error message
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
102 saying that chunk memory has been exhausted in --best mode, try adjusting
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
103 this parameter up to dedicate more memory to the descriptors. Default: 512.
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
104 """
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
105 parser.add_argument('--chunkmbs', type=int, default=512)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
106
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
107 args = parser.parse_args()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
108
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
109 logger = logging.getLogger('bismark_wrapper')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
110 logger.setLevel(logging.DEBUG)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
111 ch = logging.StreamHandler(sys.stdout)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
112 if args.output_stdout:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
113 ch.setLevel(logging.WARNING)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
114 handler = logging.FileHandler(args.output_stdout)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
115 handler.setLevel(logging.DEBUG)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
116 logger.addHandler(handler)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
117 else:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
118 ch.setLevel(logging.DEBUG)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
119 logger.addHandler(ch)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
120
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
121 # Create bismark index if necessary.
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
122 index_dir = ""
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
123 tmp_index_dir = None
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
124 if args.own_file:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
125 logger.info("Create a temporary index with the offered files from the user. "
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
126 "Utilizing the script: bismark_genome_preparation")
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
127 tmp_index_dir = tempfile.mkdtemp()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
128 index_path = os.path.join(tmp_index_dir, '.'.join(os.path.split(args.own_file)[1].split('.')[:-1]))
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
129 try:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
130 # Create a hard link pointing to args.own_file named 'index_path'.fa.
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
131 os.symlink(args.own_file, index_path + '.fa')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
132 except Exception as e:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
133 if os.path.exists(tmp_index_dir):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
134 shutil.rmtree(tmp_index_dir)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
135 stop_err(logger, 'Error in linking the reference database!\n%s' % e)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
136 # bismark_genome_preparation needs the complete path to the folder in which the database is stored
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
137 cmd_index = ['bismark_genome_preparation', '--bowtie2', tmp_index_dir]
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
138 try:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
139 logger.info("Generating index with: '%s'", " ".join(cmd_index))
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
140 process = subprocess.Popen(cmd_index, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
141 with process.stdout:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
142 log_subprocess_output(logger, process.stdout)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
143 exitcode = process.wait()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
144 if exitcode != 0:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
145 raise Exception(process.stderr)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
146 except Exception as e:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
147 if os.path.exists(tmp_index_dir):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
148 shutil.rmtree(tmp_index_dir)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
149 stop_err(logger, 'Error indexing reference sequence!\n%s' % e)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
150 index_dir = tmp_index_dir
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
151 else:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
152 # bowtie path is the path to the index directory and the first path of the index file name
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
153 index_dir = os.path.dirname(args.index_path)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
154
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
155 # Build bismark command
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
156 tmp_bismark_dir = tempfile.mkdtemp()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
157 output_dir = os.path.join(tmp_bismark_dir, 'results')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
158 cmd = ['bismark', '--bam', '--gzip', '--temp_dir', tmp_bismark_dir, '-o', output_dir, '--quiet']
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
159
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
160 if args.fasta:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
161 # the query input files (specified as mate1,mate2 or singles) are FastA
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
162 cmd.append('--fasta')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
163 elif args.fastq:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
164 cmd.append('--fastq')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
165
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
166 # alignment options
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
167 if args.num_threads > 2:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
168 # divide num_threads by 2 here since bismark will spawn 2 jobs with -p threads each
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
169 cmd.extend(['-p', str(math.ceil(args.num_threads / 2))])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
170 if args.seed_mismatches:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
171 cmd.extend(['-N', str(args.seed_mismatches)])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
172 if args.seed_len:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
173 cmd.extend(['-L', str(args.seed_len)])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
174 if args.seed_extention_attempts:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
175 cmd.extend(['-D', str(args.seed_extention_attempts)])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
176 if args.max_reseed:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
177 cmd.extend(['-R', str(args.max_reseed)])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
178 if args.no_discordant:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
179 cmd.append('--no-discordant')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
180 if args.no_mixed:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
181 cmd.append('--no-mixed')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
182 if args.skip_reads:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
183 cmd.extend(['--skip', str(args.skip_reads)])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
184 if args.qupto:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
185 cmd.extend(['--upto', 'args.qupto'])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
186 if args.phred64:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
187 cmd.append('--phred64-quals')
10
7bffcb6fc81d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 23685f742f0b5cd5de871c285d247d560485b11b
bgruening
parents: 8
diff changeset
188 if args.non_directional:
7bffcb6fc81d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 23685f742f0b5cd5de871c285d247d560485b11b
bgruening
parents: 8
diff changeset
189 cmd.append('--non-directional')
8
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
190 if args.suppress_header:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
191 cmd.append('--sam-no-hd')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
192 if args.output_unmapped_reads or (args.output_unmapped_reads_l and args.output_unmapped_reads_r):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
193 cmd.append('--un')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
194 if args.output_suppressed_reads or (args.output_suppressed_reads_l and args.output_suppressed_reads_r):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
195 cmd.append('--ambiguous')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
196
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
197 cmd.append(index_dir)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
198 # Set up the reads
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
199 if args.mate_paired:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
200 # paired-end reads library
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
201 cmd.extend(['-1', args.mate1, '-2', args.mate2, '-I', str(args.min_insert), '-X', str(args.max_insert)])
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
202 else:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
203 # single paired reads library
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
204 cmd.append(args.single_paired)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
205
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
206 # Run
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
207 try:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
208 logger.info("Running bismark with: '%s'", " ".join(cmd))
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
209 process = subprocess.Popen(args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
210 with process.stdout:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
211 log_subprocess_output(logger, process.stdout)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
212 exitcode = process.wait()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
213 if exitcode != 0:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
214 raise Exception(process.stderr)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
215 except Exception as e:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
216 stop_err(logger, 'Error in running bismark!\n%s' % e)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
217
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
218 # collect and copy output files
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
219 if args.output_report_file:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
220 output_report_file = open(args.output_report_file, 'w+')
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
221 for line in fileinput.input(glob(os.path.join(output_dir, '*report.txt'))):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
222 output_report_file.write(line)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
223 output_report_file.close()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
224
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
225 if args.output_suppressed_reads:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
226 if glob(os.path.join(output_dir, '*ambiguous_reads.txt')):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
227 shutil.move(glob(os.path.join(output_dir, '*ambiguous_reads.txt'))[0], args.output_suppressed_reads)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
228 if args.output_suppressed_reads_l:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
229 if glob(os.path.join(output_dir, '*ambiguous_reads_1.txt')):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
230 shutil.move(glob(os.path.join(output_dir, '*ambiguous_reads_1.txt'))[0], args.output_suppressed_reads_l)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
231 if args.output_suppressed_reads_r:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
232 if glob(os.path.join(output_dir, '*ambiguous_reads_2.txt')):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
233 shutil.move(glob(os.path.join(output_dir, '*ambiguous_reads_2.txt'))[0], args.output_suppressed_reads_r)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
234
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
235 if args.output_unmapped_reads:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
236 if glob(os.path.join(output_dir, '*unmapped_reads.txt')):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
237 shutil.move(glob(os.path.join(output_dir, '*unmapped_reads.txt'))[0], args.output_unmapped_reads)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
238 if args.output_unmapped_reads_l:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
239 if glob(os.path.join(output_dir, '*unmapped_reads_1.txt')):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
240 shutil.move(glob(os.path.join(output_dir, '*unmapped_reads_1.txt'))[0], args.output_unmapped_reads_l)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
241 if args.output_unmapped_reads_r:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
242 if glob(os.path.join(output_dir, '*unmapped_reads_2.txt')):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
243 shutil.move(glob(os.path.join(output_dir, '*unmapped_reads_2.txt'))[0], args.output_unmapped_reads_r)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
244
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
245 try:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
246 # merge all bam files
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
247 tmp_res = tempfile.NamedTemporaryFile(dir=output_dir).name
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
248
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
249 bam_files = glob(os.path.join(output_dir, '*.bam'))
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
250 if len(bam_files) > 1:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
251 cmd = ['samtools', 'merge', '-@', str(args.num_threads), '-f', tmp_res, ' '.join(bam_files)]
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
252 logger.info("Merging bams with: '%s'", cmd)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
253 process = subprocess.Popen(args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
254 with process.stdout:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
255 log_subprocess_output(logger, process.stdout)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
256 exitcode = process.wait()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
257 if exitcode != 0:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
258 raise Exception(process.stderr)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
259 else:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
260 tmp_res = bam_files[0]
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
261
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
262 bam_path = "%s" % tmp_res
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
263
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
264 if os.path.exists(bam_path):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
265 if args.sort_bam:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
266 cmd = ['samtools', 'sort', '-@', str(args.num_threads), bam_path, 'sorted_bam']
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
267 logger.info("Sorting bam with: '%s'", cmd)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
268 process = subprocess.Popen(args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
269 with process.stdout:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
270 log_subprocess_output(logger, process.stdout)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
271 exitcode = process.wait()
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
272 if exitcode != 0:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
273 raise Exception(process.stderr)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
274 shutil.move('sorted_bam.bam', args.output)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
275 else:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
276 shutil.move(bam_path, args.output)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
277 else:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
278 stop_err(logger, 'BAM file no found:\n%s' % bam_path)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
279
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
280 except Exception as e:
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
281 stop_err(logger, 'Error in merging bam files!\n%s' % e)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
282
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
283 # Clean up temp dirs
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
284 if tmp_index_dir and os.path.exists(tmp_index_dir):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
285 shutil.rmtree(tmp_index_dir)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
286 if os.path.exists(tmp_bismark_dir):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
287 shutil.rmtree(tmp_bismark_dir)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
288 if os.path.exists(output_dir):
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
289 shutil.rmtree(output_dir)
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
290
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
291
9bfe38410155 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
292 if __name__ == "__main__": __main__()