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

Add spot finding and decoding docs #1825

Merged
merged 16 commits into from
Mar 23, 2020
Merged

Add spot finding and decoding docs #1825

merged 16 commits into from
Mar 23, 2020

Conversation

mattcai
Copy link
Contributor

@mattcai mattcai commented Mar 12, 2020

Added tutorials for spot based decoding components and pixel based decoding. Also made minor edits to some of the related classes as well as added ROI to glossary.

@mattcai mattcai closed this Mar 12, 2020
@mattcai mattcai reopened this Mar 12, 2020
@mattcai mattcai requested review from neuromusic, ttung and shanaxel42 and removed request for neuromusic March 12, 2020 18:10
@mattcai
Copy link
Contributor Author

mattcai commented Mar 12, 2020

read the docs link for spot finding docs

@codecov-io
Copy link

codecov-io commented Mar 12, 2020

Codecov Report

Merging #1825 into master will increase coverage by 0.36%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1825      +/-   ##
==========================================
+ Coverage   87.37%   87.74%   +0.36%     
==========================================
  Files         168      168              
  Lines        5784     5843      +59     
==========================================
+ Hits         5054     5127      +73     
+ Misses        730      716      -14
Impacted Files Coverage Δ
...sh/core/spots/DecodeSpots/simple_lookup_decoder.py 100% <ø> (ø) ⬆️
...e/spots/FindSpots/trackpy_local_max_peak_finder.py 97.91% <ø> (ø) ⬆️
...fish/core/spots/FindSpots/local_max_peak_finder.py 92.61% <100%> (+15.69%) ⬆️

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 1a47383...4b7f077. Read the comment docs.

@mattcai mattcai marked this pull request as ready for review March 12, 2020 18:19
Copy link
Collaborator

@ttung ttung left a comment

Choose a reason for hiding this comment

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

can you rebase this on top of the changes you made in #1821?


The spot-based approach finds spots in each image volume based on the brightness of regions
relative to their surroundings and then builds a :term:`spot trace<Feature (Spot, Pixel) Trace>`
using the appropriate ``TraceBuildingStrategies``. The spot traces can then be mapped, or
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to link somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does now :)


.. _section_which_decoding_approach:

What Decoding Pipeline Should I Use?
Copy link
Collaborator

Choose a reason for hiding this comment

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

so good.

🚀

If you are unsure which spot finding and decoding methods are compatible with your data here is a
handy table that summarizes the three major :term:`codebook <Codebook>` designs and what methods
can be
used to decode each of them. If your codebook doesn't fall into any of these categories, *make a
Copy link
Collaborator

Choose a reason for hiding this comment

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

link "make a feature request on github" to the issue creation page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done.

.. _section_segmenting_cells:

Segmenting Cells
----------------

Unlike single-cell RNA sequencing, image-based transcriptomics methods do not physically separate
cells before acquiring RNA information. Therefore, in order to characterize cells, the RNA must be
cells before acquiring RNA information. Therefore in order to characterize cells, the RNA must be
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like stuff that changed in your earlier PR.

@@ -48,6 +48,9 @@ Glossary
A collection of Image Tiles corresponding to a specific volume or plane of the sample, under which the signal for all channels and all imaging rounds were acquired. All tiles within this FOV are the same size, but the manifest allows for different spatial coordinates for different imaging rounds or channels (to accommodate slight movement between rounds, for example).
In microscopy, a field of view corresponds to the camera sensor mapped to the sample plane, and many such fields of view are expected to be taken per tissue slice.

Region of Interest (ROI)
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm, was this file alphabetically sorted at one point in time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe? I was debating between ordering it alphabetically vs by complexity. With ctrl-F and links to terms from within the text, nobody needs to search for things alphabetically anymore. And by ordering it from basic to advanced the glossary page is more educational. This is on my to do list before JOSS submission.

important for accurate decoding and it needs vector magnitude and distance thresholds. See
:ref:`howto_metricdistance` for more details.

After decoding pixels, :py:class:`.PixelSpotDecoder` combines connected pixels into spots with
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
After decoding pixels, :py:class:`.PixelSpotDecoder` combines connected pixels into spots with
After decoding pixels, :py:class:`.PixelSpotDecoder` combines connected pixels into spots with

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

min_mass=0.02,
max_size=2, # this is max radius
separation=7,
noise_size=0.65, # this is not used because preprocess is False
Copy link
Collaborator

Choose a reason for hiding this comment

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

if it's not used, can we not specify this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept it because noise_size is mentioned in the text and is a reminder of what preprocess does. But okay, removed.

separation=7,
noise_size=0.65, # this is not used because preprocess is False
preprocess=False,
percentile=10, # this is irrelevant when min_mass, spot_diameter, and max_size are set properly
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is important to keep imo because it's like a safety measure. I changed "is irrelevant" to "has no effect", do you think that is better?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perfect.

dpsf.run(imgs, in_place=True)
glp.run(imgs, in_place=True)

# scale data with user-defined factors to normalize images
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
# scale data with user-defined factors to normalize images
# scale data with user-defined factors to normalize images. For this data set, the scale factors are stored in experiment.json.

^^ suggested this because it's not required that the scale factors be in experiment.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Comment on lines 72 to 77
metric='euclidean', # distance metric to use for computing distance between a pixel vector and a codeword
norm_order=2, # the L_n norm is taken of each pixel vector and codeword before computing the distance. this is n
distance_threshold=0.5176, # minimum distance between a pixel vector and a codeword for it to be called as a gene
magnitude_threshold=1.77e-5, # discard any pixel vectors below this magnitude
min_area=2, # do not call a 'spot' if it's area is below this threshold (measured in pixels)
max_area=np.inf, # do not call a 'spot' if it's area is above this threshold (measured in pixels)
Copy link
Collaborator

Choose a reason for hiding this comment

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

these are great explanations!

Can we align the comments?

Suggested change
metric='euclidean', # distance metric to use for computing distance between a pixel vector and a codeword
norm_order=2, # the L_n norm is taken of each pixel vector and codeword before computing the distance. this is n
distance_threshold=0.5176, # minimum distance between a pixel vector and a codeword for it to be called as a gene
magnitude_threshold=1.77e-5, # discard any pixel vectors below this magnitude
min_area=2, # do not call a 'spot' if it's area is below this threshold (measured in pixels)
max_area=np.inf, # do not call a 'spot' if it's area is above this threshold (measured in pixels)
metric='euclidean', # distance metric to use for computing distance between a pixel vector and a codeword
norm_order=2, # the L_n norm is taken of each pixel vector and codeword before computing the distance. this is n
distance_threshold=0.5176, # minimum distance between a pixel vector and a codeword for it to be called as a gene
magnitude_threshold=1.77e-5, # discard any pixel vectors below this magnitude
min_area=2, # do not call a 'spot' if it's area is below this threshold (measured in pixels)
max_area=np.inf, # do not call a 'spot' if it's area is above this threshold (measured in pixels)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -235,6 +348,8 @@ segmenting images of stained cells.
Assigning Spots to Cells
------------------------

* :ref:`Assigning Spots to Cells <tutorial_assigning_spots_to_cells>`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this belongs or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is just a temporary placeholder.

Copy link
Collaborator

@shanaxel42 shanaxel42 left a comment

Choose a reason for hiding this comment

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

This work is really amazing, thank you so much for all the detailed explanations and charts!

about how spots can be found and decoded in starfish see :ref:`section_finding_and_decoding`.

There are two methods for viewing spots. The first is to access the :py:class:`.SpotAttributes`
of a selected ImageSlice and add it as points to the napari viewer. The second is to use a
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is actually, we call an entry in SpotFiindinigResults PerImageSliceSpotResults

that can be chosen with the ``detector_method`` argument when instantiating the
detector. The default LoG approach is best unless computation time becomes a concern.

In order to detects spots of various sizes in the same set of images, :py:class:`.BlobDetector`
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
In order to detects spots of various sizes in the same set of images, :py:class:`.BlobDetector`
In order to detect spots of various sizes in the same set of images, :py:class:`.BlobDetector`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Comment on lines +18 to +22
.. image:: /_static/design/tracebuilder_decisiontree.png
:scale: 50 %
:alt: Which TraceBuilder To Use
:align: center

Copy link
Collaborator

Choose a reason for hiding this comment

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

^^^ love a good flowchart

Copy link
Collaborator

@neuromusic neuromusic left a comment

Choose a reason for hiding this comment

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

nice job, Matt! a few changes suggested, but looks good to me

using the appropriate ``TraceBuildingStrategies``. The spot traces can then be mapped, or
*decoded*, to codewords in the codebook using a :py:class:`.DecodeSpotsAlgorithm`.

.. list-table::
Copy link
Collaborator

Choose a reason for hiding this comment

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

will the "width" option prevent the tables from overflowing?

https://docutils.sourceforge.io/docs/ref/rst/directives.html#table

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I tried multiple widths and units, none of them worked. Possibly due to a bug in readthedocs sphinx theme? I know I could fix this by making a grid table. But if we settle on a different sphinx theme that might fix the issue. I've made a note to fix this before JOSS submission.

or filters as they are sometimes called, find spots that are the same size as it.

Starfish implements this blob detection technique with :py:class:`.BlobDetector`. It supports three
`approaches <https://scikit-image.org/docs/dev/auto_examples/features_detection/plot_blob.html>_
Copy link
Collaborator

Choose a reason for hiding this comment

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

not rendering

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

"""
.. _tutorial_spot_based_decoding:

Spot-Based Decoding
Copy link
Collaborator

Choose a reason for hiding this comment

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

since this has no code to render, I think it makes more sense to move this content into the "finding and decoding spots" tutorial, perhaps replacing the "spot finding" section there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added code that compares the three spot finding algorithms

Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

…inding how-tos regarding their compatibility with cropped data sets and their support for 2D slices of a volume
@neuromusic
Copy link
Collaborator

closes #1480

@neuromusic neuromusic linked an issue Mar 20, 2020 that may be closed by this pull request
@neuromusic
Copy link
Collaborator

closes #1749

@mattcai mattcai requested a review from neuromusic March 20, 2020 20:21
@mattcai mattcai merged commit 7cbf539 into master Mar 23, 2020
@ttung ttung deleted the mcai-spots-docs branch March 31, 2020 04:08
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.

Finding and Decoding Spots Tutorials
5 participants