annotate tools/mira4_0/mira4_convert.py @ 39:bbf14bb9607b draft default tip

planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
author peterjc
date Mon, 03 Jun 2019 13:29:00 -0400
parents cee8f9005e43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
1 #!/usr/bin/env python
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
2 """A simple wrapper script to call MIRA and collect its output.
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
3
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
4 This focuses on the miraconvert binary.
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
5 """
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
6
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
7 from __future__ import print_function
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
8
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
9 import os
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
10 import shutil
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
11 import subprocess
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
12 import sys
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
13
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
14 from optparse import OptionParser
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
15
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
16 try:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
17 from io import BytesIO
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
18 except ImportError:
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
19 # Should we worry about Python 2.5 or older?
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
20 from StringIO import StringIO as BytesIO
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
21
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
22 # Do we need any PYTHONPATH magic?
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
23 from mira4_make_bam import depad
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
24
35
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
25 WRAPPER_VER = "0.0.11" # Keep in sync with the XML file
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
26
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
27
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
28 def run(cmd):
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
29 # Avoid using shell=True when we call subprocess to ensure if the Python
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
30 # script is killed, so too is the child process.
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
31 try:
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
32 child = subprocess.Popen(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
33 cmd, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
34 )
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
35 except Exception as err:
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
36 sys.exit("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
37 # Use .communicate as can get deadlocks with .wait(),
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
38 stdout, stderr = child.communicate()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
39 return_code = child.returncode
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
40 if return_code:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
41 cmd_str = " ".join(cmd) # doesn't quote spaces etc
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
42 if stderr and stdout:
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
43 sys.exit(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
44 "Return code %i from command:\n%s\n\n%s\n\n%s"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
45 % (return_code, cmd_str, stdout, stderr)
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
46 )
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
47 else:
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
48 sys.exit(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
49 "Return code %i from command:\n%s\n%s" % (return_code, cmd_str, stderr)
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
50 )
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
51
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
52
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
53 def get_version(mira_binary):
38
cee8f9005e43 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 206259620376b322fc8ed99a6efdd3712f38764b
peterjc
parents: 35
diff changeset
54 """Run MIRA to find its version number."""
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
55 # At the commend line I would use: mira -v | head -n 1
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
56 # however there is some pipe error when doing that here.
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
57 cmd = [mira_binary, "-v"]
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
58 try:
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
59 child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
60 except Exception as err:
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
61 sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
62 sys.exit(1)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
63 ver, tmp = child.communicate()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
64 del child
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
65 return ver.split("\n", 1)[0].strip()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
66
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
67
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
68 # Parse Command Line
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
69 usage = (
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
70 """Galaxy MIRA4 wrapper script v%s - use as follows:
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
71
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
72 $ python mira4_convert.py ...
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
73
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
74 This will run the MIRA miraconvert binary and collect its output files as directed.
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
75 """
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
76 % WRAPPER_VER
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
77 )
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
78 parser = OptionParser(usage=usage)
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
79 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
80 "--input", dest="input", default=None, metavar="FILE", help="MIRA input filename"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
81 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
82 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
83 "-x", "--min_length", dest="min_length", default="0", help="Minimum contig length"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
84 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
85 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
86 "-y",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
87 "--min_cover",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
88 dest="min_cover",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
89 default="0",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
90 help="Minimum average contig coverage",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
91 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
92 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
93 "-z", "--min_reads", dest="min_reads", default="0", help="Minimum reads per contig"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
94 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
95 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
96 "--maf", dest="maf", default="", metavar="FILE", help="MIRA MAF output filename"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
97 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
98 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
99 "--ace", dest="ace", default="", metavar="FILE", help="ACE output filename"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
100 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
101 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
102 "--bam", dest="bam", default="", metavar="FILE", help="Unpadded BAM output filename"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
103 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
104 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
105 "--fasta",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
106 dest="fasta",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
107 default="",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
108 metavar="FILE",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
109 help="Unpadded FASTA output filename",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
110 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
111 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
112 "--cstats",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
113 dest="cstats",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
114 default="",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
115 metavar="FILE",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
116 help="Contig statistics filename",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
117 )
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
118 parser.add_option(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
119 "-v",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
120 "--version",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
121 dest="version",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
122 default=False,
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
123 action="store_true",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
124 help="Show version and quit",
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
125 )
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
126 options, args = parser.parse_args()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
127 if args:
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
128 sys.exit("Expected options (e.g. --input example.maf), not arguments")
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
129
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
130 input_maf = options.input
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
131 out_maf = options.maf
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
132 out_bam = options.bam
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
133 out_fasta = options.fasta
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
134 out_ace = options.ace
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
135 out_cstats = options.cstats
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
136
35
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
137 if "MIRA4" in os.environ:
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
138 mira_path = os.environ["MIRA4"]
35
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
139 mira_convert = os.path.join(mira_path, "miraconvert")
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
140 if not os.path.isfile(mira_convert):
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
141 sys.exit(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
142 "Missing miraconvert under $MIRA4, %r\nFolder contained: %s"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
143 % (mira_convert, ", ".join(os.listdir(mira_path)))
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
144 )
35
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
145 else:
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
146 sys.stderr.write(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
147 "DEBUG: Since $MIRA4 is not set, assuming mira binaries are on $PATH.\n"
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
148 )
35
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
149 mira_path = None
259891fce7fd planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit e4c56df75150c82d3e9c4ac487c4209108e52412
peterjc
parents: 34
diff changeset
150 mira_convert = "miraconvert"
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
151
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
152 mira_convert_ver = get_version(mira_convert)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
153 if not mira_convert_ver.strip().startswith("4.0"):
39
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
154 sys.exit(
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
155 "This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_convert_ver, mira_convert)
bbf14bb9607b planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit 89578746a1c5b29c84a173d8b2709f086f69a7b6
peterjc
parents: 38
diff changeset
156 )
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
157 if options.version:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
158 print("%s, MIRA wrapper version %s" % (mira_convert_ver, WRAPPER_VER))
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
159 sys.exit(0)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
160
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
161 if not input_maf:
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
162 sys.exit("Input MIRA file is required")
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
163 elif not os.path.isfile(input_maf):
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
164 sys.exit("Missing input MIRA file: %r" % input_maf)
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
165
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
166 if not (out_maf or out_bam or out_fasta or out_ace or out_cstats):
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
167 sys.exit("No output requested")
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
168
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
169
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
170 def check_min_int(value, name):
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
171 try:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
172 i = int(value)
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
173 except ValueError:
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
174 sys.exit("Bad %s setting, %r" % (name, value))
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
175 if i < 0:
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
176 sys.exit("Negative %s setting, %r" % (name, value))
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
177 return i
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
178
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
179
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
180 min_length = check_min_int(options.min_length, "minimum length")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
181 min_cover = check_min_int(options.min_cover, "minimum cover")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
182 min_reads = check_min_int(options.min_reads, "minimum reads")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
183
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
184 # TODO - Run MIRA in /tmp or a configurable directory?
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
185 # Currently Galaxy puts us somewhere safe like:
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
186 # /opt/galaxy-dist/database/job_working_directory/846/
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
187 temp = "."
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
188
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
189
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
190 cmd_list = [mira_convert]
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
191 if min_length:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
192 cmd_list.extend(["-x", str(min_length)])
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
193 if min_cover:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
194 cmd_list.extend(["-y", str(min_cover)])
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
195 if min_reads:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
196 cmd_list.extend(["-z", str(min_reads)])
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
197 cmd_list.extend(["-f", "maf", input_maf, os.path.join(temp, "converted")])
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
198 if out_maf:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
199 cmd_list.append("maf")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
200 if out_bam:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
201 cmd_list.append("samnbb")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
202 if not out_fasta:
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
203 # Need this for samtools depad
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
204 out_fasta = os.path.join(temp, "depadded.fasta")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
205 if out_fasta:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
206 cmd_list.append("fasta")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
207 if out_ace:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
208 cmd_list.append("ace")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
209 if out_cstats:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
210 cmd_list.append("cstats")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
211 run(cmd_list)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
212
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
213
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
214 def collect(old, new):
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
215 if not os.path.isfile(old):
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
216 sys.exit("Missing expected output file %s" % old)
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
217 shutil.move(old, new)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
218
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
219
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
220 if out_maf:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
221 collect(os.path.join(temp, "converted.maf"), out_maf)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
222 if out_fasta:
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
223 # Can we look at the MAF file to see if there are multiple strains?
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
224 old = os.path.join(temp, "converted_AllStrains.unpadded.fasta")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
225 if os.path.isfile(old):
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
226 collect(old, out_fasta)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
227 else:
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
228 # Might the output be filtered down to zero contigs?
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
229 old = os.path.join(temp, "converted.fasta")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
230 if not os.path.isfile(old):
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
231 sys.exit("Missing expected output FASTA file")
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
232 elif os.path.getsize(old) == 0:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
233 print("Warning - no contigs (harsh filters?)")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
234 collect(old, out_fasta)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
235 else:
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
236 sys.exit("Missing expected output FASTA file (only generic file present)")
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
237 if out_ace:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
238 collect(os.path.join(temp, "converted.maf"), out_ace)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
239 if out_cstats:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
240 collect(os.path.join(temp, "converted_info_contigstats.txt"), out_cstats)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
241
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
242 if out_bam:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
243 assert os.path.isfile(out_fasta)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
244 old = os.path.join(temp, "converted.samnbb")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
245 if not os.path.isfile(old):
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
246 old = os.path.join(temp, "converted.sam")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
247 if not os.path.isfile(old):
31
fd95aaef8818 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
peterjc
parents: 25
diff changeset
248 sys.exit("Missing expected intermediate file %s" % old)
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
249 h = BytesIO()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
250 msg = depad(out_fasta, old, out_bam, h)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
251 if msg:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
252 print(msg)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
253 print(h.getvalue())
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
254 h.close()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
255 sys.exit(1)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
256 h.close()
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
257 if out_fasta == os.path.join(temp, "depadded.fasta"):
32
56b421d59805 planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
peterjc
parents: 31
diff changeset
258 # Not asked for by Galaxy, no longer needed
25
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
259 os.remove(out_fasta)
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
260
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
261 if min_length or min_cover or min_reads:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
262 print("Filtered.")
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
263 else:
55ae131c5862 v0.0.8 - renamed folder, added note about mirabait
peterjc
parents:
diff changeset
264 print("Converted.")