-
Notifications
You must be signed in to change notification settings - Fork 2
/
bedtools_merge_id_assigner.py
46 lines (34 loc) · 1.26 KB
/
bedtools_merge_id_assigner.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
#!/usr/bin/env python3
# Author: Jeffrey Grover
# Purpose: Take a file output by bedtools merge and assign IDs to the rows.
# Output a bed file with 6 columns.
# Created: 2019-04-19
from argparse import ArgumentParser
def assign_bedtools_merge(input_file, basename):
line_count = 0
with open(input_file, 'r') as input_handle:
for line in input_handle:
line_count += 1
entry = line.strip().split()
chromosome = entry[0]
start = entry[1]
stop = entry[2]
strand = entry[3]
name = basename + str(line_count)
print(chromosome, start, stop, name, '.', strand, sep='\t')
# Parse command line options
def get_args():
parser = ArgumentParser(
description='Take the output from bedtools merge and assign unique IDs '
'to each line')
parser.add_argument('input_file',
help='File to process',
metavar='FILE')
parser.add_argument('-b', '--basename',
help='Basename to append ID number to for each record')
return parser.parse_args()
# Process the file
def main(args):
assign_bedtools_merge(args.input_file, args.basename)
if __name__ == '__main__':
main(get_args())