Mercurial > repos > ebi-gxa > pyscenic_aucell
annotate pyscenic_binarize_aucell.py @ 1:3192e6fb85a6 draft default tip
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
| author | ebi-gxa | 
|---|---|
| date | Sun, 15 Sep 2024 10:13:21 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
1
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
1 import argparse | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
2 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
3 import pandas as pd | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
4 from pyscenic.binarization import binarize | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
5 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
6 if __name__ == "__main__": | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
7 parser = argparse.ArgumentParser(description="Binarize AUC matrix") | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
8 parser.add_argument("input_file", help="Input TSV or CSV file") | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
9 parser.add_argument( | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
10 "--threshold-overrides", | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
11 type=str, | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
12 help="Threshold overrides in JSON format", | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
13 ) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
14 parser.add_argument("--seed", type=int, default=None, help="Random seed") | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
15 parser.add_argument( | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
16 "--num-workers", type=int, default=1, help="Number of workers" | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
17 ) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
18 parser.add_argument( | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
19 "--output-prefix", type=str, default="output", help="Output prefix" | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
20 ) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
21 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
22 args = parser.parse_args() | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
23 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
24 # Read input file | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
25 if args.input_file.endswith(".tsv"): | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
26 auc_mtx = pd.read_csv(args.input_file, sep="\t", index_col=0) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
27 elif args.input_file.endswith(".csv"): | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
28 auc_mtx = pd.read_csv(args.input_file, index_col=0) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
29 else: | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
30 raise ValueError("Input file must be a TSV or CSV file") | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
31 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
32 auc_mtx.apply(pd.to_numeric) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
33 # Parse threshold overrides | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
34 threshold_overrides = None | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
35 if args.threshold_overrides: | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
36 import json | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
37 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
38 threshold_overrides = json.loads(args.threshold_overrides) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
39 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
40 # Call binarize function | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
41 binarized_mtx, thresholds = binarize( | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
42 auc_mtx, threshold_overrides, args.seed, args.num_workers | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
43 ) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
44 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
45 # set column name for thresholds | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
46 thresholds.rename("threshold", inplace=True) | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
47 | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
48 # Save output files | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
49 binarized_mtx.to_csv(f"{args.output_prefix}/binarized_mtx.tsv", sep="\t") | 
| 
 
3192e6fb85a6
planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
 
ebi-gxa 
parents:  
diff
changeset
 | 
50 thresholds.to_csv(f"{args.output_prefix}/thresholds.tsv", sep="\t") | 
