0
|
1 #!/usr/bin/env python
|
|
2 """Wrapper for "samtools depad" for use in Galaxy.
|
|
3
|
|
4 This script takes exactly four command line arguments:
|
|
5 * Input padded reference FASTA file
|
|
6 * Input SAM/BAM filename
|
|
7 * Input format ("sam" or "bam")
|
|
8 * Output BAM filename
|
|
9
|
|
10 Runs "samtools depad" and captures the output to the desired BAM file.
|
|
11 """
|
2
|
12
|
3
|
13 from __future__ import print_function
|
|
14
|
2
|
15 import os
|
0
|
16 import sys
|
|
17
|
|
18 if "-v" in sys.argv or "--version" in sys.argv:
|
2
|
19 # Galaxy seems to invert the order of the two lines
|
3
|
20 print("(Galaxy wrapper v0.0.5)")
|
0
|
21 cmd = "samtools 2>&1 | grep -i ^Version"
|
|
22 sys.exit(os.system(cmd))
|
|
23
|
|
24 if len(sys.argv) != 5:
|
2
|
25 sys.exit("Require four arguments: padded FASTA, SAM/BAM file, format (SAM or BAM), output BAM filenames")
|
0
|
26
|
|
27 padded_ref, bam_filename, input_format, output_filename = sys.argv[1:]
|
|
28
|
|
29 if not os.path.isfile(padded_ref):
|
2
|
30 sys.exit("Input padded reference FASTA file not found: %s" % padded_ref)
|
0
|
31 if not os.path.isfile(bam_filename):
|
2
|
32 sys.exit("Input BAM file not found: %s" % bam_filename)
|
0
|
33 if input_format.lower() not in ["sam", "bam"]:
|
2
|
34 sys.exit("Input format should be SAM or BAM, not %r" % input_format)
|
0
|
35
|
2
|
36 # Run samtools depad:
|
0
|
37 if input_format.lower() == "sam":
|
2
|
38 cmd = "samtools depad -S -T '%s' '%s' > '%s'" % (padded_ref, bam_filename, output_filename)
|
0
|
39 else:
|
2
|
40 cmd = "samtools depad -T '%s' '%s' > '%s'" % (padded_ref, bam_filename, output_filename)
|
0
|
41 return_code = os.system(cmd)
|
|
42
|
|
43 if return_code:
|
2
|
44 sys.exit("Return code %i from command:\n%s" % (return_code, cmd))
|