Skip to content
Snippets Groups Projects
Commit 32c190f1 authored by Guillaume Cerutti's avatar Guillaume Cerutti
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# Packages
*.egg
*.egg-info
.eggs
.Python
*.pth
dist/
build/
env/
downloads/
eggs/
parts/
bin/
var/
sdist/
develop-eggs/
.installed.cfg
lib/
lib64/
# editors
.idea/
# Vim files
*.swp
*.*~
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
.settings
# C extensions
*.so
*.dll
*.dylib
# Compiled Static libraries
*.lai
*.la
*.a
# Compiled Object files
*.os
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
.amlog
.sconsign.dblite
# Translations
*.mo
*.pot
# Django stuff:
*.log
# PyBuilder
target/
# jupyter notebooks
.ipynb_checkpoints/
# Microsoft office temporary files
~$*.docx
~$*.pptx
~$*.xlsx
# svn
.svn
# coverage
.coverage
.DS_Store
# user custom filters
name: nuclei-quantification
channels:
- mosaic
- conda-forge
- morpheme
- defaults
dependencies:
- python =3.9
- jupyter
- numpy
- scipy
- pandas
- matplotlib
- pyvista
- ipyvtklink
- timagetk =3
- visu_core
%% Cell type:markdown id:6704c6e8 tags:
# Nuclei Fie/Cas9 Quantification
### Necessary imports
%% Cell type:code id:7002eb02 tags:
``` python
import numpy as np
import scipy.ndimage as nd
import pandas as pd
import matplotlib.pyplot as plt
import pyvista as pv
pv.set_jupyter_backend('ipyvtklink')
from timagetk import SpatialImage
from timagetk.io import imread
from timagetk.algorithms.peak_detection import detect_nuclei
from timagetk.algorithms.signal_quantification import quantify_nuclei_signal_intensity
from visu_core.vtk.utils.image_tools import vtk_image_data_from_image
```
%% Cell type:markdown id:c196d5ba tags:
### Data specification
%% Cell type:code id:ab076632 tags:
``` python
dirname = "../data/"
filename = "230315_GK_86_9_T1_5"
```
%% Cell type:markdown id:a1023b95 tags:
### Parameters
%% Cell type:code id:86777931 tags:
``` python
detection_threshold = 100,
detection_radius_range = (0.8, 3)
quantification_radius = 2.5
```
%% Cell type:markdown id:165d542f tags:
### Image loading
%% Cell type:code id:8bfe671b tags:
``` python
image_filename = f"{dirname}/{filename}.tif"
img = imread(image_filename, channel_names=['FieGFP', 'Calco', 'Cas9RFP'])
```
%% Cell type:code id:2234e546 tags:
``` python
image_datas = {}
for channel_name in img.channel_names:
image_data = vtk_image_data_from_image(img[channel_name].get_array(), img.voxelsize)
image_data = pv.UniformGrid(image_data)
image_data.point_data.GetArray(0).SetName(channel_name)
image_datas[channel_name] = image_data
plotter = pv.Plotter(notebook=True)
plotter.set_background('w')
plotter.add_volume(image_datas['Cas9RFP'], cmap='Greys', clim=(0, 2000))
plotter.show()
```
%% Cell type:code id:6195742e tags:
``` python
figure = plt.figure(figsize=(20, 10))
extent = (
-img.voxelsize[2]/2,
img.extent[2]+img.voxelsize[2]/2,
img.extent[1]+img.voxelsize[1]/2,
-img.voxelsize[1]/2,
)
figure.add_subplot(1, 2 ,1)
figure.gca().imshow(
np.max([img['FieGFP'].get_array(), img['Cas9RFP'].get_array()], axis=0).max(axis=0),
extent=extent
)
figure.add_subplot(1, 2 ,2)
figure.gca().imshow(
np.sum([img['FieGFP'].get_array(), img['Cas9RFP'].get_array()], axis=0).max(axis=0),
extent=extent
)
```
%% Cell type:markdown id:7ab91cea tags:
### Nuclei detection on fused channels
%% Cell type:code id:0d13fd28 tags:
``` python
nuclei_img = SpatialImage(
np.sum([img['FieGFP'].get_array(), img['Cas9RFP'].get_array()], axis=0),
voxelsize=img.voxelsize
)
nuclei_points = detect_nuclei(
nuclei_img,
threshold=detection_threshold,
radius_range=detection_radius_range
)
```
%% Cell type:code id:66ee5adb tags:
``` python
figure = plt.figure(figsize=(10, 10))
extent = (
-img.voxelsize[2]/2,
img.extent[2]+img.voxelsize[2]/2,
img.extent[1]+img.voxelsize[1]/2,
-img.voxelsize[1]/2,
)
figure.gca().imshow(
nuclei_img.get_array().max(axis=0),
extent=extent
)
figure.gca().scatter(
nuclei_points[:, 0],
nuclei_points[:, 1],
color='r'
)
```
%% Cell type:markdown id:6e171d20 tags:
### Nuclei signal quantification
%% Cell type:code id:7c5f3bb1 tags:
``` python
nuclei_signals = {
signal_name: quantify_nuclei_signal_intensity(
img[signal_name],
nuclei_points,
nuclei_sigma=quantification_radius
)
for signal_name in ['FieGFP', 'Cas9RFP']
}
```
%% Cell type:code id:a3d7b5c4 tags:
``` python
import matplotlib.pyplot as plt
figure = plt.figure(figsize=(20, 10))
extent = (
-img.voxelsize[2]/2,
img.extent[2]+img.voxelsize[2]/2,
img.extent[1]+img.voxelsize[1]/2,
-img.voxelsize[1]/2,
)
for i, signal_name in enumerate(['FieGFP', 'Cas9RFP']):
figure.add_subplot(1, 2, i+1)
figure.gca().imshow(
img[signal_name].get_array().max(axis=0),
extent=extent,
)
figure.gca().scatter(
nuclei_points[:, 0],
nuclei_points[:, 1],
c=nuclei_signals[signal_name],
cmap='Reds'
)
```
%% Cell type:code id:6e7b756f tags:
``` python
nuclei_mask = nuclei_points[:, 1]>200
#nuclei_mask = np.ones_like(nuclei_points[:, 1]).astype(bool)
figure = plt.figure(figsize=(10, 10))
figure.gca().scatter(
nuclei_signals['Cas9RFP'][nuclei_mask],
nuclei_signals['FieGFP'][nuclei_mask],
c=nuclei_points[:, 1][nuclei_mask],
cmap="Reds",
)
```
%% Cell type:markdown id:95a97827 tags:
### Data export
%% Cell type:code id:0bea4d68 tags:
``` python
nuclei_data = {
'id': range(len(nuclei_points)),
}
nuclei_data.update({
f'center_{dim}': nuclei_points[:, i]
for i, dim in enumerate('xyz')
})
nuclei_data.update(nuclei_signals)
nuclei_df = pd.DataFrame(nuclei_data)
nuclei_df.head()
```
%% Cell type:code id:487153ec tags:
``` python
nuclei_filename = f"{dirname}/{filename}_nuclei_data.csv"
nuclei_df.to_csv(nuclei_filename, index=False)
```
%% Cell type:markdown id:e7b650b8 tags:
### Individual nuclei slices
%% Cell type:code id:95d74f9c tags:
``` python
nucleus_window = 30
nucleus_extent = (
(-nucleus_window-0.5)*img.voxelsize[2],
(nucleus_window+0.5)*img.voxelsize[2],
(nucleus_window+0.5)*img.voxelsize[1],
(-nucleus_window-0.5)*img.voxelsize[1],
)
for nucleus_id in range(len(nuclei_points)):
nucleus_coords = (nuclei_points[nucleus_id][::-1]/img.voxelsize).astype(int)
figure = plt.figure(figsize=(20, 10))
for i, signal_name in enumerate(['FieGFP', 'Cas9RFP']):
figure.add_subplot(1, 2, i+1)
nucleus_img = img[signal_name].get_array()[nucleus_coords[0],
nucleus_coords[1]-40:nucleus_coords[1]+40,
nucleus_coords[2]-40:nucleus_coords[2]+40]
figure.gca().imshow(
nucleus_img,
extent=nucleus_extent,
)
figure.gca().set_title(signal_name, size=18)
figure.suptitle(f"Nucleus {nucleus_id}", size=24)
figure.tight_layout()
```
%% Cell type:code id:e32bc393 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment