annotate scimap_spatial.py @ 0:42e6c251bfd0 draft

planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
author goeckslab
date Tue, 19 Jul 2022 20:30:34 +0000
parents
children fd38e533a54b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
1 import argparse
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
2 import json
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
3 import warnings
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
4
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
5 import scimap as sm
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
6 from anndata import read_h5ad
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
7
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
8
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
9 def main(inputs, anndata, output):
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
10 """
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
11 Parameter
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
12 ---------
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
13 inputs : str
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
14 File path to galaxy tool parameter.
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
15 anndata : str
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
16 File path to anndata containing phenotyping info.
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
17 output : str
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
18 File path to output.
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
19 """
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
20 warnings.simplefilter('ignore')
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
21
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
22 with open(inputs, 'r') as param_handler:
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
23 params = json.load(param_handler)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
24
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
25 adata = read_h5ad(anndata)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
26
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
27 tool = params['analyses']['selected_tool']
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
28 tool_func = getattr(sm.tl, tool)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
29
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
30 options = params['analyses']['options']
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
31 if tool == 'cluster':
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
32 options['method'] = params['analyses']['method']
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
33 subset_genes = options.pop('subset_genes')
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
34 if subset_genes:
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
35 options['subset_genes'] = \
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
36 [x.strip() for x in subset_genes.split(',')]
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
37 sub_cluster_group = options.pop('sub_cluster_group')
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
38 if sub_cluster_group:
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
39 options['sub_cluster_group'] = \
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
40 [x.strip() for x in sub_cluster_group.split(',')]
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
41
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
42 for k, v in options.items():
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
43 if v == '':
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
44 options[k] = None
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
45
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
46 tool_func(adata, **options)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
47
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
48 adata.write(output)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
49
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
50
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
51 if __name__ == '__main__':
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
52 aparser = argparse.ArgumentParser()
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
53 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
54 aparser.add_argument("-e", "--output", dest="output", required=True)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
55 aparser.add_argument("-a", "--anndata", dest="anndata", required=True)
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
56
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
57 args = aparser.parse_args()
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
58
42e6c251bfd0 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit b19cb55dfb751cccc857b95a432890299bfeebb5
goeckslab
parents:
diff changeset
59 main(args.inputs, args.anndata, args.output)