First, such a great tool - I now managed to run cellpose and get cell and nuclei masks. I work with skeletal muscle tissue so I would also potentially have multiple nuclei per cell. I`m not sure if that might be the problem of the below issue:
- I run the following code in a jupyter notebook:
fov_results = multistack.extract_cell(
cell_label=cell_label,
ndim=2,
nuc_label=nuc_label,
rna_coord=spots_no_ts,
others_coord={"foci": foci, "transcription_site": ts},
image=image_contrasted,
others_image={"dapi": nuclei, "smfish": fish},
check_nuc_in_cell=False) # IMPORTANT! otherwise it does not identify my cells
print("number of cells identified: {0}".format(len(fov_results)))
for i, cell_results in enumerate(fov_results):
print("cell {0}".format(i))
# get cell results
cell_mask = cell_results["cell_mask"]
cell_coord = cell_results["cell_coord"]
nuc_mask = cell_results["nuc_mask"]
nuc_coord = cell_results["nuc_coord"]
rna_coord = cell_results["rna_coord"]
foci_coord = cell_results["foci"]
ts_coord = cell_results["transcription_site"]
image_contrasted = cell_results["image"]
print("\r number of rna {0}".format(len(rna_coord)))
print("\r number of foci {0}".format(len(foci_coord)))
print("\r number of transcription sites {0}".format(len(ts_coord)))
# plot cell
plot.plot_cell(
ndim=2, cell_coord=cell_coord, nuc_coord=nuc_coord,
rna_coord=rna_coord, foci_coord=foci_coord, other_coord=ts_coord,
image=image_contrasted, cell_mask=cell_mask, nuc_mask=nuc_mask,
title="Cell {0}".format(i))
- sometimes it finds 29 cells (when I rerun the cell)
- it then sometimes finds 30 cells
- As I keep rerunning extract cells and the plots, I sometimes get empty masks, sometimes the first cell has half of the image in it, and sometimes the background crops just fine.




- However, the nuclei are not plotted and as is quite visible, the scale of the cells is off. I have no idea what this could be due to.
- I had to also swap the coordinates for the saved spots and clusters - they did not match with the mask arrays, once I did this the cell extraction worked - I now wonder whether this messed up the scale later on, below my thought process:
print("Dimensions of mask array:", nuc_label.shape)
print("Dimensions of mask array:", cell_label.shape)
# Check maximum coordinate values
max_coords = np.max(spots, axis=0)
print("Maximum coordinate values:", max_coords)
# Check minimum coordinate values
min_coords = np.min(spots, axis=0)
print("Minimum coordinate values:", min_coords)
Dimensions of mask array: (1790, 1800)
Dimensions of mask array: (1790, 1800)
Maximum coordinate values: [1799 1789 17]
Minimum coordinate values: [ 0 0 -1]
# Swap x and y coordinates for spots
sw_spots = np.copy(spots)
sw_spots[:, 0], sw_spots[:, 1] = spots[:, 1], spots[:, 0]
# Swap x and y coordinates for clusters
sw_clusters = np.copy(clusters)
sw_clusters[:, 0], sw_clusters[:, 1] = clusters[:, 1], clusters[:, 0]
# Check maximum coordinate values
max_coords = np.max(sw_spots, axis=0)
print("Maximum coordinate values:", max_coords)
# Check minimum coordinate values
min_coords = np.min(sw_spots, axis=0)
print("Minimum coordinate values:", min_coords)
Maximum coordinate values: [1789 1799 17]
Minimum coordinate values: [ 0 0 -1]
- This is how I saved the spots and clusters, I`m not sure whether there is a mistake in how they are saved. When I plot the spots, clusters and masks on top of each other I also have to flip the coordinates for the data to represent the original images. I load the .csv exactly as in the (6.) example notebook so I did not think I made a mistake there.
# save in csv files
path = os.path.join("test_spots.csv")
stack.save_data_to_csv(spots_post_clustering, path)
path = os.path.join("test_clusters.csv")
stack.save_data_to_csv(clusters, path)
Happy for any suggestions!
First, such a great tool - I now managed to run cellpose and get cell and nuclei masks. I work with skeletal muscle tissue so I would also potentially have multiple nuclei per cell. I`m not sure if that might be the problem of the below issue:
Happy for any suggestions!