Skip to content

Commit 8d27d46

Browse files
committed
Update cool_ds.py
1 parent e7c008b commit 8d27d46

1 file changed

Lines changed: 36 additions & 35 deletions

File tree

ALLCools/mcds/cool_ds.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -366,47 +366,48 @@ def matrix(
366366
-------
367367
np.ndarray
368368
"""
369-
sel_dict = {}
370-
if samples is not None:
371-
sel_dict[self.sample_dim] = samples
372-
if value_type is not None:
373-
if da_name not in self.data_vars:
374-
value_type_dim_name = "value_type"
369+
with dask.config.set(scheduler="sync"):
370+
sel_dict = {}
371+
if samples is not None:
372+
sel_dict[self.sample_dim] = samples
373+
if value_type is not None:
374+
if da_name not in self.data_vars:
375+
value_type_dim_name = "value_type"
376+
else:
377+
value_type_dim_name = f"{da_name}_value_type"
378+
sel_dict[value_type_dim_name] = value_type
379+
if len(sel_dict) > 0:
380+
sample_da = self.sel(sel_dict)[da_name]
375381
else:
376-
value_type_dim_name = f"{da_name}_value_type"
377-
sel_dict[value_type_dim_name] = value_type
378-
if len(sel_dict) > 0:
379-
sample_da = self.sel(sel_dict)[da_name]
380-
else:
381-
sample_da = self[da_name]
382+
sample_da = self[da_name]
382383

383-
if samples is not None and not isinstance(samples, str):
384-
# sum sample_dim if multiple samples selected
385-
use_weights = self.sample_weights.sel({self.sample_dim: samples})
386-
sample_da = (sample_da * use_weights).sum(dim=self.sample_dim) / use_weights.sum() * scale_factor
384+
if samples is not None and not isinstance(samples, str):
385+
# sum sample_dim if multiple samples selected
386+
use_weights = self.sample_weights.sel({self.sample_dim: samples})
387+
sample_da = (sample_da * use_weights).sum(dim=self.sample_dim) / use_weights.sum() * scale_factor
387388

388-
data = sample_da.values.astype(dtype)
389+
data = sample_da.values.astype(dtype)
389390

390-
if fill_lower_triangle:
391-
# complete the lower triangle
392-
data = data + data.T - np.diag(data.diagonal())
391+
if fill_lower_triangle:
392+
# complete the lower triangle
393+
data = data + data.T - np.diag(data.diagonal())
393394

394-
if log1p:
395-
data = np.log1p(data)
395+
if log1p:
396+
data = np.log1p(data)
396397

397-
if rotate:
398-
# to make triangle plot, rotate the matrix by 45 degrees
399-
data = ndimage.rotate(data, 45, order=0, reshape=True, prefilter=False, cval=rotate_cval)
398+
if rotate:
399+
# to make triangle plot, rotate the matrix by 45 degrees
400+
data = ndimage.rotate(data, 45, order=0, reshape=True, prefilter=False, cval=rotate_cval)
400401

401-
middle = data.shape[0] // 2
402-
height = (rotate_height_bp // self.bin_size) / np.sqrt(2) + 4
403-
height = int(height)
404-
height = min(height, data.shape[0] // 2)
402+
middle = data.shape[0] // 2
403+
height = (rotate_height_bp // self.bin_size) / np.sqrt(2) + 4
404+
height = int(height)
405+
height = min(height, data.shape[0] // 2)
405406

406-
bottom = middle - height
407-
if fill_lower_triangle:
408-
top = middle + height
409-
else:
410-
top = middle
411-
data = data[bottom:top].copy()
407+
bottom = middle - height
408+
if fill_lower_triangle:
409+
top = middle + height
410+
else:
411+
top = middle
412+
data = data[bottom:top].copy()
412413
return data

0 commit comments

Comments
 (0)