-
Notifications
You must be signed in to change notification settings - Fork 68
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
4.) refactoring allen smFish with new spot finding #1593
Merged
+697
−41
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ | |
|
||
import starfish | ||
import starfish.data | ||
from starfish import FieldOfView, IntensityTable | ||
from starfish import FieldOfView, DecodedIntensityTable | ||
from starfish.types import TraceBuildingStrategies | ||
|
||
# equivalent to %gui qt | ||
ipython = get_ipython() | ||
|
@@ -72,7 +73,7 @@ | |
# EPY: END markdown | ||
|
||
# EPY: START code | ||
tlmpf = starfish.spots.DetectSpots.TrackpyLocalMaxPeakFinder( | ||
tlmpf = starfish.spots.FindSpots.TrackpyLocalMaxPeakFinder( | ||
spot_diameter=5, # must be odd integer | ||
min_mass=0.02, | ||
max_size=2, # this is max radius | ||
|
@@ -96,6 +97,7 @@ | |
import sys | ||
print = partial(print, file=sys.stderr) | ||
|
||
|
||
def processing_pipeline( | ||
experiment: starfish.Experiment, | ||
fov_name: str, | ||
|
@@ -123,6 +125,11 @@ def processing_pipeline( | |
print("Loading images...") | ||
images = enumerate(experiment[fov_name].get_images(FieldOfView.PRIMARY_IMAGES)) | ||
|
||
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel( | ||
codebook=codebook, | ||
trace_building_strategy=TraceBuildingStrategies.SEQUENTIAL | ||
) | ||
|
||
for image_number, primary_image in images: | ||
print(f"Filtering image {image_number}...") | ||
filter_kwargs = dict( | ||
|
@@ -140,15 +147,14 @@ def processing_pipeline( | |
clip2.run(primary_image, **filter_kwargs) | ||
|
||
print("Calling spots...") | ||
spot_attributes = tlmpf.run(primary_image) | ||
all_intensities.append(spot_attributes) | ||
spots = tlmpf.run(primary_image) | ||
print("Decoding spots...") | ||
decoded_intensities = decoder.run(spots) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should add |
||
all_intensities.append(decoded_intensities) | ||
|
||
spot_attributes = IntensityTable.concatenate_intensity_tables(all_intensities) | ||
|
||
print("Decoding spots...") | ||
decoded = codebook.decode_per_round_max(spot_attributes) | ||
decoded = DecodedIntensityTable.concatenate_intensity_tables(all_intensities) | ||
decoded = decoded[decoded["total_intensity"] > .025] | ||
|
||
print("Processing complete.") | ||
|
||
return primary_image, decoded | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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 TRACE_BUILDERS | ||
from starfish.core.types import Number, SpotFindingResults, TraceBuildingStrategies | ||
from ._base import DecodeSpotsAlgorithm | ||
|
||
|
||
class MetricDistance(DecodeSpotsAlgorithm): | ||
""" | ||
Normalizes both the magnitudes of the codes and the spot intensities, then decodes spots by | ||
assigning each spot to the closest code, measured by the provided metric. | ||
|
||
Codes greater than max_distance from the nearest code, or dimmer than min_intensity, are | ||
discarded. | ||
|
||
Parameters | ||
---------- | ||
codebook : Codebook | ||
codebook containing targets the experiment was designed to quantify | ||
max_distance : Number | ||
spots greater than this distance from their nearest target are not decoded | ||
min_intensity : Number | ||
spots dimmer than this intensity are not decoded | ||
metric : str | ||
the metric to use to measure distance. Can be any metric that satisfies the triangle | ||
inequality that is implemented by :py:mod:`scipy.spatial.distance` (default "euclidean") | ||
norm_order : int | ||
the norm to use to normalize the magnitudes of spots and codes (default 2, L2 norm) | ||
trace_building_strategy: TraceBuildingStrategies | ||
Defines the strategy for building spot traces to decode across rounds and chs of spot | ||
finding results. | ||
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. | ||
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. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
codebook: Codebook, | ||
max_distance: Number, | ||
min_intensity: Number, | ||
norm_order: int = 2, | ||
metric: str = "euclidean", | ||
trace_building_strategy: TraceBuildingStrategies = TraceBuildingStrategies.EXACT_MATCH, | ||
anchor_round: int = 1, | ||
search_radius: int = 3, | ||
) -> None: | ||
self.codebook = codebook | ||
self.max_distance = max_distance | ||
self.min_intensity = min_intensity | ||
self.norm_order = norm_order | ||
self.metric = metric | ||
self.trace_builder = 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 | ||
|
||
Parameters | ||
---------- | ||
spots : SpotFindingResults | ||
A Dict of tile indices and their corresponding measured spots | ||
|
||
Returns | ||
------- | ||
DecodedIntensityTable : | ||
IntensityTable decoded and appended with Features.TARGET and Features.QUALITY values. | ||
|
||
""" | ||
|
||
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_metric( | ||
intensities, | ||
max_distance=self.max_distance, | ||
min_intensity=self.min_intensity, | ||
norm_order=self.norm_order, | ||
metric=self.metric, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following the other components of this pipeline, this should be above (search for "define")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to put it above but there's no access to the experiment.codebook at that point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I see.