tleonardi / nanocompore

RNA modifications detection from Nanopore dRNA-Seq data
https://nanocompore.rna.rocks
GNU General Public License v3.0
77 stars 12 forks source link

plot position is giving an error #209

Closed Muhammad5577 closed 1 year ago

Muhammad5577 commented 1 year ago

Hi all i have been trying to plot a position and i get the following error, i am able to generate other plots, what am i missing here ? (2 screen shots attached)

/home/shiberlab/.local/lib/python3.8/site-packages/seaborn/distributions.py:1681: FutureWarning: Use x and y rather than data anddata2` warnings.warn(msg, FutureWarning)

IndexError Traceback (most recent call last) Cell In [50], line 1 ----> 1 fig, ax = db.plot_position ("YAL003W_mRNA",pos=456)

File ~/.local/lib/python3.8/site-packages/nanocompore/SampCompDB.py:865, in SampCompDB.plot_position(self, ref_id, pos, split_samples, figsize, palette, plot_style, xlim, ylim, alpha, pointSize, scatter, kde, model, gmm_levels) 863 for label, d in plot_datadict.items(): 864 if kde: --> 865 = sns.kdeplot( 866 data=d["intensity"], 867 data2=d["dwell"], 868 cmap=sns.light_palette(d["color"], ascmap=True), 869 ax=ax, 870 clip=((min(d["intensity"]), max(d["intensity"])), (min(d["dwell"]),max(d["dwell"])))) 871 if scatter: 872 = ax.scatter( 873 x=d["intensity"], 874 y=d["dwell"], (...) 877 alpha=alpha, 878 s=pointSize)

File ~/.local/lib/python3.8/site-packages/seaborn/_decorators.py:46, in _deprecate_positional_args..inner_f(*args, **kwargs) 36 warnings.warn( Screenshot from 2023-01-23 13-33-04 Screenshot from 2023-01-23 13-33-09

 37         "Pass the following variable{} as {}keyword arg{}: {}. "
 38         "From version 0.12, the only valid positional argument "

(...) 43 FutureWarning 44 ) 45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)}) ---> 46 return f(**kwargs)

File ~/.local/lib/python3.8/site-packages/seaborn/distributions.py:1738, in kdeplot(x, y, shade, vertical, kernel, bw, gridsize, cut, clip, legend, cumulative, shade_lowest, cbar, cbar_ax, cbar_kws, ax, weights, hue, palette, hue_order, hue_norm, multiple, common_norm, common_grid, levels, thresh, bw_method, bw_adjust, log_scale, color, fill, data, data2, warn_singular, **kwargs) 1734 fill = shade 1736 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -> 1738 p = _DistributionPlotter( 1739 data=data, 1740 variables=_DistributionPlotter.get_semantics(locals()), 1741 ) 1743 p.map_hue(palette=palette, order=hue_order, norm=hue_norm) 1745 if ax is None:

File ~/.local/lib/python3.8/site-packages/seaborn/distributions.py:111, in _DistributionPlotter.init(self, data, variables) 105 def init( 106 self, 107 data=None, 108 variables={}, 109 ): --> 111 super().init(data=data, variables=variables)

File ~/.local/lib/python3.8/site-packages/seaborn/_core.py:605, in VectorPlotter.init(self, data, variables) 603 def init(self, data=None, variables={}): --> 605 self.assign_variables(data, variables) 607 for var, cls in self._semantic_mappings.items(): 608 609 # Create the mapping function 610 map_func = partial(cls.map, plotter=self)

File ~/.local/lib/python3.8/site-packages/seaborn/_core.py:668, in VectorPlotter.assign_variables(self, data, variables) 666 else: 667 self.input_format = "long" --> 668 plot_data, variables = self._assign_variables_longform( 669 data, **variables, 670 ) 672 self.plot_data = plot_data 673 self.variables = variables

File ~/.local/lib/python3.8/site-packages/seaborn/_core.py:893, in VectorPlotter._assign_variables_longform(self, data, **kwargs) 888 if val_as_data_key: 889 890 # We know that getitem will work 892 if val in data: --> 893 plot_data[key] = data[val] 894 elif val in index: 895 plot_data[key] = index[val]

IndexError: arrays used as indices must be of integer (or boolean) type

lmulroney commented 1 year ago

Hi Muhammad5577,

Can you confirm for me which version of seaborn you're using?

Muhammad5577 commented 1 year ago

Hi lmulroney seaborn is v 0.11.2

Muhammad5577 commented 1 year ago

Hi lmulroney After updating to seaborn 0.12.2 i get this error now


ValueError Traceback (most recent call last) Cell In [12], line 1 ----> 1 fig, ax = db.plot_position ("YKL096W_mRNA",pos=1)

File ~/.local/lib/python3.8/site-packages/nanocompore/SampCompDB.py:865, in SampCompDB.plot_position(self, ref_id, pos, split_samples, figsize, palette, plot_style, xlim, ylim, alpha, pointSize, scatter, kde, model, gmm_levels) 863 for label, d in plot_datadict.items(): 864 if kde: --> 865 = sns.kdeplot( 866 data=d["intensity"], 867 data2=d["dwell"], 868 cmap=sns.light_palette(d["color"], ascmap=True), 869 ax=ax, 870 clip=((min(d["intensity"]), max(d["intensity"])), (min(d["dwell"]),max(d["dwell"])))) 871 if scatter: 872 = ax.scatter( 873 x=d["intensity"], 874 y=d["dwell"], (...) 877 alpha=alpha, 878 s=pointSize)

File ~/.local/lib/python3.8/site-packages/seaborn/distributions.py:1717, in kdeplot(data, x, y, hue, weights, palette, hue_order, hue_norm, color, fill, multiple, common_norm, common_grid, cumulative, bw_method, bw_adjust, warn_singular, log_scale, levels, thresh, gridsize, cut, clip, legend, cbar, cbar_ax, cbar_kws, ax, kwargs) 1713 if p.univariate: 1715 plot_kws = kwargs.copy() -> 1717 p.plot_univariate_density( 1718 multiple=multiple, 1719 common_norm=common_norm, 1720 common_grid=common_grid, 1721 fill=fill, 1722 color=color, 1723 legend=legend, 1724 warn_singular=warn_singular, 1725 estimate_kws=estimate_kws, 1726 plot_kws, 1727 ) 1729 else: 1731 p.plot_bivariate_density( 1732 common_norm=common_norm, 1733 fill=fill, (...) 1743 **kwargs, 1744 )

File ~/.local/lib/python3.8/site-packages/seaborn/distributions.py:937, in _DistributionPlotter.plot_univariate_density(self, multiple, common_norm, common_grid, warn_singular, fill, color, legend, estimate_kws, **plot_kws) 934 log_scale = self._log_scaled(self.data_variable) 936 # Do the computation --> 937 densities = self._compute_univariate_density( 938 self.data_variable, 939 common_norm, 940 common_grid, 941 estimate_kws, 942 log_scale, 943 warn_singular, 944 ) 946 # Adjust densities based on the multiple rule 947 densities, baselines = self._resolve_multiple(densities, multiple)

File ~/.local/lib/python3.8/site-packages/seaborn/distributions.py:349, in _DistributionPlotter._compute_univariate_density(self, data_variable, common_norm, common_grid, estimate_kws, log_scale, warn_singular) 345 try: 346 if not singular: 347 # Convoluted approach needed because numerical failures 348 # can manifest in a few different ways. --> 349 density, support = estimator(observations, weights=weights) 350 except np.linalg.LinAlgError: 351 singular = True

File ~/.local/lib/python3.8/site-packages/seaborn/_statistics.py:192, in KDE.call(self, x1, x2, weights) 190 """Fit and evaluate on univariate or bivariate data.""" 191 if x2 is None: --> 192 return self._eval_univariate(x1, weights) 193 else: 194 return self._eval_bivariate(x1, x2, weights)

File ~/.local/lib/python3.8/site-packages/seaborn/_statistics.py:151, in KDE._eval_univariate(self, x, weights) 149 support = self.support 150 if support is None: --> 151 support = self.define_support(x, cache=False) 153 kde = self._fit(x, weights) 155 if self.cumulative:

File ~/.local/lib/python3.8/site-packages/seaborn/_statistics.py:127, in KDE.define_support(self, x1, x2, weights, cache) 125 """Create the evaluation grid for a given data set.""" 126 if x2 is None: --> 127 support = self._define_support_univariate(x1, weights) 128 else: 129 support = self._define_support_bivariate(x1, x2, weights)

File ~/.local/lib/python3.8/site-packages/seaborn/_statistics.py:101, in KDE._define_support_univariate(self, x, weights) 99 kde = self._fit(x, weights) 100 bw = np.sqrt(kde.covariance.squeeze()) --> 101 grid = self._define_support_grid( 102 x, bw, self.cut, self.clip, self.gridsize 103 ) 104 return grid

File ~/.local/lib/python3.8/site-packages/seaborn/_statistics.py:93, in KDE._define_support_grid(self, x, bw, cut, clip, gridsize) 91 clip_lo = -np.inf if clip[0] is None else clip[0] 92 clip_hi = +np.inf if clip[1] is None else clip[1] ---> 93 gridmin = max(x.min() - bw cut, clip_lo) 94 gridmax = min(x.max() + bw cut, clip_hi) 95 return np.linspace(gridmin, gridmax, gridsize)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

lmulroney commented 1 year ago

It looks like seaborn changed the way that the do internal indexing in the versions you're using compared to the version recommended in nanocompore. Can you try using version 0.11.0 instead of 0.11.2 or 0.12.2?

Also, just to make sure, do you have data at position 1 of YKL096W_mRNA or pos 456 of YAL003W_mRNA? It might be throwing the error due to no data at those positions?

Muhammad5577 commented 1 year ago

Hi lmulroney thank you for your help. after reinstalling seaborn 0.11 it worked ! cheers for the support !