Hi, I am trying to use scirpy to do scRNAseq data analysis together with TCR analysis. I have the following issue, could you help me please?
Thank you for your help.
import tarfile
import warnings
from glob import glob
import anndata
import muon as mu
import numpy as np
import pandas as pd
import scanpy as sc
import scirpy as ir
from cycler import cycler
from matplotlib import cm as mpl_cm
from matplotlib import pyplot as plt
sc.set_figure_params(figsize=(4, 4))
sc.settings.verbosity = 2 # verbosity: errors (0), warnings (1), info (2), hints (3)
# Load the associated transcriptomics data
adata = sc.read('immune_withoutX.h5ad')
adata.uns['log1p']["base"] = None
adata.var_names_make_unique()
# Load the TCR data
adata_tcr = ir.io.read_10x_vdj(
"filtered_contig_annotations.csv"
)
adata_tcr.shape
(272, 0)
adata.shape
(5954, 14191)
mdata = mu.MuData({"gex": adata, "airr": adata_tcr})
mdata.obs_names_make_unique()
sc.pp.log1p(mdata["gex"])
sc.pp.pca(mdata["gex"], svd_solver="arpack")
sc.pp.neighbors(mdata["gex"])
sc.tl.umap(mdata["gex"])
WARNING: adata.X seems to be already log-transformed.
computing PCA
on highly variable genes
with n_comps=50
finished (0:00:02)
computing neighbors
using 'X_pca' with n_pcs = 50
finished (0:00:00)
computing UMAP
finished (0:00:10)
ir.pp.index_chains(mdata)
ir.tl.chain_qc(mdata)
100% 1/1 [00:00<00:00, 30.74it/s]
Stored result in `mdata.obs["airr:receptor_type"]`. Stored result in `mdata.obs["airr:receptor_subtype"]`. Stored result in `mdata.obs["airr:chain_pairing"]`.
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(10, 4), gridspec_kw={"wspace": 0.5})
mu.pl.embedding(mdata, basis="gex:umap", color=["Cd3e"], ax=ax0, show=False)
mu.pl.embedding(mdata, basis="gex:umap", color=["airr:receptor_type"], ax=ax1)
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
Cell In[42], line 3
1 fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(10, 4), gridspec_kw={"wspace": 0.5})
2 mu.pl.embedding(mdata, basis="gex:umap", color=["Cd3e"], ax=ax0, show=False)
----> 3 mu.pl.embedding(mdata, basis="gex:umap", color=["airr:receptor_type"], ax=ax1)
File ~\Anaconda3\lib\site-packages\muon\_core\plot.py:264, in embedding(data, basis, color, use_raw, layer, **kwargs)
261 color = [mod_key_modifier[k] for k in keys]
263 ad = AnnData(obs=obs, obsm=adata.obsm, obsp=adata.obsp, uns=adata.uns)
--> 264 retval = sc.pl.embedding(ad, basis=basis_mod, color=color, **kwargs)
265 for key, col in zip(keys, color):
266 try:
File ~\Anaconda3\lib\site-packages\scanpy\plotting\_tools\scatterplots.py:392, in embedding(adata, basis, color, gene_symbols, use_raw, sort_order, edges, edges_width, edges_color, neighbors_key, arrows, arrows_kwds, groups, components, dimensions, layer, projection, scale_factor, color_map, cmap, palette, na_color, na_in_legend, size, frameon, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, colorbar_loc, vmax, vmin, vcenter, norm, add_outline, outline_width, outline_color, ncols, hspace, wspace, title, show, save, ax, return_fig, **kwargs)
389 # if user did not set alpha, set alpha to 0.7
390 kwargs['alpha'] = 0.7 if alpha is None else alpha
--> 392 cax = scatter(
393 coords[:, 0],
394 coords[:, 1],
395 marker=".",
396 c=color_vector,
397 rasterized=settings._vector_friendly,
398 norm=normalize,
399 **kwargs,
400 )
402 # remove y and x ticks
403 ax.set_yticks([])
File ~\Anaconda3\lib\site-packages\matplotlib\__init__.py:1442, in _preprocess_data.<locals>.inner(ax, data, *args, **kwargs)
1439 @functools.wraps(func)
1440 def inner(ax, *args, data=None, **kwargs):
1441 if data is None:
-> 1442 return func(ax, *map(sanitize_sequence, args), **kwargs)
1444 bound = new_sig.bind(ax, *args, **kwargs)
1445 auto_label = (bound.arguments.get(label_namer)
1446 or bound.kwargs.get(label_namer))
File ~\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py:4602, in Axes.scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors, plotnonfinite, **kwargs)
4599 if edgecolors is None:
4600 orig_edgecolor = kwargs.get('edgecolor', None)
4601 c, colors, edgecolors = \
-> 4602 self._parse_scatter_color_args(
4603 c, edgecolors, kwargs, x.size,
4604 get_next_color_func=self._get_patches_for_fill.get_next_color)
4606 if plotnonfinite and colors is None:
4607 c = np.ma.masked_invalid(c)
File ~\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py:4400, in Axes._parse_scatter_color_args(c, edgecolors, kwargs, xsize, get_next_color_func)
4393 if c is None:
4394 c = (facecolors if facecolors is not None
4395 else "b" if mpl.rcParams['_internal.classic_mode']
4396 else get_next_color_func())
4397 c_is_string_or_strings = (
4398 isinstance(c, str)
4399 or (np.iterable(c) and len(c) > 0
-> 4400 and isinstance(cbook._safe_first_finite(c), str)))
4402 def invalid_shape_exception(csize, xsize):
4403 return ValueError(
4404 f"'c' argument has {csize} elements, which is inconsistent "
4405 f"with 'x' and 'y' with size {xsize}.")
File ~\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py:1715, in _safe_first_finite(obj, skip_nonfinite)
1712 raise RuntimeError("matplotlib does not "
1713 "support generators as input")
1714 else:
-> 1715 return next(val for val in obj if safe_isfinite(val))
StopIteration:
I have the same issue following this:
_ = ir.pl.group_abundance(
mdata, groupby="airr:receptor_subtype", target_col="gex:mouse"
)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[52], line 1
----> 1 _ = ir.pl.group_abundance(
2 mdata, groupby="airr:receptor_subtype", target_col="gex:mouse"
3 )
File ~\Anaconda3\lib\site-packages\scirpy\pl\_group_abundance.py:98, in group_abundance(adata, groupby, target_col, normalize, max_cols, sort, **kwargs)
95 default_style_kws.update(kwargs["style_kws"])
96 kwargs["style_kws"] = default_style_kws
---> 98 return base.bar(abundance, **kwargs)
File ~\Anaconda3\lib\site-packages\scirpy\pl\base.py:65, in bar(data, ax, stacked, style, style_kws, fig_kws, **kwargs)
63 if "grid" not in kwargs:
64 kwargs["grid"] = False
---> 65 ax = data.plot.bar(ax=ax, stacked=stacked, **kwargs)
67 # Remove excess x label
68 if style_kws is not None:
File ~\Anaconda3\lib\site-packages\pandas\plotting\_core.py:1136, in PlotAccessor.bar(self, x, y, **kwargs)
1046 @Appender(
1047 """
1048 See Also
(...)
1125 self, x=None, y=None, **kwargs
1126 ) -> PlotAccessor:
1127 """
1128 Vertical bar plot.
1129
(...)
1134 other axis represents a measured value.
1135 """
-> 1136 return self(kind="bar", x=x, y=y, **kwargs)
File ~\Anaconda3\lib\site-packages\pandas\plotting\_core.py:975, in PlotAccessor.__call__(self, *args, **kwargs)
972 label_name = label_kw or data.columns
973 data.columns = label_name
--> 975 return plot_backend.plot(data, kind=kind, **kwargs)
File ~\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\__init__.py:71, in plot(data, kind, **kwargs)
69 kwargs["ax"] = getattr(ax, "left_ax", ax)
70 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 71 plot_obj.generate()
72 plot_obj.draw()
73 return plot_obj.result
File ~\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py:446, in MPLPlot.generate(self)
444 def generate(self) -> None:
445 self._args_adjust()
--> 446 self._compute_plot_data()
447 self._setup_subplots()
448 self._make_plot()
File ~\Anaconda3\lib\site-packages\pandas\plotting\_matplotlib\core.py:632, in MPLPlot._compute_plot_data(self)
630 # no non-numeric frames or series allowed
631 if is_empty:
--> 632 raise TypeError("no numeric data to plot")
634 self.data = numeric_data.apply(self._convert_to_ndarray)
TypeError: no numeric data to plot
Thank you very much for your help