Mercurial > repos > goeckslab > rename_tiff_channels
comparison scale_cell_coordinates.py @ 5:61fd94c7ce42 draft
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/mti-utils commit bc438db690e41823909b32b693f297d942433a43
author | goeckslab |
---|---|
date | Thu, 11 Jul 2024 22:41:10 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:55bc102d7709 | 5:61fd94c7ce42 |
---|---|
1 import argparse | |
2 import json | |
3 import warnings | |
4 | |
5 import anndata as ad | |
6 | |
7 | |
8 def main(inputs, output): | |
9 | |
10 """ | |
11 inputs : str | |
12 File path to galaxy tool JSON inputs config file | |
13 output: str | |
14 File path to save the output h5ad file | |
15 """ | |
16 warnings.simplefilter('ignore') | |
17 | |
18 # read inputs JSON | |
19 with open(inputs, 'r') as param_handler: | |
20 params = json.load(param_handler) | |
21 | |
22 # read input anndata file | |
23 adata = ad.read_h5ad(params['anndata']) | |
24 | |
25 # scale coords | |
26 unit = params['unit'] | |
27 new_col_names = [] | |
28 for c in [params['x_coord'], params['y_coord']]: | |
29 scaled_col_name = f'{c}_{unit}' | |
30 adata.obs[scaled_col_name] = adata.obs[c] * params['resolution'] | |
31 new_col_names.append(scaled_col_name) | |
32 | |
33 # overwrite adata.obsm['spatial'] with scaled coordinates | |
34 adata.obsm['spatial'] = adata.obs[scaled_col_name].values | |
35 | |
36 # write out anndata to h5ad file | |
37 adata.write_h5ad(output) | |
38 | |
39 | |
40 if __name__ == '__main__': | |
41 | |
42 aparser = argparse.ArgumentParser() | |
43 aparser.add_argument( | |
44 "-i", "--inputs", dest="inputs", required=True) | |
45 aparser.add_argument( | |
46 "-o", "--output", dest="output", required=False) | |
47 | |
48 args = aparser.parse_args() | |
49 | |
50 main(args.inputs, args.output) |