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

Creating a standard starfish.wdl that can be run with any recipe file #1364

Merged
merged 7 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 0 additions & 178 deletions wdl/starfish.wdl

This file was deleted.

13 changes: 0 additions & 13 deletions wdl/starfish_example_inputs.json

This file was deleted.

5 changes: 5 additions & 0 deletions workflows/wdl/iss_published/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Starfish.experiment": "https://d2nhj9g34unfro.cloudfront.net/browse/formatted/iss/20190506/experiment.json",
"Starfish.num_fovs": 15,
"Starfish.recipe_file": "https://raw.githubusercontent.com/spacetx/starfish/master/workflows/wdl/iss_published/recipe.py"
}
66 changes: 66 additions & 0 deletions workflows/wdl/iss_published/recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import starfish
from starfish import FieldOfView
from starfish.image import Filter
from starfish.image import ApplyTransform, LearnTransform
from starfish.spots import DetectSpots
from starfish.types import Axes


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")

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

Choose a reason for hiding this comment

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

I'd just do:

Suggested change
filt = Filter.WhiteTophat(masking_radius, is_volume=False)
filt = Filter.WhiteTophat(masking_radius=15, is_volume=False)


filtered_imgs = filt.run(imgs, verbose=True, in_place=False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider moving the registration to before filtering so you can do inplace processing.

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

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

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

print("Detecting")
p = DetectSpots.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
p = DetectSpots.BlobDetector(
detector = DetectSpots.BlobDetector(

min_sigma=1,
max_sigma=10,
num_sigma=30,
threshold=0.01,
measurement_type='mean',
)

intensities = p.run(registered_imgs, blobs_image=dots, blobs_axes=(Axes.ROUND, Axes.ZPLANE))

decoded = experiment.codebook.decode_per_round_max(intensities)
df = decoded.to_decoded_spots()
return df
Copy link
Collaborator

Choose a reason for hiding this comment

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

add nl.

5 changes: 5 additions & 0 deletions workflows/wdl/iss_published/test_inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Starfish.experiment": "https://d2nhj9g34unfro.cloudfront.net/browse/formatted/iss/20190506/experiment.json",
"Starfish.num_fovs": 2,
"Starfish.recipe_file": "https://raw.githubusercontent.com/spacetx/starfish/master/workflows/wdl/iss_published/recipe.py"
}
5 changes: 5 additions & 0 deletions workflows/wdl/iss_spaceTX/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Starfish.experiment": "https://d2nhj9g34unfro.cloudfront.net/xiaoyan_qian/ISS_human_HCA_07_MultiFOV/main_files/experiment.json",
"Starfish.num_fovs": 539,
"Starfish.recipe_file": "https://raw.githubusercontent.com/spacetx/starfish/master/workflows/wdl/iss_spaceTX/recipe.py"
}
55 changes: 55 additions & 0 deletions workflows/wdl/iss_spaceTX/recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import numpy as np
import starfish
from starfish.types import Axes


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)

fov = experiment[fov_str]
imgs = fov.get_image(starfish.FieldOfView.PRIMARY_IMAGES)
dots = imgs.max_proj(Axes.CH)

# filter
filt = starfish.image.Filter.WhiteTophat(masking_radius=15, is_volume=False)
filtered_imgs = filt.run(imgs, verbose=True, in_place=False)
filt.run(dots, verbose=True, in_place=True)

# find threshold
tmp = dots.sel({Axes.ROUND:0, Axes.CH:0, Axes.ZPLANE:0})
dots_threshold = np.percentile(np.ravel(tmp.xarray.values), 50)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is incompatible with the pipeline architecture. do we have an issue for fixing this?


# find spots
p = starfish.spots.DetectSpots.BlobDetector(
min_sigma=1,
max_sigma=10,
num_sigma=30,
threshold=dots_threshold,
measurement_type='mean',
)

# blobs = dots; define the spots in the dots image, but then find them again in the stack.
intensities = p.run(filtered_imgs, blobs_image=dots, blobs_axes=(Axes.ROUND, Axes.ZPLANE))

# decode
decoded = experiment.codebook.decode_per_round_max(intensities)

# save results
df = decoded.to_decoded_spots()
return df
5 changes: 5 additions & 0 deletions workflows/wdl/iss_spaceTX/test_inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Starfish.experiment": "https://d2nhj9g34unfro.cloudfront.net/xiaoyan_qian/ISS_human_HCA_07_MultiFOV/main_files/experiment.json",
"Starfish.num_fovs": 2,
"Starfish.recipe_file": "https://raw.githubusercontent.com/spacetx/starfish/master/workflows/wdl/iss_spaceTX/recipe.py"
}
5 changes: 5 additions & 0 deletions workflows/wdl/merfish_published/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Starfish.experiment": "https://d2nhj9g34unfro.cloudfront.net/browse/formatted/MERFISH/20190511/experiment.json",
"Starfish.num_fovs": 495,
"Starfish.recipe_file": "https://raw.githubusercontent.com/spacetx/starfish/saxelrod-standard-wdl/workflows/wdl/merfish_published/recipe.py"
}
Loading