Mercurial > repos > goeckslab > scimap_anndata_to_csv
comparison scimap_phenotyping.py @ 0:199b5f278356 draft
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit 9fb5578191db8a559191e45156cfb95350f01aea
author | goeckslab |
---|---|
date | Mon, 10 Jun 2024 18:44:49 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:199b5f278356 |
---|---|
1 import argparse | |
2 import warnings | |
3 | |
4 import pandas as pd | |
5 import scimap as sm | |
6 from anndata import read_h5ad | |
7 | |
8 | |
9 def main( | |
10 adata, | |
11 output, | |
12 log, | |
13 gating_workflow, | |
14 gating_workflow_ext, | |
15 manual_gates=None, | |
16 manual_gates_ext=None, | |
17 random_state=0 | |
18 ): | |
19 """ | |
20 Parameter | |
21 --------- | |
22 adata : str | |
23 File path to the input AnnData. | |
24 output : str | |
25 File path to the output AnnData. | |
26 log: bool | |
27 Boolean whether to log the input data prior to rescaling | |
28 gating_workflow : str | |
29 File path to the gating workflow. | |
30 gating_workflow_ext : str | |
31 Datatype for gating workflow, either 'csv' or 'tabular'. | |
32 manual_gates : str | |
33 File path to the munual gating. | |
34 manual_gates_ext : str | |
35 Datatype for munual gate, either 'csv' or 'tabular'. | |
36 random_state: int | |
37 The seed used by the random number generator for GMM in sm.pp.rescale | |
38 """ | |
39 warnings.simplefilter('ignore') | |
40 | |
41 adata = read_h5ad(adata) | |
42 # Rescale data | |
43 if manual_gates: | |
44 sep = ',' if manual_gates_ext == 'csv' else '\t' | |
45 manual_gates = pd.read_csv(manual_gates, sep=sep) | |
46 | |
47 adata = sm.pp.rescale( | |
48 adata, | |
49 gate=manual_gates, | |
50 log=log, | |
51 random_state=random_state | |
52 ) | |
53 | |
54 # Phenotype cells | |
55 # Load the gating workflow | |
56 sep = ',' if gating_workflow_ext == 'csv' else '\t' | |
57 phenotype = pd.read_csv(gating_workflow, sep=sep) | |
58 adata = sm.tl.phenotype_cells( | |
59 adata, | |
60 phenotype=phenotype, | |
61 label="phenotype" | |
62 ) | |
63 | |
64 # Summary of the phenotyping | |
65 print(adata.obs['phenotype'].value_counts()) | |
66 | |
67 adata.write(output) | |
68 | |
69 | |
70 if __name__ == '__main__': | |
71 aparser = argparse.ArgumentParser() | |
72 aparser.add_argument("-a", "--adata", dest="adata", required=True) | |
73 aparser.add_argument("-o", "--output", dest="output", required=True) | |
74 aparser.add_argument("-l", "--log", dest="log", action="store_true") | |
75 aparser.add_argument( | |
76 "-g", | |
77 "--gating_workflow", | |
78 dest="gating_workflow", | |
79 required=True | |
80 ) | |
81 aparser.add_argument( | |
82 "-s", | |
83 "--gating_workflow_ext", | |
84 dest="gating_workflow_ext", | |
85 required=True | |
86 ) | |
87 aparser.add_argument( | |
88 "-m", | |
89 "--manual_gates", | |
90 dest="manual_gates", | |
91 required=False | |
92 ) | |
93 aparser.add_argument( | |
94 "-S", | |
95 "--manual_gates_ext", | |
96 dest="manual_gates_ext", | |
97 required=False | |
98 ) | |
99 aparser.add_argument( | |
100 "--random_state", | |
101 dest="random_state", | |
102 type=int, | |
103 required=False | |
104 ) | |
105 | |
106 args = aparser.parse_args() | |
107 | |
108 if args.log: | |
109 print("\n adata.raw.X will be log1p transformed \n") | |
110 | |
111 main( | |
112 adata=args.adata, | |
113 output=args.output, | |
114 log=args.log, | |
115 gating_workflow=args.gating_workflow, | |
116 gating_workflow_ext=args.gating_workflow_ext, | |
117 manual_gates=args.manual_gates, | |
118 manual_gates_ext=args.manual_gates_ext, | |
119 random_state=args.random_state | |
120 ) |