from __future__ import division
import numpy as np


class HicMatrixFileReader(object):
    def __init__(self, file_name=None):
        self.m = None

        if file_name is not None:
            self.load(file_name)

    def load(self, file_name):
        self.m = np.loadtxt(file_name)

    def matrix(self, file_name=None):
        if self.m is None and file_name is not None:
            self.load(file_name)
        else:
            raise ValueError("Either provide a file name or explicitly use 'load' before requesting matrix")
        return self.m

@@ -552,8 +552,945 @@
  self.m%0A
+%0A%0Aclass HicRegionFileReader(object):%0A    def __init__(self, file_name=None, _separator=%22%5Ct%22):%0A        self.sep = _separator%0A        self.r = None%0A        if file_name is not None:%0A            self.load(file_name)%0A%0A    def load(self, file_name):%0A        regions = %5B%5D%0A        with open(file_name, 'r') as f:%0A            for line in f:%0A                line = line.rstrip()%0A                fields = line.split(self.sep)%0A                if len(fields) %3E 2:%0A                    chromosome = fields%5B0%5D%0A                    start = int(fields%5B1%5D)%0A                    end = int(fields%5B2%5D)%0A                    regions.append(%5Bchromosome, start, end%5D)%0A        self.r = regions%0A%0A    def regions(self, file_name=None):%0A        if self.r is None and file_name is not None:%0A            self.load(file_name)%0A        else:%0A            raise ValueError(%22Either provide a file name or explicitly use 'load' before requesting regions%22)%0A        return self.r%0A

Read regions from file