-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advice on simple IF hystocytometry #81
Comments
Hello @cstrlln, thanks for the very detailed issue, your code is looking good! Indeed the Regarding the |
Thanks! Interesting, I will look into scyan. I also use spectral flow so could be pretty helpful. I got into an error when trying to do sdata.write:
I'm not that familiar with python structures but after checking with a chatbot, it looks like the issue was the coordinate being labelled as 'Z' and the function was looking for 'z'? This is what the data looked like
KeysView({'image': DataTree('None', parent=None) So I did this:
and then it worked. Is this issue because the way the image was imported? or the reader? Was there a way to avoid this issue? |
also, just noticed the z_scores are empty:
EDIT: actually no worries, seems like was accessing the wrong way, this worked:
10459 rows × 4 columns ```
|
Regarding the issue about the Concerning the z-scores, can you check that |
Yep, it was that for z_scores, the transposed values were the issue when trying to use pd.DataFrame. How can I access the raw intensity values? I guess I would need this for scyan? and where is the cellpose mask or segmentation stored? would like to check the segmentation more closely |
This depends on the technology you have:
For cellpose, we save the segmentation as polygons instead of masks, because masks can be very heavy in term of memory/storage. They can be found in the spatialdata object, at Hope this helps! |
Great, thanks for the responses. Just to be sure, for the case of protein only, I can take the intensities from adata.X, export this as a csv and then input this in scyan? Would it be possible to go back to sopa once I have obtained the cell label identities? for doing spatial analysis. I know that this is out of the scope of sopa, but figuring out how to work with protein only cases would be useful. Could you suggest an outline how to proceed? In any case I think this closes the original issue. |
Actually you don't even need to export In particular, you can skip the "loading a FCS/CSV" section, and directly start at this preprocessing step (I think asinh normalization should be fine for your type of data, but don't hesitate to try other transformations like
Then you can train Scyan according to this tutorial, but since you have fluorescence data I advise to try a high I'm closing the issue, but don't hesitate to let me know and ask other questions if you need more help! |
Thanks, I'll give this a try! |
Sorry going back to this I noticed this was not unswered: how best to go back to sopa once cell identities are obtained. |
Hi, usually sopa is used as a preprocessing step, and scyan can be used afterwards for cell annotation. Normally, you don't need sopa afterwards. Still, note that both # run sopa
sdata = ...
adata = sdata["table"]
table = pd.read_csv("...", index_col=0) # read your knowledge table
model = scyan.Scyan(adata, table, prior_std=1)
model.fit()
model.predict()
# now, adata is updated, as well as sdata which contains the adata object inside sdata["table"] But if you run Scyan separately and that you saved your anndata object somewhere else, you'll need to update the table from your spatialdata object (i.e. If you need to see the cell-types from Scyan inside the Xenium Explorer, then you can use this function, or follow this tutorial. |
Similar I guess to issue #78, I'm trying to use sopa to do histocymetry-like protocol with a one-round classic IF tissue staining. I have confocal image with 4 channels, I want to use cellpose with one channel (e.g. CH3) and would like to get the average intensity info of the other channels based on that segmentation. Then use the different levels of fluorescence to assign cell labels, cells will have combinations of CH1+CH2 or CH4+CH2 or single CH4 and CH1 with no CH2 intensity.
What would your workflow advice on going through this?
I tested the following code, but I guess the way I'm doing it is trying to look for cells with either of the markers and not taking into account double positives.
I'm still troubleshooting the min_area in the segmentation method, do you have a recommendation for this based on the diameter passed to cellpose?
SpatialData object with:
└── Images
└── 'image': MultiscaleSpatialImage[cyx] (4, 2947, 3921), (4, 1473, 1960), (4, 736, 980), (4, 368, 490), (4, 184, 245)
with coordinate systems:
▸ 'global', with elements:
image (Images)
[INFO] (sopa.segmentation.patching) 12 patches were saved in sdata['sopa_patches']
['CH1' 'CH2' 'CH3' 'CH4']
[INFO] (sopa.segmentation.shapes) Percentage of non-geometrized cells: 0.08% (usually due to segmentation artefacts)
[INFO] (sopa.segmentation.shapes) Percentage of non-geometrized cells: 0.00% (usually due to segmentation artefacts)
[INFO] (sopa.segmentation.shapes) Percentage of non-geometrized cells: 0.00% (usually due to segmentation artefacts)
[INFO] (sopa.segmentation.shapes) Percentage of non-geometrized cells: 0.12% (usually due to segmentation artefacts)
[INFO] (sopa.segmentation.shapes) Percentage of non-geometrized cells: 0.07% (usually due to segmentation artefacts)
[INFO] (sopa.segmentation.shapes) Percentage of non-geometrized cells: 0.00% (usually due to segmentation artefacts)
Reading patches: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 12/12 [00:00<00:00, 251.48it/s]
[INFO] (sopa.segmentation.stainings) Found 11295 total cells
Resolving conflicts: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2066/2066 [00:00<00:00, 6959.47it/s]
[INFO] (sopa.segmentation.stainings) Added 10459 cell boundaries in sdata['cellpose_boundaries']
NFO] (sopa.segmentation.aggregate) Averaging channels intensity over 10459 cells with expansion 0.0
[########################################] | 100% Completed | 1.52 sms
/Users/carlos/mambaforge/envs/sopa/lib/python3.10/site-packages/spatialdata/_core/_elements.py:92: UserWarning: Key
cellpose_boundaries
already exists. Overwriting it.self._check_key(key, self.keys(), self._shared_keys)
SpatialData object with:
├── Images
│ └── 'image': MultiscaleSpatialImage[cyx] (4, 2947, 3921), (4, 1473, 1960), (4, 736, 980), (4, 368, 490), (4, 184, 245)
├── Shapes
│ ├── 'cellpose_boundaries': GeoDataFrame shape: (10459, 1) (2D shapes)
│ └── 'sopa_patches': GeoDataFrame shape: (6, 3) (2D shapes)
└── Tables
└── 'table': AnnData (10459, 4)
with coordinate systems:
▸ 'global', with elements:
image (Images), cellpose_boundaries (Shapes), sopa_patches (Shapes)
[INFO] (sopa.annotation.fluorescence) Annotation counts: cell_type
marker-1 3794
segment_marker 2617
marker-3 2218
marker-2 1830
Name: count, dtype: int64
[INFO] (sopa.io.report.generate) Writing general_section
[INFO] (sopa.io.report.generate) Writing cell_section
[INFO] (sopa.io.report.generate) Writing channel_section
[INFO] (sopa.io.report.generate) Writing transcripts_section
[INFO] (sopa.io.report.generate) Writing representation_section
[INFO] (sopa.io.report.generate) Computing UMAP on 10459 cells
OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.
/Users/carlos/mambaforge/envs/sopa/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
[INFO] (sopa.io.report.generate) Writing report to report.html
AnnData object with n_obs × n_vars = 10459 × 4
obs: 'region', 'slide', 'cell_id', 'area', 'cell_type'
uns: 'sopa_attrs', 'spatialdata_attrs', 'pca', 'neighbors', 'umap', 'cell_type_colors'
obsm: 'spatial', 'z_scores', 'X_pca', 'X_umap'
varm: 'PCs'
obsp: 'distances', 'connectivities'
The text was updated successfully, but these errors were encountered: