Skip to content

Commit

Permalink
Merge pull request #332 from david-castillo/master
Browse files Browse the repository at this point in the history
Fix write_matrix only yielding diagonal
  • Loading branch information
fransua authored Oct 26, 2020
2 parents d222512 + 44afbba commit 0eaf741
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
10 changes: 5 additions & 5 deletions _pytadbit/modelling/structuralmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from itertools import combinations
from uuid import uuid5, UUID
from hashlib import md5
from copy import deepcopy
from copy import deepcopy, copy

from numpy import exp as np_exp
from numpy import median as np_median
Expand Down Expand Up @@ -1644,7 +1644,7 @@ def zscore_plot(self, axe=None, savefig=None, do_normaltest=False):
masked_array, mask=masked_array < self._config['upfreq'])
masked_array_bot = ma.array (
masked_array, mask=self._config['lowfreq'] < masked_array)
cmap = viridis
cmap = copy(viridis)
cmap.set_bad('w', 1.)
if not axe:
fig = plt.figure(figsize=(25, 5.5))
Expand All @@ -1656,7 +1656,7 @@ def zscore_plot(self, axe=None, savefig=None, do_normaltest=False):
ax.set_ylabel('Particles')
ax.set_xlabel('Particles')
ax.set_title('Z-scores of the normalized Hi-C count')
cbar = ax.figure.colorbar(ims, cmap=cmap)
cbar = ax.figure.colorbar(ims)
cbar.ax.set_ylabel('Z-score value')

ax = plt.axes([.38, 0.11, .28, .61])
Expand Down Expand Up @@ -1825,7 +1825,7 @@ def correlate_with_real_data(self, models=None, cluster=None, cutoff=None,
size='x-large')
ax = fig.add_subplot(131)
# imshow of the modeled data
cmap = plt.get_cmap('viridis')
cmap = copy(plt.get_cmap('viridis'))
cmap.set_bad('darkgrey', 1)
ims = ax.imshow(model_matrix, origin='lower', interpolation="nearest",
vmin=0, vmax=1, cmap=cmap,
Expand Down Expand Up @@ -1910,7 +1910,7 @@ def correlate_with_real_data(self, models=None, cluster=None, cutoff=None,
# axmidl.patch.set_visible(False)
ax.set_title('Real versus modelled data')
ax = fig.add_subplot(133)
cmap = plt.get_cmap('viridis')
cmap = copy(plt.get_cmap('viridis'))
cmap.set_bad('darkgrey', 1)
with errstate(divide='ignore'):
ims = ax.imshow(log2(self._original_data), origin='lower',
Expand Down
22 changes: 4 additions & 18 deletions _pytadbit/parsers/hic_bam_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,32 +1188,18 @@ def get_bin_name(a, b):
if 'raw&decay' in normalizations and not cooler:
write = write_raw_and_expc(write)

# pull all sub-matrices and write full matrix
if region2 is not None: # already half-matrix in this case
half_matrix = False

if cooler:
for ichunk, c, j, k, v in _iter_matrix_frags(chunks, tmpdir, rand_hash,
verbose=verbose, clean=clean,
include_chunk_count=True):
if j > k:
continue
if j not in bads1 and k not in bads2:
out_raw.write_iter(ichunk, j, k, v)
out_raw.close()
else:
if half_matrix:
for c, j, k, v in _iter_matrix_frags(chunks, tmpdir, rand_hash,
verbose=verbose, clean=clean):
if k > j:
continue
if j not in bads1 and k not in bads2:
write(c, j, k, v)
else:
for c, j, k, v in _iter_matrix_frags(chunks, tmpdir, rand_hash,
verbose=verbose, clean=clean):
if j not in bads1 and k not in bads2:
write(c, j, k, v)
for c, j, k, v in _iter_matrix_frags(chunks, tmpdir, rand_hash,
verbose=verbose, clean=clean):
if j not in bads1 and k not in bads2:
write(c, j, k, v)

fnames = {}
if append_to_tar:
Expand Down
8 changes: 6 additions & 2 deletions _pytadbit/utils/extraviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
from itertools import product

import numpy as np
import copy
from scipy import interpolate

try:
from matplotlib.ticker import MultipleLocator
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import FuncFormatter

if "mpl_toolkits.legacy_colorbar" in plt.rcParams:
plt.rcParams["mpl_toolkits.legacy_colorbar"] = False
except ImportError:
warn('matplotlib not found\n')

Expand Down Expand Up @@ -717,7 +721,7 @@ def plot_2d_optimization_result(result,
result = result.transpose(trans)
# set NaNs
result = np.ma.array(result, mask=np.isnan(result))
cmap = plt.get_cmap(cmap)
cmap = copy.copy(plt.get_cmap(cmap))
cmap.set_bad('w', 1.)

# defines axes
Expand Down Expand Up @@ -1314,7 +1318,7 @@ def plot_HiC_matrix(matrix, bad_color=None, triangular=False, axe=None,
the second to the color bar
"""
if bad_color is not None:
kwargs['cmap'] = plt.get_cmap(kwargs.get('cmap', None))
kwargs['cmap'] = copy.copy(plt.get_cmap(kwargs.get('cmap', None)))
kwargs['cmap'].set_bad(bad_color, 1.)

if not isinstance(matrix, (np.ndarray, np.generic)):
Expand Down

0 comments on commit 0eaf741

Please sign in to comment.