# Path: tools.py
# class Tracker(object):
# 	"""Tracks progress of task"""
# 	def __init__(self, name, size, currPercentage=0, count=0):
# 		self.name = name	#name of task
# 		self.size = size	#total size of task (e.g. number of lines in file)
# 		self.currPercentage = currPercentage	#current percentage of task complete
# 		self.count = count		#absolute amount of task complete (e.g. number of lines of file read)
# 	def increment(self):
# 		if self.size !=0 and self.size is not None:
# 			self.count += 1
# 			newPercentage = self.currPercentage + 1
# 			if float(self.count)/self.size >= float(newPercentage)/100:	#if at least X% of the file has been read, print percentage
# 				self.currPercentage = newPercentage
# 				print("{} {}% complete".format(self.name, self.currPercentage))	
# 
# Path: hic_oe.py
# def get_expected(mat):
# 	n = len(mat)
# 
# 	tots = np.zeros(n-1)
# 	counts = np.zeros(n-1)
# 
# 	for i in range(n):
# 		for j in range(i):
# 			observed = mat[i,j]
# 			if observed != 0:
# 				s = i - j
# 				tots[s - 1] += observed
# 				counts[s - 1] += 1
# 
# 	avgs = np.zeros(n-1)
# 	for i, count in enumerate(counts):
# 		if count != 0:
# 			avgs[i] = tots[i]/count
# 
# 	return avgs


import sys
import numpy as np
import array_tools as at
from tools import Tracker
from linear_algebra import *
from tad import *
from hic_oe import get_expected
			if minPos is None or maxPos is None:
				pos1 = int(line[1])
				pos2 = int(line[4])
				if minPos is None:
					curr_minPos = min((pos1, pos2))
					if curr_minPos < overall_minPos:
						overall_minPos = curr_minPos
				if maxPos is None:
					curr_maxPos = max((pos1, pos2))
					if curr_maxPos > overall_maxPos:
						overall_maxPos = curr_maxPos
			if i == 0:
				name = line[0]
				res = (int(line[2]) - pos1)	
		infile.close()
	minPos = int(np.floor(float(overall_minPos)/res)) * res	#round
	maxPos = int(np.ceil(float(overall_maxPos)/res)) * res
	return ChromParameters(minPos, maxPos, res, name)

def matFromBed(path, size=None, structure=None):	
	"""Converts BED file to matrix. Only includes loci in structure."""
	if structure is None:
		structure = structureFromBed(path, size)

	abs_indices = structure.nonzero_abs_indices()

	numpoints = len(abs_indices)
	mat = np.zeros((numpoints, numpoints))	

	if size is not None:

# Path: tools.py
# class Tracker(object):
# 	"""Tracks progress of task"""
# 	def __init__(self, name, size, currPercentage=0, count=0):
# 		self.name = name	#name of task
# 		self.size = size	#total size of task (e.g. number of lines in file)
# 		self.currPercentage = currPercentage	#current percentage of task complete
# 		self.count = count		#absolute amount of task complete (e.g. number of lines of file read)
# 	def increment(self):
# 		if self.size !=0 and self.size is not None:
# 			self.count += 1
# 			newPercentage = self.currPercentage + 1
# 			if float(self.count)/self.size >= float(newPercentage)/100:	#if at least X% of the file has been read, print percentage
# 				self.currPercentage = newPercentage
# 				print("{} {}% complete".format(self.name, self.currPercentage))	
# 
# Path: hic_oe.py
# def get_expected(mat):
# 	n = len(mat)
# 
# 	tots = np.zeros(n-1)
# 	counts = np.zeros(n-1)
# 
# 	for i in range(n):
# 		for j in range(i):
# 			observed = mat[i,j]
# 			if observed != 0:
# 				s = i - j
# 				tots[s - 1] += observed
# 				counts[s - 1] += 1
# 
# 	avgs = np.zeros(n-1)
# 	for i, count in enumerate(counts):
# 		if count != 0:
# 			avgs[i] = tots[i]/count
# 
# 	return avgs


# Path: data_tools.py
import sys
import numpy as np
import array_tools as at
from tools import Tracker
from linear_algebra import *
from tad import *
from hic_oe import get_expected

			if minPos is None or maxPos is None:
				pos1 = int(line[1])
				pos2 = int(line[4])
				if minPos is None:
					curr_minPos = min((pos1, pos2))
					if curr_minPos < overall_minPos:
						overall_minPos = curr_minPos
				if maxPos is None:
					curr_maxPos = max((pos1, pos2))
					if curr_maxPos > overall_maxPos:
						overall_maxPos = curr_maxPos
			if i == 0:
				name = line[0]
				res = (int(line[2]) - pos1)	
		infile.close()
	minPos = int(np.floor(float(overall_minPos)/res)) * res	#round
	maxPos = int(np.ceil(float(overall_maxPos)/res)) * res
	return ChromParameters(minPos, maxPos, res, name)

def matFromBed(path, size=None, structure=None):	
	"""Converts BED file to matrix. Only includes loci in structure."""
	if structure is None:
		structure = structureFromBed(path, size)

	abs_indices = structure.nonzero_abs_indices()

	numpoints = len(abs_indices)
	mat = np.zeros((numpoints, numpoints))	

	if size is not None:

		tracker = Tracker("Filling matrix", size)