-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_length_to_island.py
62 lines (52 loc) · 1.78 KB
/
add_length_to_island.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# Copyright (c) 2010 The George Washington University
# Authors: Chongzhi Zang, Weiqun Peng
#
# This software is distributable under the terms of the GNU General
# Public License (GPL) v2, the text of which can be found at
# http://www.gnu.org/copyleft/gpl.html. Installing, importing or
# otherwise using this module constitutes acceptance of the terms of
# this License.
#
# Disclaimer
#
# This software is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# Comments and/or additions are welcome (send e-mail to:
import re, os, sys, shutil
from math import *
from string import *
from optparse import OptionParser
import operator
def add_tag_density(infile, outfile):
f = open(infile,'r')
o = open(outfile, 'w')
for line in f:
if not re.match("#", line):
line = line.strip()
sline = line.split()
start = atoi(sline[1])
end = atoi(sline[2])
#count = atof(sline[3])
length = end - start + 1
#sline.append(str(length))
o.write('\t'.join([sline[0], sline[1],sline[2],str(length)])+'\n')
f.close()
o.close()
def main(argv):
parser = OptionParser()
parser.add_option("-b", "--island_bed_file", action="store", type="string",
dest="bed_file", help="island bed file", metavar="<file>")
parser.add_option("-o", "--output_file_name", action="store", type="string",
dest="out_file", help="output file name", metavar="<file>")
(opt, args) = parser.parse_args(argv)
if len(argv) < 4:
parser.print_help()
sys.exit(1)
add_tag_density(opt.bed_file, opt.out_file)
if __name__ == "__main__":
main(sys.argv)