annotate anndata_to_csv.py @ 2:ef73596d678a draft default tip

planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit c39cea5ae2ebf61b3d51d687fd9d2930c907b72d
author goeckslab
date Tue, 30 Jul 2024 18:20:43 +0000
parents 834ee9481948
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
1 import argparse
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
2 import json
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
3 import warnings
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
4
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
5 import scimap as sm
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
6 from anndata import read_h5ad
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
7
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
8
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
9 def main(inputs, outfile):
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
10 """
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
11 Parameters
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
12 ---------
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
13 inputs : str
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
14 File path to galaxy tool parameter.
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
15 anndata : str
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
16 File path to anndata.
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
17 output : str
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
18 File path to output.
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
19 """
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
20 warnings.simplefilter('ignore')
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
21
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
22 with open(inputs, 'r') as param_handler:
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
23 params = json.load(param_handler)
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
24
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
25 adata = read_h5ad(params['anndata'])
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
26
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
27 if params['layer'] == 'x':
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
28 params['layer'] = None
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
29
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
30 df = sm.hl.scimap_to_csv(
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
31 adata=adata,
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
32 layer=params['layer'],
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
33 CellID=params['cellid'],
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
34 )
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
35
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
36 df.to_csv(outfile, index=False)
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
37
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
38
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
39 if __name__ == '__main__':
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
40 aparser = argparse.ArgumentParser()
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
41 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
42 aparser.add_argument("-e", "--outfile", dest="outfile", required=True)
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
43 args = aparser.parse_args()
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
44
834ee9481948 planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
goeckslab
parents:
diff changeset
45 main(args.inputs, args.outfile)