annotate Contra/scripts/count_libsize.py @ 4:9a76d500b049

Uploaded
author fcaramia
date Thu, 13 Sep 2012 02:44:08 -0400
parents 7564f3b1e675
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 get_libsize(bedgraph_file):
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
25 bedgraph = open(bedgraph_file)
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
26 libsize = 0
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
27 for line in bedgraph:
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
28 line = line.split()
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
29 chr = line[0]
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
30 start = int(line[1])
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
31 end = int(line[2])
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
32 cov = float(line[3])
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
33 #cov = int(line[3])
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
34
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
35 libsize += (end-start)*cov
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
36
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
37 bedgraph.close()
7564f3b1e675 Uploaded
fcaramia
parents:
diff changeset
38 return int(libsize)