# 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
		"""Rescale radius of gyration of structure to 1"""
		rg = radius_of_gyration(self)
		for i, point in enumerate(self.points):
			if point != 0:
				x, y, z = point.pos
				self.points[i].pos = (x/rg, y/rg, z/rg)

class Point(object):
	"""Point in 3-D space"""
	def __init__(self, pos, chrom, absolute_index, relative_index):
		self.pos = pos	#3D coordinates
		self.chrom = chrom	#chromosome parameters
		self.absolute_index = absolute_index	#index relative to all points in structure (including null/zero points)
		self.relative_index = relative_index	#index relative to only non-zero points

def structureFromBed(path, size=None, chrom=None, start=None, end=None, offset=0):
	"""Initializes structure from intrachromosomal BED file."""
	if chrom is None:
		chrom = chromFromBed(path)

	if start is None:
		start = chrom.minPos

	if end is None:
		end = chrom.maxPos

	structure = Structure([], [], chrom, offset)
	structure.points = np.zeros(int((end - start)/chrom.res) + 1, dtype=object)	#true if locus should be added

	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

		"""Rescale radius of gyration of structure to 1"""
		rg = radius_of_gyration(self)
		for i, point in enumerate(self.points):
			if point != 0:
				x, y, z = point.pos
				self.points[i].pos = (x/rg, y/rg, z/rg)

class Point(object):
	"""Point in 3-D space"""
	def __init__(self, pos, chrom, absolute_index, relative_index):
		self.pos = pos	#3D coordinates
		self.chrom = chrom	#chromosome parameters
		self.absolute_index = absolute_index	#index relative to all points in structure (including null/zero points)
		self.relative_index = relative_index	#index relative to only non-zero points

def structureFromBed(path, size=None, chrom=None, start=None, end=None, offset=0):
	"""Initializes structure from intrachromosomal BED file."""
	if chrom is None:
		chrom = chromFromBed(path)

	if start is None:
		start = chrom.minPos

	if end is None:
		end = chrom.maxPos

	structure = Structure([], [], chrom, offset)
	structure.points = np.zeros(int((end - start)/chrom.res) + 1, dtype=object)	#true if locus should be added

	if size is not None:

		tracker = Tracker("Identifying loci", size)