Skip to content

Commit

Permalink
rework infer_truth
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Sep 19, 2024
1 parent dec59ad commit 49c9cf4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/data_processors/infer_truth/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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',
Expand All @@ -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']]
Expand Down

0 comments on commit 49c9cf4

Please sign in to comment.