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

[easy] - fixing all expression matrix saves #1413

Merged
merged 9 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 30 additions & 0 deletions starfish/core/expression_matrix/test/test_serialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random

from starfish import IntensityTable
from starfish.core.codebook.test.factories import codebook_array_factory
from starfish.core.types import Features

NUMBER_SPOTS = 10


def test_save_expression_matrix():

codebook = codebook_array_factory()

intensities = IntensityTable.synthetic_intensities(
codebook,
num_z=3,
height=100,
width=100,
n_spots=10
)
# mock out come cell_ids
cell_ids = random.sample(range(1, 20), NUMBER_SPOTS)
intensities[Features.CELL_ID] = (Features.AXIS, cell_ids)

expression_matrix = intensities.to_expression_matrix()

# test all saving methods
expression_matrix.save_anndata("expression.h5")
expression_matrix.save_loom("expression")
expression_matrix.save("expression")
5 changes: 3 additions & 2 deletions starfish/core/intensity_table/intensity_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,11 @@ def to_expression_matrix(self) -> ExpressionMatrix:
counts = grouped.count().iloc[:, 0].unstack().fillna(0)
if self.has_physical_coords:
grouped = self.to_features_dataframe().groupby([Features.CELL_ID])[[
Axes.X, Axes.Y, Axes.ZPLANE, Coordinates.X, Coordinates.Y, Coordinates.Z]]
Axes.X.value, Axes.Y.value, Axes.ZPLANE.value, Coordinates.X.value,
Coordinates.Y.value, Coordinates.Z.value]]
else:
grouped = self.to_features_dataframe().groupby([Features.CELL_ID])[[
Axes.X, Axes.Y, Axes.ZPLANE]]
Axes.X.value, Axes.Y.value, Axes.ZPLANE.value]]
min_ = grouped.min()
max_ = grouped.max()
coordinate_df = min_ + (max_ - min_) / 2
Expand Down