annotate bamtobed.py @ 1:aba7a47e9ed2 draft default tip

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