-
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
Adding new modules and data SpotFindingResults class. #1515
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1515 +/- ##
==========================================
- Coverage 88.18% 87.26% -0.93%
==========================================
Files 138 139 +1
Lines 4978 5026 +48
==========================================
- Hits 4390 4386 -4
- Misses 588 640 +52
Continue to review full report at Codecov.
|
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.
Since this is a new class, it may be helpful to consider which APIs you want end users (i.e., pipeline users) to be using, and prefixing the other APIs with _.
Parameters | ||
----------- | ||
spot_attributes_list : Optional[List[Tuple[indices, SpotAttributes]]] | ||
If spots were fond using Imagestack.transform() the result is a list of |
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.
If spots were fond using Imagestack.transform() the result is a list of | |
If spots were found using ImageStack.transform() the result is a list of |
|
||
class SpotFindingResults: | ||
""" | ||
Wrapper class that describes the results from a spot finding method. The |
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.
is your fill column set to 80 and not 100?
class SpotFindingResults: | ||
""" | ||
Wrapper class that describes the results from a spot finding method. The | ||
results dict is a collection of (round,ch) indices and their corresponding measured |
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.
results dict is a collection of (round,ch) indices and their corresponding measured | |
results dict is a collection of (round, ch) indices and their corresponding measured |
(because you used a space below in your other tuple)
class SpotFindingResults: | ||
""" | ||
Wrapper class that describes the results from a spot finding method. The | ||
results dict is a collection of (round,ch) indices and their corresponding measured |
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.
Is this API doc likely to be read by an end user? Would results dict
be confusing?
tuples (indices, SpotAttributes). Instantiating SpotFindingResults with | ||
this list will convert the information to a dictionary. | ||
""" | ||
self._results: Mapping[Tuple, SpotAttributes] = dict() |
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.
This could be written as:
spot_attributes_list = spot_attributes_list or []
self._results: Mapping[Tuple, SpotAttributes] = {
indices: spots
for indices, spots in spot_attributes_list
}
for indices, spots in spot_attributes_list: | ||
self._results[indices] = spots | ||
|
||
def set_spots_for_round_ch(self, indices: Mapping[Axes, int], spots: SpotAttributes |
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.
nit: this function declaration style leads to unnecessary LOC changes. would prefer:
def set_spots_for_round_ch(self, indices: Mapping[Axes, int], spots: SpotAttributes) -> None:
or
def set_spots_for_round_ch(
self, indices: Mapping[Axes, int], spots: SpotAttributes) -> None:
or
def set_spots_for_round_ch(
self, indices: Mapping[Axes, int], spots: SpotAttributes,
) -> None:
All of these approaches do not produce unnecessary changes if the method name changes.
Describes spots found on this tile. | ||
""" | ||
round_ch_index = tuple(indices[i] for i in AXES_ORDER) | ||
self._results[round_ch_index] = spots # type: ignore |
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.
You can get rid of the # type: ignore
if you make self._results a MutableMapping
.
def set_spots_for_round_ch(self, indices: Mapping[Axes, int], spots: SpotAttributes | ||
) -> None: | ||
""" | ||
Add the r,ch indices and corresponding SpotAttributes to the results dict. |
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.
Add the r,ch indices and corresponding SpotAttributes to the results dict. | |
Add the round, ch indices and corresponding SpotAttributes to the results dict. |
to match what you are doing elsewhere.
""" | ||
Return the set of Round labels in the SpotFindingResults | ||
""" | ||
return list(set(sorted(r for (r, ch) in self.round_ch_indices()))) |
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.
if you take a set of sorted, then you lose the sorting. did you want sorted(set(...))?
""" | ||
Return the set of ch labels in the SpotFindingResults | ||
""" | ||
return list(set(sorted(ch for (c, ch) in self.round_ch_indices()))) |
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.
ditto.
starfish/core/types/__init__.py
Outdated
@@ -15,6 +15,7 @@ | |||
) | |||
from ._decoded_spots import DecodedSpots | |||
from ._spot_attributes import SpotAttributes | |||
from ._spot_finding_resutls import SpotFindingResults |
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.
from ._spot_finding_resutls import SpotFindingResults | |
from ._spot_finding_results import SpotFindingResults |
(and as such, the file probably needs to be renamed)
@abstractmethod | ||
def run(self, image_stack: ImageStack, | ||
reference_image: Optional[ImageStack] = None, *args) -> SpotFindingResults: | ||
"""Find and measure spots across rounds and chs in the provided ImageStack.""" |
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.
"""Find and measure spots across rounds and chs in the provided ImageStack.""" | |
"""Find and measure spots across rounds and channels in the provided ImageStack.""" |
AXES_ORDER = (Axes.ROUND, Axes.CH) | ||
|
||
|
||
class SpotFindingResults: |
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.
Given this wraps a dict, I would prefer this be implemented to mimic the dictionary container, and more clearly document what it contains. This should simplify a lot of the accessors you've written. For example,
+ def values(self):
- def all_spots(self):
- """
- Return all SpotAttributes across rounds and chs.
- """
return self._results.values()
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.
Yea so I started down this route but found that things became too confusing. For example get_spots_for_round_ch would instead just be getitem(key) and then when you used it it wasn't totally clear what you were getting. I'm not super opinionated on this though so open to changing it back if that's what you'd prefer I just thought this was more descriptive
""" | ||
Return the set of ch labels in the SpotFindingResults | ||
""" | ||
return list(sorted(set(ch for (c, ch) in self.round_ch_indices()))) |
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.
return list(sorted(set(ch for (c, ch) in self.round_ch_indices()))) | |
return list(sorted(set(ch for (r, ch) in self.round_ch_indices()))) |
1add80c
to
ae65a33
Compare
15c0db2
to
f60e4e3
Compare
ae65a33
to
66481de
Compare
f60e4e3
to
87178b9
Compare
66481de
to
d6c8012
Compare
b01a15a
to
87af7ad
Compare
d6c8012
to
667ebb1
Compare
87af7ad
to
1308d03
Compare
667ebb1
to
cc5a4c7
Compare
741bb16
to
afecd9c
Compare
5db69cb
to
dd52d49
Compare
afecd9c
to
5b11569
Compare
5b11569
to
1ddb24f
Compare
dd52d49
to
7fce7e4
Compare
1ddb24f
to
6145462
Compare
7fce7e4
to
a112655
Compare
6145462
to
49d8713
Compare
a112655
to
b73ab2f
Compare
49d8713
to
7d1f343
Compare
7d1f343
to
c033d9d
Compare
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 don't think this will doc correctly.
----------- | ||
spot_attributes_list : Optional[List[Tuple]] | ||
If spots were found using ImageStack.transform() the result is a list of | ||
tuples (indices, SpotAttributes). Instantiating SpotFindingResults with |
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.
The format for the indices is not very clear. It appears to be a Tuple of index values in the order of AXES_ORDER, but I'm just inferring that from the code.
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.
That's exactly what it is! I'll make it more clear
""" | ||
Return the set of Round labels in the SpotFindingResults | ||
""" | ||
return list(sorted(set(r for (r, ch) in self.keys()))) |
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 still think sorted(set(..)) would do what you want. the extra list() shouldn't be necessary.
>>> sorted(set([1, 2, 3, 4]))
[1, 2, 3, 4]
>>> ^D
@property | ||
def round_labels(self): | ||
""" | ||
Return the set of Round labels in the SpotFindingResults |
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.
Return the set of Round labels in the SpotFindingResults | |
Return the set of round labels in the SpotFindingResults |
c033d9d
to
e495707
Compare
e495707
to
26f2f41
Compare
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.
Just a few docs and comments issues, rest lgtm.
docs/source/api/spots/index.rst
Outdated
|
||
from starfish.spots import FindSpots | ||
|
||
.. autoclass:: starfish.spots.FindSpots |
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.
Isn't FindSpots a module? I think you want automodule
here to recursively pull in all the implementations in FindSpots
, and the weird logic to import in all the submodules of FindSpots
.
|
||
.. code-block:: python | ||
|
||
from starfish.spots import DecodeSpots |
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.
Ditto.
@abstractmethod | ||
def run(self, image_stack: ImageStack, | ||
reference_image: Optional[ImageStack] = None, *args) -> SpotFindingResults: | ||
"""Find and measure spots across rounds and channels in the provided |
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.
unwrap? I'd check your editor to make sure you're set up to 100col. This clocks in at 92col unwrapped for me.
26f2f41
to
803d1a4
Compare
This PR lays some of the ground work for the spot finding refactor.
Depends on #1489