Skip to content

Commit

Permalink
update cooler file support (100kb)
Browse files Browse the repository at this point in the history
  • Loading branch information
ursinedeity committed Mar 14, 2017
1 parent 55549f9 commit 1ed3a24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions alab/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,29 @@ def loadhic(filename,genome='hg19',resolution=100000,usechr=['#','X'],verbose=Fa
#--

return m

def loadcooler(filename,usechr=['#','X'],verbose=False):
import scipy.sparse

h5 = h5py.File(filename,'r')
genome = str(h5.attrs['genome-assembly'])
resolution = h5.attrs['bin-size']
nbins = h5.attrs['nbins']

if verbose:
print genome, resolution

tgenome = utils.genome(genome)
bininfo = tgenome.bininfo(resolution)
sp = scipy.sparse.csr_matrix((h5['pixels']['count'],h5['pixels']['bin2_id'],h5['indexes']['bin1_offset']),shape=(nbins,nbins))

m = contactmatrix(len(bininfo.chromList),genome=genome,resolution=resolution,usechr=usechr)
m.matrix = sp.toarray()[:len(m.idx),:len(m.idx)].astype(np.float32)
h5.close()

t = m.matrix.diagonal().copy()
m.matrix[np.diag_indices(len(m.idx))] = 0
m.matrix += m.matrix.T
m.matrix[np.diag_indices(len(m.idx))] = t

return m
2 changes: 2 additions & 0 deletions pgsflows/script/buildTADMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def main(matrixfile, domainfile, outputfile, genome, resolution) : #fileFormat):
raise IOError,"File %s doesn't exist!\n" % (matrixfile)
if os.path.splitext(matrixfile)[1] == '.hic':
m = alab.matrix.loadhic(matrixfile,genome=genome,resolution=resolution)
elif os.path.splitext(matrixfile)[1] == '.cool':
m = alab.matrix.loadcooler(matrixfile)
else:
m = alab.matrix.contactmatrix(matrixfile, genome=genome, resolution=resolution )
#m = None
Expand Down

0 comments on commit 1ed3a24

Please sign in to comment.