Skip to content
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

3.) SeqFish/StarMap/LocalBlobSearch #1592

Merged
merged 1 commit into from
Oct 10, 2019
Merged

Conversation

shanaxel42
Copy link
Collaborator

@shanaxel42 shanaxel42 commented Oct 1, 2019

Both STARmap and current Seqfish currently use LocalSearchBlobDetector. This refactor eliminates the need for a separate LocalSearchBlobDetector class and instead both assays now use the regular BlobDetector and the PerRoundMaxChannel with a trace building strategy of 'nearest neighbors'. A lot of the changes here are mostly just moving code that already existed in LocalSearchBlobDetector and a few changes to make BlobDetector work for both ISS and STARmap.

depends on: #1518 #1517

@shanaxel42 shanaxel42 changed the title SeqFish/StarMap/LocalSearch 3.) SeqFish/StarMap/LocalSearch Oct 1, 2019
@codecov-io
Copy link

codecov-io commented Oct 1, 2019

Codecov Report

Merging #1592 into master will increase coverage by 0.21%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1592      +/-   ##
==========================================
+ Coverage   88.04%   88.26%   +0.21%     
==========================================
  Files         151      152       +1     
  Lines        5171     5241      +70     
==========================================
+ Hits         4553     4626      +73     
+ Misses        618      615       -3
Impacted Files Coverage Δ
starfish/types.py 100% <ø> (ø) ⬆️
starfish/core/types/__init__.py 100% <ø> (ø) ⬆️
starfish/core/spots/DecodeSpots/trace_builders.py 100% <100%> (ø) ⬆️
starfish/core/types/_constants.py 98.21% <100%> (+0.1%) ⬆️
...re/spots/DetectSpots/local_search_blob_detector.py 95.23% <100%> (+0.04%) ⬆️
starfish/core/types/_spot_finding_results.py 96.96% <100%> (+0.19%) ⬆️
...spots/DecodeSpots/per_round_max_channel_decoder.py 100% <100%> (ø) ⬆️
starfish/core/spots/DecodeSpots/util.py 100% <100%> (ø)
starfish/core/spots/FindSpots/blob.py 95.91% <100%> (+6.78%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58eb7ac...cd62776. Read the comment docs.

@shanaxel42 shanaxel42 changed the title 3.) SeqFish/StarMap/LocalSearch SeqFish/StarMap/LocalBlobSearch Oct 1, 2019
@shanaxel42 shanaxel42 changed the title SeqFish/StarMap/LocalBlobSearch 3.) SeqFish/StarMap/LocalBlobSearch Oct 1, 2019
@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch 2 times, most recently from cffb21c to 5996a09 Compare October 1, 2019 15:32
@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch from 5996a09 to 8dd6a0b Compare October 3, 2019 17:42
@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch 4 times, most recently from ed13a8b to 6d4a553 Compare October 8, 2019 17:31
threshold=np.percentile(np.ravel(stack.xarray.values), 95),
exclude_border=2)

spots = bd.run(scaled, n_processes=8)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this has an explicit n_processes setting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, changed it to the default

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also possible that it was done to survive travis...?

Comment on lines 223 to 227
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=experiment.codebook,
anchor_round=0,
search_radius=10,
trace_building_strategy=
TraceBuildingStrategies.NEAREST_NEIGHBOR)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, if you stick the parameters onto the next line, it'll format better.

Suggested change
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=experiment.codebook,
anchor_round=0,
search_radius=10,
trace_building_strategy=
TraceBuildingStrategies.NEAREST_NEIGHBOR)
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(
codebook=experiment.codebook,
anchor_round=0,
search_radius=10,
trace_building_strategy=TraceBuildingStrategies.NEAREST_NEIGHBOR)

threshold=threshold)

spots = bd.run(clipped)
decoder = starfish.spots.DecodeSpots.PerRoundMaxChannel(codebook=exp.codebook,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

def __init__(
self,
codebook: Codebook,
anchor_round: Optional[int]=1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parameter order you have in the docblock makes more sense as the optional params only pertain to certain selections of trace_building_strategy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

def build_traces_nearest_neighbors(spot_results: SpotFindingResults, anchor_round: int=1,
search_radius: int=3):
"""
Combine spots found across round and channels of ana ImageStack using a nearest neighbors
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Combine spots found across round and channels of ana ImageStack using a nearest neighbors
Combine spots found across round and channels of an ImageStack using a nearest neighbors

feature_index = np.arange(ind.shape[0], dtype=int)

# mask spots that are outside the search radius
mask = np.asarray(dist[r] < search_radius) # indices need not match
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meta question (and out of the scope of this PR), but why is distance in x-y space treated the same as distance in z-space? intuitively that seems incorrect to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a good question @ambrosejcarr ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the properties of the data acquisition, In most cases it should not be treated the same (although there are exceptions). This is the way the search was implemented by the authors of the pipeline, and so it is how we implemented it. If it is simple to set search radii differently for x, y, z, that would be an improvement.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a really good question

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that we file an issue to discuss this, and perhaps engage some ppl who use this approach to discuss. It may not matter in the end, but it does not currently pass the smell test. :)

) -> Dict[int, pd.DataFrame]:
"""Merge DataFrames containing spots from different channels into one DataFrame per round.

Executed on the output of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment on lines 223 to 229
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go after the next markdown block.

from starfish.core.types import Axes


def traversing_code() -> ImageStack:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be really exhaustive, there should probably be a test case for testing the distance filter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which distance filter? the search_radius param?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically to make sure that trace building deals with the search_radius param correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh got it. More then what's already in the jitter_code test where it checks that it doesn't build traces when the search radius is below the 3px distance?

for r in sorted(set(round_dataframes.keys()) - {anchor_round, }):
query_df = round_dataframes[r]
query_coordinates = query_df[[Axes.ZPLANE, Axes.Y, Axes.X]]
nn = NearestNeighbors(n_neighbors=1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does NN not support a distance filter intrinsically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like no there's a metric param that might work. But probs another question for @ambrosejcarr

@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch from 6d4a553 to f4c676c Compare October 8, 2019 22:48
@shanaxel42 shanaxel42 force-pushed the saxelrod-iss-new-spot-finding branch 2 times, most recently from e6c6431 to cf170a5 Compare October 8, 2019 22:56
@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch 2 times, most recently from 147cd1a to c80190f Compare October 9, 2019 15:24
@shanaxel42 shanaxel42 changed the base branch from saxelrod-iss-new-spot-finding to master October 9, 2019 15:25
@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch 4 times, most recently from 1f4858f to df82f1e Compare October 9, 2019 21:55
@shanaxel42 shanaxel42 requested a review from ttung October 9, 2019 21:56
@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch from df82f1e to a900ebd Compare October 9, 2019 23:25
assert np.all(c == np.array([0, 0, 1]))
assert np.all(r == np.array([0, 2, 1]))

# test again with smaller search radius
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

feature_index = np.arange(ind.shape[0], dtype=int)

# mask spots that are outside the search radius
mask = np.asarray(dist[r] < search_radius) # indices need not match
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose that we file an issue to discuss this, and perhaps engage some ppl who use this approach to discuss. It may not matter in the end, but it does not currently pass the smell test. :)

@ttung
Copy link
Collaborator

ttung commented Oct 10, 2019

Tests are failing though.

@shanaxel42 shanaxel42 force-pushed the saxelrod-starMap-refactor branch from a900ebd to cd62776 Compare October 10, 2019 15:15
@shanaxel42 shanaxel42 merged commit 6bf1d96 into master Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants