annotate Contra/scripts/target_breakdown.py @ 0:7564f3b1e675

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