Skip to content

Commit

Permalink
Merge pull request #60 from fish-quant/multistack
Browse files Browse the repository at this point in the history
Multistack subpackage
  • Loading branch information
Henley13 authored Jan 18, 2022
2 parents c95cb63 + 8ee7e55 commit d56b134
Show file tree
Hide file tree
Showing 23 changed files with 2,404 additions and 1,972 deletions.
8 changes: 7 additions & 1 deletion bigfish/detection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
and 3-d.
"""

# TODO adapt to float64 coordinates

from .spot_detection import detect_spots
from .spot_detection import local_maximum_detection
from .spot_detection import spots_thresholding
Expand All @@ -29,6 +31,7 @@

from .snr import compute_snr_spots

from .utils import convert_spot_coordinates

_spots = [
"detect_spots",
Expand Down Expand Up @@ -57,4 +60,7 @@
_snr = [
"compute_snr_spots"]

__all__ = _spots + _dense + _model + _clusters + _snr
_utils = [
"convert_spot_coordinates"]

__all__ = (_spots + _dense + _model + _clusters + _snr + _utils)
39 changes: 4 additions & 35 deletions bigfish/detection/cluster_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy as np
import bigfish.stack as stack
from sklearn.cluster import DBSCAN
from .utils import convert_spot_coordinates


# ### Detect clusters ###
Expand Down Expand Up @@ -87,38 +88,6 @@ def detect_clusters(spots, voxel_size_z=None, voxel_size_yx=100, radius=350,
return clustered_spots, clusters


def _convert_spot_coordinates(spots, voxel_size_z, voxel_size_yx):
"""Convert spots coordinates from pixel to nanometer.
Parameters
----------
spots : np.ndarray, np.int64
Coordinates of the detected spots with shape (nb_spots, 3) or
(nb_spots, 2).
voxel_size_z : int or float
Height of a voxel, along the z axis, in nanometer.
voxel_size_yx : int or float
Size of a voxel on the yx plan, in nanometer.
Returns
-------
spots_nanometer : np.ndarray, np.int64
Coordinates of the detected spots with shape (nb_spots, 3) or
(nb_spots, 3), in nanometer.
"""
# convert spots coordinates in nanometer
spots_nanometer = spots.copy()
if spots.shape[1] == 3:
spots_nanometer[:, 0] *= voxel_size_z
spots_nanometer[:, 1:] *= voxel_size_yx

else:
spots_nanometer *= voxel_size_yx

return spots_nanometer


def _cluster_spots(spots, voxel_size_z, voxel_size_yx, radius, nb_min_spots):
"""Assign a cluster to each spot.
Expand Down Expand Up @@ -149,9 +118,9 @@ def _cluster_spots(spots, voxel_size_z, voxel_size_yx, radius, nb_min_spots):
"""
# convert spots coordinates in nanometer
spots_nanometer = _convert_spot_coordinates(spots=spots,
voxel_size_z=voxel_size_z,
voxel_size_yx=voxel_size_yx)
spots_nanometer = convert_spot_coordinates(spots=spots,
voxel_size_z=voxel_size_z,
voxel_size_yx=voxel_size_yx)

# fit a DBSCAN clustering algorithm with a specific radius
dbscan = DBSCAN(eps=radius, min_samples=nb_min_spots)
Expand Down
39 changes: 39 additions & 0 deletions bigfish/detection/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Author: Arthur Imbert <[email protected]>
# License: BSD 3 clause

"""
Utility functions for bigfish.detection subpackage.
"""


def convert_spot_coordinates(spots, voxel_size_z, voxel_size_yx):
"""Convert spots coordinates from pixel to nanometer.
Parameters
----------
spots : np.ndarray, np.int64
Coordinates of the detected spots with shape (nb_spots, 3) or
(nb_spots, 2).
voxel_size_z : int or float
Height of a voxel, along the z axis, in nanometer.
voxel_size_yx : int or float
Size of a voxel on the yx plan, in nanometer.
Returns
-------
spots_nanometer : np.ndarray, np.int64
Coordinates of the detected spots with shape (nb_spots, 3) or
(nb_spots, 3), in nanometer.
"""
# convert spots coordinates in nanometer
spots_nanometer = spots.copy()
if spots.shape[1] == 3:
spots_nanometer[:, 0] *= voxel_size_z
spots_nanometer[:, 1:] *= voxel_size_yx

else:
spots_nanometer *= voxel_size_yx

return spots_nanometer
48 changes: 48 additions & 0 deletions bigfish/multistack/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Author: Arthur Imbert <[email protected]>
# License: BSD 3 clause

"""
The bigfish.multistack subpackage includes function to process input and output
from different channels.
"""

from .utils import check_recipe
from .utils import check_datamap

from .preprocess import build_stacks
from .preprocess import build_stack
from .preprocess import build_stack_no_recipe

from .colocalization import detect_spots_colocalization
from .colocalization import get_elbow_value_colocalized

from .cell_extraction import identify_objects_in_region
from .cell_extraction import remove_transcription_site
from .cell_extraction import match_nuc_cell
from .cell_extraction import extract_cell
from .cell_extraction import extract_spots_from_frame
from .cell_extraction import summarize_extraction_results

_utils = [
"check_recipe",
"check_datamap"]

_preprocess = [
"build_stacks",
"build_stack",
"build_stack_no_recipe"]

_colocalization = [
"detect_spots_colocalization",
"get_elbow_value_colocalized"]

_postprocess = [
"identify_objects_in_region",
"remove_transcription_site",
"match_nuc_cell",
"extract_cell",
"extract_spots_from_frame",
"summarize_extraction_results"]

__all__ = _utils + _preprocess + _colocalization + _postprocess
Loading

0 comments on commit d56b134

Please sign in to comment.