annotate bamtobed.py @ 2:59907c23e75e draft

Uploaded
author geoffrey.dintilhac
date Sat, 11 Jan 2020 12:23:57 -0500
parents 68f7b5a4b1e2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
1 #!/usr/bin/env python
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
2
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
3 import argparse
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
4 import os
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
5
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
6 parser = argparse.ArgumentParser(description='Call bamtobed with parameters')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
7 parser.add_argument('-i', '--inputBAM', required=True, help='input BAM file')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
8 parser.add_argument('-o', '--outputBED', required=True, help='output BED file')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
9 parser.add_argument('-oot', '--otherOutputType', required=True, help='Y or N')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
10 parser.add_argument('-f', '--outputFormat', required=False, help='output file format')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
11 parser.add_argument('-sc', '--scoreCalculation', required=True, help='calculation for BED score')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
12 parser.add_argument('-tag', '--tag', required=False, help='another tag')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
13 parser.add_argument('-spt', '--splitD', required=False, help='split : with "N" CIGAR and "D" operation', action="store_true")
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
14 parser.add_argument('-cgr', '--cigar', required=False, help='cigar string', action="store_true")
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
15
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
16 args = parser.parse_args()
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
17
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
18 # Displays the other output format if selected.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
19 if args.otherOutputType == "Y":
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
20 print('format output chosen : ' + args.outputFormat)
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
21
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
22 # Construction of the command line calling the tool.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
23 myCommandLine = ('bedtools bamtobed'+' -i ' + args.inputBAM)
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
24
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
25 # Other output format options.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
26 if args.otherOutputType == "Y":
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
27 if args.outputFormat == "BEDPE":
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
28 myCommandLine += (' -bedpe ')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
29 elif args.outputFormat == "BED12":
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
30 myCommandLine += (' -bed12 ')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
31
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
32 # Score calculation options.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
33 if args.scoreCalculation == "ed":
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
34 myCommandLine += (' -ed ')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
35 elif args.scoreCalculation == "tag":
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
36 myCommandLine += (' -tag ' + args.tag)
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
37
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
38 # Split option.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
39 if args.splitD:
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
40 myCommandLine += (' -splitD ')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
41 print('Splitted BAM')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
42
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
43 # CIGAR option.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
44 if args.cigar:
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
45 myCommandLine += (' -cigar ')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
46 print('CIGAR string column added')
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
47
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
48 myCommandLine += (' > ' + args.outputBED)
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
49
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
50 # Running of the command line.
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
51 os.system(myCommandLine)
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
52
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
53
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
54
68f7b5a4b1e2 Uploaded
geoffrey.dintilhac
parents:
diff changeset
55