Skip to content

Commit

Permalink
reading and plotting update
Browse files Browse the repository at this point in the history
  • Loading branch information
leoguignard committed Jul 18, 2023
1 parent f8b0124 commit 52d57e5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/sc3D/sc3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def read_anndata(
self.tissue = dict(
zip(ids, map(tissue_map.get, data.obs[tissue_id]))
)
self.corres_tissue = {v: k for k, v in tissue_map.items()}

if gene_name_id in data.var:
data.var.set_index(gene_name_id, inplace=True)
Expand Down Expand Up @@ -722,6 +723,7 @@ def plot_coverslip(
legend=False,
color=None,
cells=None,
show=False,
**kwargs,
):
"""
Expand Down Expand Up @@ -749,7 +751,8 @@ def plot_coverslip(
fig (matplotlib.Figure): the created figure
ax (matplotlib.AxesSubplot): the working axis
"""
if ax is None:
pre_existing_ax = ax is not None
if not pre_existing_ax:
fig, ax = plt.subplots()
else:
fig = ax.get_figure()
Expand Down Expand Up @@ -792,9 +795,17 @@ def plot_coverslip(
]
scatter = ax.scatter(*positions.T, c=color, **scatter_args)
if legend:
ax.legend(
handles=scatter.legend_elements()[0], labels=np.unique(tissues)
)
from matplotlib import colormaps
cmap = colormaps[scatter_args["cmap"]]
mapping = lambda v: (v - scatter_args["vmin"]) / (scatter_args["vmax"] - scatter_args["vmin"])
for t in np.unique(tissues):
ax.plot([], [], linestyle="", marker=scatter_args["marker"], color=cmap(mapping(t)), label=self.corres_tissue.get(t, t))
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
if not pre_existing_ax:
ax.set_aspect("equal")
fig.tight_layout()
if show:
plt.show()
return fig, ax

def removing_spatial_outliers(self, th=0.2, n_components=3):
Expand Down Expand Up @@ -2206,7 +2217,7 @@ def compute_volumes(self, tissues_to_treat=None, bead_size=(10, 10, 30)):

def __init__(
self,
data_path,
data_path="",
tissues_to_ignore=None,
corres_tissue=None,
tissue_weight=None,
Expand Down

0 comments on commit 52d57e5

Please sign in to comment.