Skip to content

Commit

Permalink
test subsampling at sc merge
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaybio committed Jan 7, 2021
1 parent c3d5e6b commit b5ba767
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pycytominer/tests/test_cyto_utils/test_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,52 @@ def test_merge_single_cells():
)


def test_merge_single_cells_subsample():

for subsample_frac in [0.1, 0.5, 0.9]:
ap_subsample = SingleCells(file_or_conn=file, subsample_frac=subsample_frac)

sc_merged_df = ap_subsample.merge_single_cells(
sc_output_file="none",
compute_subsample=True,
compression_options=None,
float_format=None,
single_cell_normalize=True,
normalize_args=None,
)

# Assert that the image data was merged
assert all(
x in sc_merged_df.columns for x in ["Metadata_Plate", "Metadata_Well"]
)

# Assert that metadata columns were renamed appropriately
for x in ap_subsample.full_merge_suffix_rename:
assert ap_subsample.full_merge_suffix_rename[x] == "Metadata_{x}".format(
x=x
)

# Assert that the subsample fraction worked
assert sc_merged_df.shape[0] == cells_df.shape[0] * subsample_frac

for subsample_n in [2, 5, 10]:
ap_subsample = SingleCells(file_or_conn=file, subsample_n=subsample_n)

sc_merged_df = ap_subsample.merge_single_cells(
sc_output_file="none",
compute_subsample=True,
compression_options=None,
float_format=None,
single_cell_normalize=True,
normalize_args=None,
)

# Assert that the number of each strata should be even
assert subsample_n == int(
sc_merged_df.loc[:, ap_subsample.strata].value_counts().values.mean()
)


def test_aggregate_comparment():
df = image_df.merge(cells_df, how="inner", on=["TableNumber", "ImageNumber"])
result = aggregate(df)
Expand Down

0 comments on commit b5ba767

Please sign in to comment.