Skip to content

Commit

Permalink
Various Small Fixes/Improvements (#1985)
Browse files Browse the repository at this point in the history
* Initial commit

* Updated comments

* Changed filter_tally to rounds_used in decoded_intensity_table

* Fixed validation errors

* added tests for checkAll decoder

* Fixed imports order

* include test updates

* annotation fixes and speed improvements

* added ray to requirements

* More speed and memory improvements

* Replaced ray w/ multiprocessing

* Fix import order

* few more fixes

* Changed test to account for randomness

* fix test

* Added new filter step

* Added input error checking and condition for empty results

* Fixed channel bug

* March 30 2022 big update

* Updated comments

* Updated comments and fixed mypy errors

* Swapped ray multiprocessing w/ standard Python

* fixed function arg bug

* mypy fix

* bug fixes

* fix

* Added sphinx update to reqs

* fixed error correction bug

* reqs fix

* Added better error catching

* Added error catch for no decoded targets

* fix

* Added spot saving/loading

* Replaced old seqfish notebook

* Added ability to read in 3d external label image as mask

* Modified BlobDetector to work when is_volume=False

* Speed improvements

* fix for windows test

* retrigger checks

* retrigger checks
  • Loading branch information
nickeener authored Sep 6, 2022
1 parent c8327a8 commit 853f56c
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 392 deletions.
389 changes: 160 additions & 229 deletions notebooks/SeqFISH.ipynb

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions starfish/core/morphology/binary_mask/binary_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,28 @@ def from_external_labeled_image(cls, path_to_labeled_image: Union[str, Path],
# Load the label image generated from another program
label_image = io.imread(path_to_labeled_image)

# Get the physical ticks from the original dapi image
physical_ticks = {Coordinates.Y: original_image.xarray.yc.values,
Coordinates.X: original_image.xarray.xc.values}
# Fixes dimension order. Tiff files saved with skimage.io.imsave and tifffile.imsave will
# have different dimension order when read in.
if len(label_image.shape) == 3 and label_image.shape[0] > label_image.shape[-1]:
label_image = np.transpose(label_image, [2, 0, 1])

if len(label_image.shape) == 3:
# Get the physical ticks from the original dapi image
physical_ticks = {Coordinates.Y: original_image.xarray.yc.values,
Coordinates.X: original_image.xarray.xc.values,
Coordinates.Z: original_image.xarray.zc.values}

# Get the pixel values from the original dapi image
pixel_coords = {Axes.Y: original_image.xarray.y.values,
Axes.X: original_image.xarray.x.values,
Axes.ZPLANE: original_image.xarray.z.values}
else:
physical_ticks = {Coordinates.Y: original_image.xarray.yc.values,
Coordinates.X: original_image.xarray.xc.values}

# Get the pixel values from the original dapi image
pixel_coords = {Axes.Y: original_image.xarray.y.values,
Axes.X: original_image.xarray.x.values}
# Get the pixel values from the original dapi image
pixel_coords = {Axes.Y: original_image.xarray.y.values,
Axes.X: original_image.xarray.x.values}

# Create the label image
label_im = LabelImage.from_label_array_and_ticks(
Expand Down
66 changes: 40 additions & 26 deletions starfish/core/spots/DecodeSpots/check_all_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ def run(self,
# Adds spot_codes column to roundData

roundData = buildBarcodes(roundData, neighborDict,
currentRoundOmitNum, channelDict,
strictness, r, numJobs)
currentRoundOmitNum, strictness, r,
numJobs)

# When strictness is positive the filter-first methods is used
# and distanceFilter is run first on all the potential barcodes
Expand Down Expand Up @@ -400,7 +400,12 @@ def run(self,
# create empty IntensityTable filled with np.nan
data = np.full((len(allCodes), len(channels), len(rounds)), fill_value=np.nan)
dims = (Features.AXIS, Axes.CH.value, Axes.ROUND.value)
centers = allCodes['center']

if len(allCodes) == 0:
centers = []
else:
centers = allCodes['center']

coords: Mapping[Hashable, Tuple[str, Any]] = {
Features.SPOT_RADIUS: (Features.AXIS, np.full(len(allCodes), 1)),
Axes.ZPLANE.value: (Features.AXIS, np.asarray([round(c[0]) for c in centers])),
Expand All @@ -413,28 +418,37 @@ def run(self,
}
int_table = IntensityTable(data=data, dims=dims, coords=coords)

# Fill in data values
table_codes = []
for i in range(len(allCodes)):
code = []
# ints = allCodes.loc[i, 'intensities']
for j, ch in enumerate(allCodes.loc[i, 'best_barcodes']):
# If a round is not used, row will be all zeros
code.append(np.asarray([0 if k != ch - 1 else 1 for k in range(len(channels))]))
table_codes.append(np.asarray(code).T)
int_table.values = np.asarray(table_codes)
int_table = transfer_physical_coords_to_intensity_table(intensity_table=int_table,
spots=spots)

# Validate results are correct shape
self.codebook._validate_decode_intensity_input_matches_codebook_shape(int_table)

# Create DecodedIntensityTable
result = DecodedIntensityTable.from_intensity_table(
int_table,
targets=(Features.AXIS, allCodes['targets'].astype('U')),
distances=(Features.AXIS, allCodes["distance"]),
passes_threshold=(Features.AXIS, np.full(len(allCodes), True)),
rounds_used=(Features.AXIS, allCodes['rounds_used']))
# If no targets found returns empty DecodedIntensityTable
if len(allCodes) > 0:
# Fill in data values
table_codes = []
for i in range(len(allCodes)):
code = []
# ints = allCodes.loc[i, 'intensities']
for j, ch in enumerate(allCodes.loc[i, 'best_barcodes']):
# If a round is not used, row will be all zeros
code.append(np.asarray([0 if k != ch - 1 else 1 for k in range(len(channels))]))
table_codes.append(np.asarray(code).T)
int_table.values = np.asarray(table_codes)
int_table = transfer_physical_coords_to_intensity_table(intensity_table=int_table,
spots=spots)

# Validate results are correct shape
self.codebook._validate_decode_intensity_input_matches_codebook_shape(int_table)

# Create DecodedIntensityTable
result = DecodedIntensityTable.from_intensity_table(
int_table,
targets=(Features.AXIS, allCodes['targets'].astype('U')),
distances=(Features.AXIS, allCodes["distance"]),
passes_threshold=(Features.AXIS, np.full(len(allCodes), True)),
rounds_used=(Features.AXIS, allCodes['rounds_used']))
else:
result = DecodedIntensityTable.from_intensity_table(
int_table,
targets=(Features.AXIS, np.array([])),
distances=(Features.AXIS, np.array([])),
passes_threshold=(Features.AXIS, np.array([])),
rounds_used=(Features.AXIS, np.array([])))

return result
Loading

0 comments on commit 853f56c

Please sign in to comment.