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 10, 2019
1 parent 58eb7ac commit cd62776
Show file tree
Hide file tree
Showing 15 changed files with 509 additions and 65 deletions.
30 changes: 21 additions & 9 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 @@ -136,7 +136,7 @@
"source": [
"ch_z_max_projector = starfish.image.Filter.Reduce((Axes.CH, Axes.ZPLANE), func=\"max\")\n",
"projection = ch_r_max_projector.run(stack)\n",
"reference_image = projection.sel({Axes.ROUND: 1})\n",
"reference_image = projection.sel({Axes.ROUND: 0})\n",
"\n",
"ltt = starfish.image.LearnTransform.Translation(\n",
" reference_stack=reference_image,\n",
Expand Down Expand Up @@ -302,16 +302,14 @@
"metadata": {},
"outputs": [],
"source": [
"lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(\n",
"bd = starfish.spots.FindSpots.BlobDetector(\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)"
" exclude_border=2)\n",
"\n",
"spots = bd.run(scaled)"
]
},
{
Expand All @@ -331,7 +329,21 @@
"metadata": {},
"outputs": [],
"source": [
"decoded = experiment.codebook.decode_per_round_max(IntensityTable(intensities.fillna(0)))\n",
"decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(\n",
" codebook=experiment.codebook,\n",
" anchor_round=0,\n",
" search_radius=10,\n",
" trace_building_strategy=TraceBuildingStrategies.NEAREST_NEIGHBOR)\n",
"\n",
"decoded = decoder.run(spots=spots)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"decode_mask = decoded['target'] != 'nan'\n",
"\n",
"# %gui qt\n",
Expand Down
21 changes: 12 additions & 9 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,19 @@
"source": [
"threshold = 0.5\n",
"\n",
"lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(\n",
"bd = starfish.spots.FindSpots.BlobDetector(\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))"
" threshold=threshold)\n",
"\n",
"spots = bd.run(clipped)\n",
"decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(\n",
" codebook=exp.codebook,\n",
" search_radius=7,\n",
" trace_building_strategy=TraceBuildingStrategies.NEAREST_NEIGHBOR)\n",
"\n",
"decoded = decoder.run(spots=spots)"
]
},
{
Expand All @@ -213,7 +216,7 @@
"metadata": {},
"outputs": [],
"source": [
"starfish.display(clipped, intensities)"
"starfish.display(clipped, decoded)"
]
},
{
Expand Down
25 changes: 16 additions & 9 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 @@ -97,7 +97,7 @@
# EPY: START code
ch_z_max_projector = starfish.image.Filter.Reduce((Axes.CH, Axes.ZPLANE), func="max")
projection = ch_r_max_projector.run(stack)
reference_image = projection.sel({Axes.ROUND: 1})
reference_image = projection.sel({Axes.ROUND: 0})

ltt = starfish.image.LearnTransform.Translation(
reference_stack=reference_image,
Expand Down Expand Up @@ -213,16 +213,14 @@ def plot_scaling_result(
# EPY: END markdown

# EPY: START code
lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(
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,
anchor_round=0,
search_radius=10,
)
intensities = lsbd.run(scaled, n_processes=8)
exclude_border=2)

spots = bd.run(scaled)
# EPY: END code

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

# EPY: START code
decoded = experiment.codebook.decode_per_round_max(IntensityTable(intensities.fillna(0)))
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 code
decode_mask = decoded['target'] != 'nan'

# %gui qt
Expand Down
21 changes: 12 additions & 9 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,23 @@
# EPY: START code
threshold = 0.5

lsbd = starfish.spots.DetectSpots.LocalSearchBlobDetector(
bd = starfish.spots.FindSpots.BlobDetector(
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))
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,
trace_building_strategy: TraceBuildingStrategies = TraceBuildingStrategies.EXACT_MATCH,
anchor_round: Optional[int]=1,
search_radius: Optional[int]=3):
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 cd62776

Please sign in to comment.