def test_SingleCells_init(): """ Testing initialization of SingleCells """ assert ap.file_or_conn == file assert ap.strata == ["Metadata_Plate", "Metadata_Well"] assert ap.merge_cols == ["TableNumber", "ImageNumber"] assert ap.image_cols == ["TableNumber", "ImageNumber", "Metadata_Site"] pd.testing.assert_frame_equal(image_df.sort_index(axis=1), ap.image_df.sort_index(axis=1)) assert ap.subsample_frac == 1 assert ap_subsample.subsample_frac == 1 assert ap.subsample_n == "all" assert ap_subsample.subsample_n == 2 assert ap.subset_data_df == "none" assert ap.output_file == "none" assert ap.aggregation_operation == "median" assert not ap.is_aggregated assert ap.subsampling_random_state == "none" assert ap_subsample.subsampling_random_state == 123 assert ap.fields_of_view == "all" assert ap.fields_of_view_feature == "Metadata_Site" assert ap.object_feature == "Metadata_ObjectNumber" assert ap.compartment_linking_cols == get_default_linking_cols() assert ap.compartments == get_default_compartments()
def create_linking_columns(noncanonical, noncanonical_compartments): linking_columns = get_default_linking_cols() if noncanonical: for comp in noncanonical_compartments: linking_columns[comp] = {"cytoplasm": "ObjectNumber"} linking_columns["cytoplasm"][ comp] = f"Cytoplasm_Parent_{comp.capitalize()}" # This will not work if the feature name uses CamelCase. return linking_columns
def test_provide_linking_cols_feature_name_update(): expected_result = { "Cytoplasm_Parent_Cells": "Metadata_Cytoplasm_Parent_Cells", "Cytoplasm_Parent_Nuclei": "Metadata_Cytoplasm_Parent_Nuclei", "ObjectNumber": "Metadata_ObjectNumber", } result = provide_linking_cols_feature_name_update() assert result == expected_result new_linking_cols = get_default_linking_cols() new_linking_cols["cytoplasm"]["new"] = "Cytoplasm_Parent_New" new_linking_cols["new"] = {"cytoplasm": "ObjectNumber"} result = provide_linking_cols_feature_name_update(new_linking_cols) expected_result = { "Cytoplasm_Parent_Cells": "Metadata_Cytoplasm_Parent_Cells", "Cytoplasm_Parent_Nuclei": "Metadata_Cytoplasm_Parent_Nuclei", "Cytoplasm_Parent_New": "Metadata_Cytoplasm_Parent_New", "ObjectNumber": "Metadata_ObjectNumber", } assert result == expected_result
new_cytoplasm_df.to_sql("cytoplasm", con=test_new_engine, index=False, if_exists="replace") nuclei_df.to_sql("nuclei", con=test_new_engine, index=False, if_exists="replace") new_compartment_df.to_sql("new", con=test_new_engine, index=False, if_exists="replace") new_compartments = ["cells", "cytoplasm", "nuclei", "new"] new_linking_cols = get_default_linking_cols() new_linking_cols["cytoplasm"]["new"] = "Cytoplasm_Parent_New" new_linking_cols["new"] = {"cytoplasm": "ObjectNumber"} # Setup SingleCells Class ap = SingleCells(file_or_conn=file, object_feature="Metadata_ObjectNumber") ap_subsample = SingleCells( file_or_conn=file, subsample_n=2, subsampling_random_state=123, object_feature="Metadata_ObjectNumber", ) ap_new = SingleCells( file_or_conn=new_file, load_image_data=False, compartments=new_compartments,
def test_default_linking_cols(): linking_cols = get_default_linking_cols() assert linking_cols == default_linking_cols