-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.py
More file actions
55 lines (44 loc) · 1.14 KB
/
script.py
File metadata and controls
55 lines (44 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import warnings
warnings.filterwarnings('ignore')
import anndata as ad
import numpy as np
import pandas as pd
# VIASH START
par = {
'input_data': 'resources_test/task_spatially_variable_genes/mouse_brain_coronal/dataset.h5ad',
'output': 'output.h5ad'
}
meta = {
'name': 'scbsp'
}
# VIASH END
print('Load data', flush=True)
adata = ad.read_h5ad(par['input_data'])
print('Run scBSP', flush=True)
from scbsp import granp
coords = adata.obsm['spatial']
X = adata.layers['counts']
if hasattr(X, 'toarray'):
X_dense = X.toarray()
else:
X_dense = np.asarray(X)
result_df = granp(
np.ascontiguousarray(coords, dtype=np.float64),
np.ascontiguousarray(X_dense, dtype=np.float64),
)
# granp returns DataFrame with columns: gene_names, p_values
pvals = result_df['p_values'].values
scores = -np.log10(np.clip(pvals, 1e-300, 1))
df = pd.DataFrame({
'feature_id': list(adata.var_names),
'pred_spatial_var_score': scores
})
output = ad.AnnData(
var=df,
uns={
'dataset_id': adata.uns['dataset_id'],
'method_id': meta['name']
}
)
print('Write output to file', flush=True)
output.write_h5ad(par['output'])