Skip to content

Commit

Permalink
fix: cci and interactive plot and type matplotlib
Browse files Browse the repository at this point in the history
  • Loading branch information
duypham2108 committed Mar 8, 2023
1 parent 89abaa9 commit 10b105a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 33 deletions.
5 changes: 2 additions & 3 deletions stlearn/plotting/cci_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def lr_result_plot(
title: Optional["str"] = None,
figsize: Optional[Tuple[float, float]] = None,
cmap: Optional[str] = "Spectral_r",
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -919,7 +919,7 @@ def het_plot(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -1069,7 +1069,6 @@ def ccinet_plot(

# Either plotting overall interactions, or just for a particular LR #
int_df, title = get_int_df(adata, lr, use_label, sig_interactions, title)

# Creating the interaction graph #
all_set = int_df.index.values
int_matrix = int_df.values
Expand Down
8 changes: 6 additions & 2 deletions stlearn/plotting/cci_plot_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,23 @@ def add_arrows_by_edges(
def get_int_df(adata, lr, use_label, sig_interactions, title):
"""Retrieves the relevant interaction count matrix."""
no_title = type(title) == type(None)
labels_ordered = adata.obs[use_label].cat.categories
if type(lr) == type(None): # No LR inputted, so just use all
int_df = (
adata.uns[f"lr_cci_{use_label}"]
if sig_interactions
else adata.uns[f"lr_cci_raw_{use_label}"]
)
)[labels_ordered].loc[labels_ordered]
title = "Cell-Cell LR Interactions" if no_title else title
else:

labels_ordered = adata.obs[use_label].cat.categories
int_df = (
adata.uns[f"per_lr_cci_{use_label}"][lr]
if sig_interactions
else adata.uns[f"per_lr_cci_raw_{use_label}"][lr]
)
)[labels_ordered].loc[labels_ordered]

title = f"Cell-Cell {lr} interactions" if no_title else title

return int_df, title
Expand Down
14 changes: 7 additions & 7 deletions stlearn/plotting/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -244,7 +244,7 @@ def __init__(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -457,7 +457,7 @@ def __init__(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -627,7 +627,7 @@ def __init__(
cmap: Optional[str] = "default",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -981,7 +981,7 @@ def __init__(
cmap: Optional[str] = "jet",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ def __init__(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down Expand Up @@ -1205,7 +1205,7 @@ def __init__(
figsize: Optional[Tuple[float, float]] = None,
cmap: Optional[str] = "Spectral_r",
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down
34 changes: 17 additions & 17 deletions stlearn/plotting/classes_bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
view = self.image.view(dtype=np.uint8).reshape((self.ydim, self.xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view[:, :, :] = np.flipud(np.asarray(img_pillow))
view[:, :, :] = np.asarray(img_pillow)

# Display the 32-bit RGBA image
self.dim = max(self.xdim, self.ydim)
Expand Down Expand Up @@ -159,7 +159,7 @@ def make_fig(self):

fig = figure(
title=self.gene_select.value,
x_range=(0, self.dim - 150),
x_range=(0, self.dim),
y_range=(self.dim, 0),
output_backend=self.output_backend.value,
name="GenePlot",
Expand All @@ -173,7 +173,7 @@ def make_fig(self):
fig.image_rgba(
image=[self.image],
x=0,
y=self.xdim,
y=0,
dw=self.ydim,
dh=self.xdim,
global_alpha=self.tissue_alpha.value,
Expand Down Expand Up @@ -251,11 +251,11 @@ def add_violin(self):
view2 = image2.view(dtype=np.uint8).reshape((ydim, xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view2[:, :, :] = np.flipud(np.asarray(img_pillow2))
view2[:, :, :] = np.asarray(img_pillow2)

p = figure(
plot_width=910,
plot_height=int(910 / xdim * ydim) + 5,
width=910,
height=int(910 / xdim * ydim) + 5,
output_backend=self.output_backend.value,
)

Expand Down Expand Up @@ -346,7 +346,7 @@ def __init__(
view = self.image.view(dtype=np.uint8).reshape((self.ydim, self.xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view[:, :, :] = np.flipud(np.asarray(img_pillow))
view[:, :, :] = np.asarray(img_pillow)

# Display the 32-bit RGBA image
self.dim = max(self.xdim, self.ydim)
Expand Down Expand Up @@ -556,7 +556,7 @@ def make_fig(self):
fig.image_rgba(
image=[self.image],
x=0,
y=self.xdim,
y=0,
dw=self.ydim,
dh=self.xdim,
global_alpha=self.tissue_alpha.value,
Expand Down Expand Up @@ -682,11 +682,11 @@ def add_dea(self):
view2 = image2.view(dtype=np.uint8).reshape((ydim, xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view2[:, :, :] = np.flipud(np.asarray(img_pillow2))
view2[:, :, :] = np.asarray(img_pillow2)

p = figure(
plot_width=910,
plot_height=int(910 / xdim * ydim) + 5,
width=910,
height=int(910 / xdim * ydim) + 5,
output_backend=self.output_backend.value,
)

Expand Down Expand Up @@ -796,7 +796,7 @@ def __init__(
view = self.image.view(dtype=np.uint8).reshape((self.ydim, self.xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view[:, :, :] = np.flipud(np.asarray(img_pillow))
view[:, :, :] = np.asarray(img_pillow)

# Display the 32-bit RGBA image
self.dim = max(self.xdim, self.ydim)
Expand Down Expand Up @@ -883,7 +883,7 @@ def make_fig(self):
fig.image_rgba(
image=[self.image],
x=0,
y=self.xdim,
y=0,
dw=self.ydim,
dh=self.xdim,
global_alpha=self.tissue_alpha.value,
Expand Down Expand Up @@ -975,7 +975,7 @@ def __init__(
view = self.image.view(dtype=np.uint8).reshape((self.ydim, self.xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view[:, :, :] = np.flipud(np.asarray(img_pillow))
view[:, :, :] = np.asarray(img_pillow)

# Display the 32-bit RGBA image
self.dim = max(self.xdim, self.ydim)
Expand Down Expand Up @@ -1072,7 +1072,7 @@ def make_fig(self):
fig.image_rgba(
image=[self.image],
x=0,
y=self.xdim,
y=0,
dw=self.ydim,
dh=self.xdim,
global_alpha=self.tissue_alpha.value,
Expand Down Expand Up @@ -1264,7 +1264,7 @@ def __init__(
view = self.image.view(dtype=np.uint8).reshape((self.ydim, self.xdim, 4))
# Copy the RGBA image into view, flipping it so it comes right-side up
# with a lower-left origin
view[:, :, :] = np.flipud(np.asarray(img_pillow))
view[:, :, :] = np.asarray(img_pillow)

# Display the 32-bit RGBA image
self.dim = max(self.xdim, self.ydim)
Expand Down Expand Up @@ -1320,7 +1320,7 @@ def make_fig(self):
fig.image_rgba(
image=[self.image],
x=0,
y=self.xdim,
y=0,
dw=self.ydim,
dh=self.xdim,
global_alpha=self.tissue_alpha.value,
Expand Down
2 changes: 1 addition & 1 deletion stlearn/plotting/cluster_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def cluster_plot(
cmap: Optional[str] = "default",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down
2 changes: 1 addition & 1 deletion stlearn/plotting/feat_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def feat_plot(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down
2 changes: 1 addition & 1 deletion stlearn/plotting/gene_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def gene_plot(
cmap: Optional[str] = "Spectral_r",
use_label: Optional[str] = None,
list_clusters: Optional[list] = None,
ax: Optional[matplotlib.axes._subplots.Axes] = None,
ax: Optional[matplotlib.axes.Axes] = None,
fig: Optional[matplotlib.figure.Figure] = None,
show_plot: Optional[bool] = True,
show_axis: Optional[bool] = False,
Expand Down
2 changes: 1 addition & 1 deletion stlearn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Empty(Enum):
from abc import ABC


class _AxesSubplot(Axes, axes.SubplotBase, ABC):
class _AxesSubplot(Axes, axes.SubplotBase):
"""Intersection between Axes and SubplotBase: Has methods of both"""


Expand Down
4 changes: 4 additions & 0 deletions stlearn/wrapper/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def Read10X(
adata.obs["imagerow"] = image_coor[:, 1]
adata.uns["spatial"][library_id]["use_quality"] = quality

adata.obs["array_row"] = adata.obs["array_row"].astype(int)
adata.obs["array_col"] = adata.obs["array_col"].astype(int)
adata.obsm["spatial"] = adata.obsm["spatial"].astype("int64")

return adata


Expand Down

0 comments on commit 10b105a

Please sign in to comment.