| 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 get_libsize(bedgraph_file): | 
|  | 25 	bedgraph = open(bedgraph_file) | 
|  | 26 	libsize = 0 | 
|  | 27 	for line in bedgraph: | 
|  | 28 		line	= line.split() | 
|  | 29 		chr	= line[0] | 
|  | 30 		start	= int(line[1]) | 
|  | 31 		end	= int(line[2]) | 
|  | 32 		cov	= float(line[3]) | 
|  | 33 		#cov	= int(line[3]) | 
|  | 34 | 
|  | 35 		libsize += (end-start)*cov | 
|  | 36 | 
|  | 37 	bedgraph.close() | 
|  | 38 	return int(libsize) |