0
|
1 # ----------------------------------------------------------------------#
|
|
2 # Copyright (c) 2011, Richard Lupat & Jason Li.
|
|
3 #
|
|
4 # > Source License <
|
|
5 # This file is part of CONTRA.
|
|
6 #
|
|
7 # CONTRA is free software: you can redistribute it and/or modify
|
|
8 # it under the terms of the GNU General Public License as published by
|
|
9 # the Free Software Foundation, either version 3 of the License, or
|
|
10 # (at your option) any later version.
|
|
11 #
|
|
12 # CONTRA is distributed in the hope that it will be useful,
|
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 # GNU General Public License for more details.
|
|
16 #
|
|
17 # You should have received a copy of the GNU General Public License
|
|
18 # along with CONTRA. If not, see <http://www.gnu.org/licenses/>.
|
|
19 #
|
|
20 #
|
|
21 #-----------------------------------------------------------------------#
|
|
22 # Last Updated : 05 October 2011 16:43PM
|
|
23
|
|
24 def target_breakdown(filename, maxRegionSize, targetRegionSize, out_fname):
|
|
25 from math import ceil
|
|
26
|
|
27 a = open(filename)
|
|
28 output = open(out_fname, "w")
|
|
29
|
|
30 for x in a:
|
|
31 x = x.split()
|
|
32 chr = x[0]
|
|
33 start = int(x[1])
|
|
34 end = int(x[2])
|
|
35 info = ""
|
|
36 if (len(x) > 3):
|
|
37 info = x[3]
|
|
38
|
|
39 regionSize = end-start
|
|
40
|
|
41 if regionSize > maxRegionSize:
|
|
42 seg = ceil(regionSize/float(targetRegionSize))
|
|
43 limit = ceil(regionSize/float(seg))
|
|
44
|
|
45 s_end = start
|
|
46 for i in range(int(seg)):
|
|
47 s_start = s_end
|
|
48 s_end = int(start + (limit*(i+1)))
|
|
49 if s_end > end:
|
|
50 s_end = end
|
|
51 output.write("\t".join([chr, str(s_start), str(s_end), info+"(SPLIT)"])+"\n")
|
|
52 else:
|
|
53 output.write("\t".join([chr, str(start), str(end), info])+"\n")
|
|
54
|
|
55 output.close()
|
|
56
|