Skip to content

Commit

Permalink
implementing starMap refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Shannon Axelrod committed Oct 1, 2019
1 parent 120f989 commit 5996a09
Show file tree
Hide file tree
Showing 15 changed files with 516 additions and 78 deletions.
27 changes: 15 additions & 12 deletions notebooks/STARmap.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"import starfish\n",
"from starfish import IntensityTable\n",
"import starfish.data\n",
"from starfish.types import Axes\n",
"from starfish.types import Axes, TraceBuildingStrategies\n",
"from starfish.util.plot import (\n",
" diagnose_registration, imshow_plane, intensity_histogram\n",
")\n",
Expand Down Expand Up @@ -302,16 +302,20 @@
"metadata": {},
"outputs": [],
"source": [
"lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(\n",
" min_sigma=1,\n",
" max_sigma=8,\n",
" num_sigma=10,\n",
" threshold=np.percentile(np.ravel(stack.xarray.values), 95),\n",
" exclude_border=2,\n",
" anchor_round=0,\n",
" search_radius=10,\n",
")\n",
"intensities = lsbd.run(scaled, n_processes=8)"
"bd = starfish.spots.FindSpots.BlobDetector(min_sigma=1,\n",
" max_sigma=8,\n",
" num_sigma=10,\n",
" threshold=np.percentile(np.ravel(stack.xarray.values), 95),\n",
" exclude_border=2)\n",
"\n",
"spots = bd.run(scaled, n_processes=8)\n",
"decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=experiment.codebook,\n",
" anchor_round=0,\n",
" search_radius=10,\n",
" trace_building_strategy=\n",
" TraceBuildingStrategies.NEAREST_NEIGHBOR)\n",
"\n",
"decoded = decoder.run(spots=spots)"
]
},
{
Expand All @@ -331,7 +335,6 @@
"metadata": {},
"outputs": [],
"source": [
"decoded = experiment.codebook.decode_per_round_max(IntensityTable(intensities.fillna(0)))\n",
"decode_mask = decoded['target'] != 'nan'\n",
"\n",
"# %gui qt\n",
Expand Down
26 changes: 14 additions & 12 deletions notebooks/SeqFISH.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"\n",
"import starfish\n",
"import starfish.data\n",
"from starfish.spots import DetectSpots\n",
"from starfish.types import Axes"
"from starfish.types import Axes, TraceBuildingStrategies"
]
},
{
Expand Down Expand Up @@ -196,15 +195,18 @@
"source": [
"threshold = 0.5\n",
"\n",
"lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(\n",
" min_sigma=(1.5, 1.5, 1.5),\n",
" max_sigma=(8, 8, 8),\n",
" num_sigma=10,\n",
" threshold=threshold,\n",
" search_radius=7\n",
")\n",
"intensities = lsbd.run(clipped)\n",
"decoded = exp.codebook.decode_per_round_max(intensities.fillna(0))"
"bd = starfish.spots.FindSpots.BlobDetector(min_sigma=(1.5, 1.5, 1.5),\n",
" max_sigma=(8, 8, 8),\n",
" num_sigma=10,\n",
" threshold=threshold)\n",
"\n",
"spots = bd.run(clipped)\n",
"decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=exp.codebook,\n",
" search_radius=7,\n",
" trace_building_strategy=\n",
" TraceBuildingStrategies.NEAREST_NEIGHBOR)\n",
"\n",
"decoded = decoder.run(spots=spots)"
]
},
{
Expand All @@ -213,7 +215,7 @@
"metadata": {},
"outputs": [],
"source": [
"starfish.display(clipped, intensities)"
"starfish.display(clipped, decoded)"
]
},
{
Expand Down
27 changes: 15 additions & 12 deletions notebooks/py/STARmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import starfish
from starfish import IntensityTable
import starfish.data
from starfish.types import Axes
from starfish.types import Axes, TraceBuildingStrategies
from starfish.util.plot import (
diagnose_registration, imshow_plane, intensity_histogram
)
Expand Down Expand Up @@ -213,16 +213,20 @@ def plot_scaling_result(
# EPY: END markdown

# EPY: START code
lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(
min_sigma=1,
max_sigma=8,
num_sigma=10,
threshold=np.percentile(np.ravel(stack.xarray.values), 95),
exclude_border=2,
anchor_round=0,
search_radius=10,
)
intensities = lsbd.run(scaled, n_processes=8)
bd = starfish.spots.FindSpots.BlobDetector(min_sigma=1,
max_sigma=8,
num_sigma=10,
threshold=np.percentile(np.ravel(stack.xarray.values), 95),
exclude_border=2)

spots = bd.run(scaled, n_processes=8)
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=experiment.codebook,
anchor_round=0,
search_radius=10,
trace_building_strategy=
TraceBuildingStrategies.NEAREST_NEIGHBOR)

decoded = decoder.run(spots=spots)
# EPY: END code

# EPY: START markdown
Expand All @@ -234,7 +238,6 @@ def plot_scaling_result(
# EPY: END markdown

# EPY: START code
decoded = experiment.codebook.decode_per_round_max(IntensityTable(intensities.fillna(0)))
decode_mask = decoded['target'] != 'nan'

# %gui qt
Expand Down
26 changes: 14 additions & 12 deletions notebooks/py/SeqFISH.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

import starfish
import starfish.data
from starfish.spots import DetectSpots
from starfish.types import Axes
from starfish.types import Axes, TraceBuildingStrategies
# EPY: END code

# EPY: START markdown
Expand Down Expand Up @@ -117,19 +116,22 @@
# EPY: START code
threshold = 0.5

lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(
min_sigma=(1.5, 1.5, 1.5),
max_sigma=(8, 8, 8),
num_sigma=10,
threshold=threshold,
search_radius=7
)
intensities = lsbd.run(clipped)
decoded = exp.codebook.decode_per_round_max(intensities.fillna(0))
bd = starfish.spots.FindSpots.BlobDetector(min_sigma=(1.5, 1.5, 1.5),
max_sigma=(8, 8, 8),
num_sigma=10,
threshold=threshold)

spots = bd.run(clipped)
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=exp.codebook,
search_radius=7,
trace_building_strategy=
TraceBuildingStrategies.NEAREST_NEIGHBOR)

decoded = decoder.run(spots=spots)
# EPY: END code

# EPY: START code
starfish.display(clipped, intensities)
starfish.display(clipped, decoded)
# EPY: END code

# EPY: START markdown
Expand Down
31 changes: 26 additions & 5 deletions starfish/core/spots/DecodeSpots/per_round_max_channel_decoder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from typing import Callable, Optional

from starfish.core.codebook.codebook import Codebook
from starfish.core.intensity_table.decoded_intensity_table import DecodedIntensityTable
from starfish.core.intensity_table.intensity_table_coordinates import \
transfer_physical_coords_to_intensity_table
from starfish.core.spots.DecodeSpots.trace_builders import build_spot_traces_exact_match
from starfish.core.types import SpotFindingResults
from starfish.core.spots.DecodeSpots.trace_builders import trace_builders
from starfish.core.types import SpotFindingResults, TraceBuildingStrategies
from ._base import DecodeSpotsAlgorithm


Expand All @@ -20,11 +22,28 @@ class PerRoundMaxChannel(DecodeSpotsAlgorithm):
----------
codebook : Codebook
Contains codes to decode IntensityTable
trace_building_strategy: TraceBuildingStrategies
Defines the strategy for building spot traces to decode across rounds and chs of spot
finding results.
search_radius : Optional[int]
Only applicable if trace_building_strategy is TraceBuildingStrategies.NEAREST_NEIGHBORS.
Number of pixels over which to search for spots in other rounds and channels.
anchor_round : Optional[int]
Only applicable if trace_building_strategy is TraceBuildingStrategies.NEAREST_NEIGHBORS.
The imaging round against which other rounds will be checked for spots in the same
approximate pixel location.
"""

def __init__(self, codebook: Codebook):
def __init__(
self,
codebook: Codebook,
anchor_round: Optional[int]=1,
search_radius: Optional[int]=3,
trace_building_strategy: TraceBuildingStrategies=TraceBuildingStrategies.EXACT_MATCH):
self.codebook = codebook
self.trace_builder: Callable = trace_builders[trace_building_strategy]
self.anchor_round = anchor_round
self.search_radius = search_radius

def run(self, spots: SpotFindingResults, *args) -> DecodedIntensityTable:
"""Decode spots by selecting the max-valued channel in each sequencing round
Expand All @@ -40,6 +59,8 @@ def run(self, spots: SpotFindingResults, *args) -> DecodedIntensityTable:
IntensityTable decoded and appended with Features.TARGET and Features.QUALITY values.
"""
intensities = build_spot_traces_exact_match(spots)
intensities = self.trace_builder(spot_results=spots,
anchor_round=self.anchor_round,
search_radius=self.search_radius)
transfer_physical_coords_to_intensity_table(intensity_table=intensities, spots=spots)
return self.codebook.decode_per_round_max(intensities)
Empty file.
Loading

0 comments on commit 5996a09

Please sign in to comment.