forked from bpucker/ncss2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
construct_RNA_seq_coverage_file.py
48 lines (34 loc) · 1.16 KB
/
construct_RNA_seq_coverage_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
### Boas Pucker ###
### [email protected] ###
### v0.2 ###
__usage__ = """
python construct_RNA_seq_coverage_file.py\n
--in <BAM_FILE>
--out <OUTPUT_FILE>
--bam_is_sorted <PREVENTS_EXTRA_SORTING_OF_BAM_FILE>
feature requests and bug reports: [email protected]
"""
import os, sys
# --- end of imports --- #
def main( arguments ):
bam_file = arguments[ arguments.index( '--in' )+1 ]
output_file = arguments[ arguments.index( '--out' )+1 ]
samtools = "samtools"
bedtools = "genomeCoverageBed"
if '--bam_is_sorted' in arguments:
sorted_bam_file = bam_file
else:
print "sorting BAM file ..."
sorted_bam_file = output_file + "_sorted.bam"
cmd = samtools + " sort -m 5000000000 --threads 8 " + bam_file + " > " + sorted_bam_file
os.popen( cmd )
# --- calculate read coverage depth per position --- #
print "calculating coverage per position ...."
cmd = bedtools + " -d -split -ibam " + sorted_bam_file + " > " + output_file
os.popen( cmd )
if __name__ == '__main__':
if '--in' in sys.argv and '--out' in sys.argv:
main( sys.argv )
else:
sys.exit( __usage__ )
print "all done!"