Mercurial > repos > goeckslab > scimap_spatial
comparison scimap_phenotyping.py @ 2:d19c068c2490 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:35 +0000 |
parents | 42e6c251bfd0 |
children |
comparison
equal
deleted
inserted
replaced
1:fd38e533a54b | 2:d19c068c2490 |
---|---|
7 | 7 |
8 | 8 |
9 def main( | 9 def main( |
10 adata, | 10 adata, |
11 output, | 11 output, |
12 log, | |
12 gating_workflow, | 13 gating_workflow, |
13 gating_workflow_ext, | 14 gating_workflow_ext, |
14 manual_gates=None, | 15 manual_gates=None, |
15 manual_gates_ext=None, | 16 manual_gates_ext=None, |
16 rescale_plots=False | 17 random_state=0 |
17 ): | 18 ): |
18 """ | 19 """ |
19 Parameter | 20 Parameter |
20 --------- | 21 --------- |
21 adata : str | 22 adata : str |
22 File path to the input AnnData. | 23 File path to the input AnnData. |
23 output : str | 24 output : str |
24 File path to the output AnnData. | 25 File path to the output AnnData. |
26 log: bool | |
27 Boolean whether to log the input data prior to rescaling | |
25 gating_workflow : str | 28 gating_workflow : str |
26 File path to the gating workflow. | 29 File path to the gating workflow. |
27 gating_workflow_ext : str | 30 gating_workflow_ext : str |
28 Datatype for gating workflow, either 'csv' or 'tabular'. | 31 Datatype for gating workflow, either 'csv' or 'tabular'. |
29 manual_gates : str | 32 manual_gates : str |
30 File path to the munual gating. | 33 File path to the munual gating. |
31 manual_gates_ext : str | 34 manual_gates_ext : str |
32 Datatype for munual gate, either 'csv' or 'tabular'. | 35 Datatype for munual gate, either 'csv' or 'tabular'. |
33 rescale_plots : boolean | 36 random_state: int |
34 Save plots from rescaling. | 37 The seed used by the random number generator for GMM in sm.pp.rescale |
35 """ | 38 """ |
36 warnings.simplefilter('ignore') | 39 warnings.simplefilter('ignore') |
37 | 40 |
38 adata = read_h5ad(adata) | 41 adata = read_h5ad(adata) |
39 # Rescale data | 42 # Rescale data |
40 if manual_gates: | 43 if manual_gates: |
41 sep = ',' if manual_gates_ext == 'csv' else '\t' | 44 sep = ',' if manual_gates_ext == 'csv' else '\t' |
42 manual_gates = pd.read_csv(manual_gates, sep=sep) | 45 manual_gates = pd.read_csv(manual_gates, sep=sep) |
43 | 46 |
44 adata = sm.pp.rescale(adata, gate=manual_gates, save_fig=rescale_plots) | 47 adata = sm.pp.rescale( |
48 adata, | |
49 gate=manual_gates, | |
50 log=log, | |
51 random_state=random_state | |
52 ) | |
45 | 53 |
46 # Phenotype cells | 54 # Phenotype cells |
47 # Load the gating workflow | 55 # Load the gating workflow |
48 sep = ',' if gating_workflow_ext == 'csv' else '\t' | 56 sep = ',' if gating_workflow_ext == 'csv' else '\t' |
49 phenotype = pd.read_csv(gating_workflow, sep=sep) | 57 phenotype = pd.read_csv(gating_workflow, sep=sep) |
50 adata = sm.tl.phenotype_cells(adata, phenotype=phenotype, label="phenotype") | 58 adata = sm.tl.phenotype_cells( |
59 adata, | |
60 phenotype=phenotype, | |
61 label="phenotype" | |
62 ) | |
51 | 63 |
52 # Summary of the phenotyping | 64 # Summary of the phenotyping |
53 print(adata.obs['phenotype'].value_counts()) | 65 print(adata.obs['phenotype'].value_counts()) |
54 | 66 |
55 adata.write(output) | 67 adata.write(output) |
57 | 69 |
58 if __name__ == '__main__': | 70 if __name__ == '__main__': |
59 aparser = argparse.ArgumentParser() | 71 aparser = argparse.ArgumentParser() |
60 aparser.add_argument("-a", "--adata", dest="adata", required=True) | 72 aparser.add_argument("-a", "--adata", dest="adata", required=True) |
61 aparser.add_argument("-o", "--output", dest="output", required=True) | 73 aparser.add_argument("-o", "--output", dest="output", required=True) |
62 aparser.add_argument("-g", "--gating_workflow", dest="gating_workflow", required=True) | 74 aparser.add_argument("-l", "--log", dest="log", action="store_true") |
63 aparser.add_argument("-s", "--gating_workflow_ext", dest="gating_workflow_ext", required=True) | 75 aparser.add_argument( |
64 aparser.add_argument("-m", "--manual_gates", dest="manual_gates", required=False) | 76 "-g", |
65 aparser.add_argument("-S", "--manual_gates_ext", dest="manual_gates_ext", required=False) | 77 "--gating_workflow", |
66 aparser.add_argument("-p", "--rescale_plots", dest="rescale_plots", action="store_true", | 78 dest="gating_workflow", |
67 default=False, required=False) | 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 ) | |
68 | 105 |
69 args = aparser.parse_args() | 106 args = aparser.parse_args() |
70 | 107 |
71 main(args.adata, args.output, args.gating_workflow, | 108 if args.log: |
72 args.gating_workflow_ext, args.manual_gates, | 109 print("\n adata.raw.X will be log1p transformed \n") |
73 args.manual_gates_ext, args.rescale_plots) | 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 ) |