Mercurial > repos > goeckslab > scimap_phenotyping
comparison scimap_phenotyping.py @ 0:7ed4b55b11f7 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:29:22 +0000 |
parents | |
children | ce22e846c5e4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ed4b55b11f7 |
---|---|
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 gating_workflow, | |
13 gating_workflow_ext, | |
14 manual_gates=None, | |
15 manual_gates_ext=None, | |
16 rescale_plots=False | |
17 ): | |
18 """ | |
19 Parameter | |
20 --------- | |
21 adata : str | |
22 File path to the input AnnData. | |
23 output : str | |
24 File path to the output AnnData. | |
25 gating_workflow : str | |
26 File path to the gating workflow. | |
27 gating_workflow_ext : str | |
28 Datatype for gating workflow, either 'csv' or 'tabular'. | |
29 manual_gates : str | |
30 File path to the munual gating. | |
31 manual_gates_ext : str | |
32 Datatype for munual gate, either 'csv' or 'tabular'. | |
33 rescale_plots : boolean | |
34 Save plots from rescaling. | |
35 """ | |
36 warnings.simplefilter('ignore') | |
37 | |
38 adata = read_h5ad(adata) | |
39 # Rescale data | |
40 if manual_gates: | |
41 sep = ',' if manual_gates_ext == 'csv' else '\t' | |
42 manual_gates = pd.read_csv(manual_gates, sep=sep) | |
43 | |
44 adata = sm.pp.rescale(adata, gate=manual_gates, save_fig=rescale_plots) | |
45 | |
46 # Phenotype cells | |
47 # Load the gating workflow | |
48 sep = ',' if gating_workflow_ext == 'csv' else '\t' | |
49 phenotype = pd.read_csv(gating_workflow, sep=sep) | |
50 adata = sm.tl.phenotype_cells(adata, phenotype=phenotype, label="phenotype") | |
51 | |
52 # Summary of the phenotyping | |
53 print(adata.obs['phenotype'].value_counts()) | |
54 | |
55 adata.write(output) | |
56 | |
57 | |
58 if __name__ == '__main__': | |
59 aparser = argparse.ArgumentParser() | |
60 aparser.add_argument("-a", "--adata", dest="adata", required=True) | |
61 aparser.add_argument("-o", "--output", dest="output", required=True) | |
62 aparser.add_argument("-g", "--gating_workflow", dest="gating_workflow", required=True) | |
63 aparser.add_argument("-s", "--gating_workflow_ext", dest="gating_workflow_ext", required=True) | |
64 aparser.add_argument("-m", "--manual_gates", dest="manual_gates", required=False) | |
65 aparser.add_argument("-S", "--manual_gates_ext", dest="manual_gates_ext", required=False) | |
66 aparser.add_argument("-p", "--rescale_plots", dest="rescale_plots", action="store_true", | |
67 default=False, required=False) | |
68 | |
69 args = aparser.parse_args() | |
70 | |
71 main(args.adata, args.output, args.gating_workflow, | |
72 args.gating_workflow_ext, args.manual_gates, | |
73 args.manual_gates_ext, args.rescale_plots) |