Ejemplo n.º 1
0
def process_fov(fov: FieldOfView, codebook: Codebook) -> DecodedIntensityTable:
    """Process a single field of view of ISS data

    Parameters
    ----------
    fov : FieldOfView
        the field of view to process
    codebook : Codebook
        the Codebook to use for decoding

    Returns
    -------
    DecodedSpots :
        tabular object containing the locations of detected spots.
    """

    # note the structure of the 5D tensor containing the raw imaging data
    imgs = fov.get_image(FieldOfView.PRIMARY_IMAGES)
    dots = fov.get_image("dots")
    nuclei = fov.get_image("nuclei")

    print("Learning Transform")
    learn_translation = LearnTransform.Translation(reference_stack=dots,
                                                   axes=Axes.ROUND,
                                                   upsampling=1000)
    transforms_list = learn_translation.run(
        imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max"))

    print("Applying transform")
    warp = ApplyTransform.Warp()
    registered_imgs = warp.run(imgs,
                               transforms_list=transforms_list,
                               verbose=True)

    print("Filter WhiteTophat")
    filt = Filter.WhiteTophat(masking_radius=15, is_volume=False)

    filtered_imgs = filt.run(registered_imgs, verbose=True)
    filt.run(dots, verbose=True, in_place=True)
    filt.run(nuclei, verbose=True, in_place=True)

    print("Detecting")
    detector = FindSpots.BlobDetector(
        min_sigma=1,
        max_sigma=10,
        num_sigma=30,
        threshold=0.01,
        measurement_type='mean',
    )
    dots_max = dots.reduce((Axes.ROUND, Axes.ZPLANE),
                           func="max",
                           module=FunctionSource.np)
    spots = detector.run(image_stack=filtered_imgs, reference_image=dots_max)

    print("Decoding")
    decoder = DecodeSpots.PerRoundMaxChannel(codebook=codebook)
    decoded = decoder.run(spots=spots)
    return decoded
Ejemplo n.º 2
0
def find_spots(imgs, dots):

    p = FindSpots.BlobDetector(
        min_sigma=1,
        max_sigma=10,
        num_sigma=30,
        threshold=0.01,
        measurement_type='mean',
    )

    intensities = p.run(image_stack=imgs, reference_image=dots)
    return intensities
Ejemplo n.º 3
0
def iss_pipeline(fov, codebook):
    primary_image = fov.get_image(starfish.FieldOfView.PRIMARY_IMAGES)

    # register the raw image
    learn_translation = LearnTransform.Translation(
        reference_stack=fov.get_image('dots'), axes=Axes.ROUND, upsampling=100)
    transforms_list = learn_translation.run(
        primary_image.reduce({Axes.CH, Axes.ZPLANE}, func="max"))
    warp = ApplyTransform.Warp()
    registered = warp.run(primary_image,
                          transforms_list=transforms_list,
                          in_place=False,
                          verbose=True)

    # filter raw data
    masking_radius = 15
    filt = Filter.WhiteTophat(masking_radius, is_volume=False)
    filtered = filt.run(registered, verbose=True, in_place=False)

    bd = FindSpots.BlobDetector(
        min_sigma=1,
        max_sigma=10,
        num_sigma=30,
        threshold=0.01,
        measurement_type='mean',
    )

    # detect spots using laplacian of gaussians approach
    dots_max = fov.get_image('dots').reduce((Axes.ROUND, Axes.ZPLANE),
                                            func="max",
                                            module=FunctionSource.np)
    # locate spots in a reference image
    spots = bd.run(reference_image=dots_max, image_stack=filtered)

    # decode the pixel traces using the codebook
    decoder = DecodeSpots.PerRoundMaxChannel(codebook=codebook)
    decoded = decoder.run(spots=spots)

    # segment cells
    seg = Segment.Watershed(
        nuclei_threshold=.16,
        input_threshold=.22,
        min_distance=57,
    )
    label_image = seg.run(primary_image, fov.get_image('dots'))

    # assign spots to cells
    ta = AssignTargets.Label()
    assigned = ta.run(label_image, decoded)

    return assigned, label_image
Ejemplo n.º 4
0
masking_radius = 15
filt = Filter.WhiteTophat(masking_radius, is_volume=False)
filt.run(imgs, in_place=True)
filt.run(dots, in_place=True)

# register primary images to reference round
learn_translation = LearnTransform.Translation(reference_stack=dots,
                                               axes=Axes.ROUND,
                                               upsampling=1000)
transforms_list = learn_translation.run(
    imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max"))
warp = ApplyTransform.Warp()
warp.run(imgs, transforms_list=transforms_list, in_place=True)

# run blob detector on dots (reference image with every spot)
bd = FindSpots.BlobDetector(
    min_sigma=1,
    max_sigma=10,
    num_sigma=30,
    threshold=0.01,
    measurement_type='mean',
)
dots_max = dots.reduce((Axes.ROUND, Axes.ZPLANE), func="max")
spots = bd.run(image_stack=imgs, reference_image=dots_max)

# Decode spots with PerRoundMaxChannel
from starfish.spots import DecodeSpots
decoder = DecodeSpots.PerRoundMaxChannel(
    codebook=experiment.codebook,
    trace_building_strategy=TraceBuildingStrategies.EXACT_MATCH)
decoded_intensities = decoder.run(spots=spots)
Ejemplo n.º 5
0
fov = experiment.fov()
imgs = fov.get_image(FieldOfView.PRIMARY_IMAGES) # primary images
dots = fov.get_image("dots") # reference round where every spot labeled with fluorophore

# filter raw data
masking_radius = 15
filt = Filter.WhiteTophat(masking_radius, is_volume=False)
filt.run(imgs, in_place=True)
filt.run(dots, in_place=True)

# register primary images to reference round
learn_translation = LearnTransform.Translation(reference_stack=dots, axes=Axes.ROUND, upsampling=1000)
transforms_list = learn_translation.run(imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max"))
warp = ApplyTransform.Warp()
warp.run(imgs, transforms_list=transforms_list, in_place=True)

# view dots to estimate radius of spots: radius range from 1.5 to 4 pixels
imshow_plane(dots, {Axes.X: (500, 550), Axes.Y: (600, 650)})

# run blob detector with dots as reference image
# following guideline of sigma = radius/sqrt(2) for 2D images
# threshold is set conservatively low
bd = FindSpots.BlobDetector(
    min_sigma=1,
    max_sigma=3,
    num_sigma=10,
    threshold=0.01,
    is_volume=False,
    measurement_type='mean',
)
spots = bd.run(image_stack=imgs, reference_image=dots)
Ejemplo n.º 6
0
             })

####################################################################################################
# The ``dots`` reference image shows spots are approximately 10 pixels in diameter and can be
# tightly packed together. This helped inform the parameter settings of the spot finders below.
# However, the accuracy can always be improved by further tuning parameters. For example,
# if low intensity background noise is being detected as spots, increasing values for
# ``threshold``, ``stringency``, ``min_mass``, and ``percentile`` can remove them. If large spots
# are not missed, increasing values such as ``max_sigma``, ``max_obj_area``, ``spot_diameter``,
# and ``max_size`` could include them. Moreover, signal enhancement and background reduction
# prior to this step can also improve accuracy of spot finding.

bd = FindSpots.BlobDetector(
    min_sigma=2,
    max_sigma=6,
    num_sigma=20,
    threshold=0.1,
    is_volume=True,
    measurement_type='mean',
)

lmp = FindSpots.LocalMaxPeakFinder(min_distance=2,
                                   stringency=8,
                                   min_obj_area=6,
                                   max_obj_area=600,
                                   is_volume=True)

tlmpf = FindSpots.TrackpyLocalMaxPeakFinder(
    spot_diameter=11,
    min_mass=0.2,
    max_size=8,
    separation=3,
Ejemplo n.º 7
0
# Finally, a local blob detector that finds spots in each (z, y, x) volume separately is applied.
# The user selects an "anchor round" and spots found in all channels of that round are used to
# seed a local search across other rounds and channels. The closest spot is selected,
# and any spots outside the search radius (here 10 pixels) is discarded.
#
# The Spot finder returns an IntensityTable containing all spots from round zero. Note that many
# of the spots do not identify spots in other rounds and channels and will therefore fail
# decoding. Because of the stringency built into the STARmap codebook, it is OK to be relatively
# permissive with the spot finding parameters for this assay.

import numpy as np
from starfish.spots import FindSpots

bd = FindSpots.BlobDetector(min_sigma=1,
                            max_sigma=8,
                            num_sigma=10,
                            threshold=np.percentile(
                                np.ravel(stack.xarray.values), 95),
                            exclude_border=2)

spots = bd.run(scaled)

###################################################################################################
# Decode spots
# ------------
# Next, spots are decoded. There is really no good way to display 3-d spot detection in 2-d planes,
# so we encourage you to grab this notebook and uncomment the below lines.

from starfish.spots import DecodeSpots
from starfish.types import TraceBuildingStrategies

decoder = DecodeSpots.PerRoundMaxChannel(
Ejemplo n.º 8
0
def process_fov(field_num: int, experiment_str: str):
    """Process a single field of view of ISS data
    Parameters
    ----------
    field_num : int
        the field of view to process
    experiment_str : int
        path of experiment json file

    Returns
    -------
    DecodedSpots :
        tabular object containing the locations of detected spots.
    """

    fov_str: str = f"fov_{int(field_num):03d}"

    # load experiment
    experiment = starfish.Experiment.from_json(experiment_str)

    print(f"loading fov: {fov_str}")
    fov = experiment[fov_str]

    # note the structure of the 5D tensor containing the raw imaging data
    imgs = fov.get_image(FieldOfView.PRIMARY_IMAGES)
    dots = fov.get_image("dots")
    nuclei = fov.get_image("nuclei")

    print("Learning Transform")
    learn_translation = LearnTransform.Translation(reference_stack=dots,
                                                   axes=Axes.ROUND,
                                                   upsampling=1000)
    transforms_list = learn_translation.run(
        imgs.reduce({Axes.CH, Axes.ZPLANE}, func="max"))

    print("Applying transform")
    warp = ApplyTransform.Warp()
    registered_imgs = warp.run(imgs,
                               transforms_list=transforms_list,
                               in_place=True,
                               verbose=True)

    print("Filter WhiteTophat")
    filt = Filter.WhiteTophat(masking_radius=15, is_volume=False)

    filtered_imgs = filt.run(registered_imgs, verbose=True, in_place=True)
    filt.run(dots, verbose=True, in_place=True)
    filt.run(nuclei, verbose=True, in_place=True)

    print("Detecting")
    detector = FindSpots.BlobDetector(
        min_sigma=1,
        max_sigma=10,
        num_sigma=30,
        threshold=0.01,
        measurement_type='mean',
    )
    dots_max_projector = Filter.Reduce((Axes.ROUND, Axes.ZPLANE),
                                       func=FunctionSource.np("max"))
    dots_max = dots_max_projector.run(dots)

    spots = detector.run(image_stack=filtered_imgs, reference_image=dots_max)

    decoder = DecodeSpots.PerRoundMaxChannel(codebook=experiment.codebook)
    decoded = decoder.run(spots=spots)
    df = decoded.to_decoded_dataframe()
    return df