diff --git a/src/data_processors/infer_truth/script.py b/src/data_processors/infer_truth/script.py index 7a81fa3..e256765 100644 --- a/src/data_processors/infer_truth/script.py +++ b/src/data_processors/infer_truth/script.py @@ -3,7 +3,7 @@ ## VIASH START par = { - "input": "resources_test/task_cell_cell_communication/slidetags_human_brain/raw_spatial.h5ad", + "input": "resources_test/common/singlecell_broadinstitute_scp2167_human_brain/dataset.h5ad", "output": "output.h5ad" } meta = { @@ -17,32 +17,31 @@ # read the dataset adata = ad.read_h5ad(par["input"]) -adata.X = adata.layers["counts"] +adata.X = adata.layers["normalized"] adata.var.index = adata.var["feature_name"] -# Get needed params -groupby = 'cell_type' -organism = adata.uns['dataset_organism'] - # one hot encode cell types li.ut.spatial_neighbors(adata, bandwidth=1000, max_neighbours=10) -ctdata = onehot_groupby(adata, groupby=groupby) +# get organism organism = adata.uns['dataset_organism'] resource_name_map = { "homo_sapiens": "consensus", "mus_musculus": "mouseconsensus" } +resource_name = resource_name_map[organism] +# run LR lr = li.mt.bivariate(adata, global_name='morans', local_name=None, use_raw=False, - resource_name=resource_name_map[organism], + resource_name=resource_name, verbose=True, n_perms=1000) -# Infer Co-localized Cell types +# run CP +ctdata = onehot_groupby(adata, groupby='cell_type') interactions = non_mirrored_product(ctdata.var.index, ctdata.var.index) ct = li.mt.bivariate(ctdata, global_name='morans', @@ -61,6 +60,7 @@ # cross join assumed_truth = lr.assign(key=1).merge(ct.assign(key=1), on='key') + # simplify the dataframe assumed_truth['colocalized'] = assumed_truth['truth_y'] * assumed_truth['truth_x'] assumed_truth = assumed_truth[assumed_truth['colocalized']]