Mercurial > repos > ebi-gxa > pyscenic_ctx
comparison pyscenic_binarize_aucell.py @ 1:3ce4ff3b9f1b 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:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:931cd3661690 | 1:3ce4ff3b9f1b |
---|---|
1 import argparse | |
2 | |
3 import pandas as pd | |
4 from pyscenic.binarization import binarize | |
5 | |
6 if __name__ == "__main__": | |
7 parser = argparse.ArgumentParser(description="Binarize AUC matrix") | |
8 parser.add_argument("input_file", help="Input TSV or CSV file") | |
9 parser.add_argument( | |
10 "--threshold-overrides", | |
11 type=str, | |
12 help="Threshold overrides in JSON format", | |
13 ) | |
14 parser.add_argument("--seed", type=int, default=None, help="Random seed") | |
15 parser.add_argument( | |
16 "--num-workers", type=int, default=1, help="Number of workers" | |
17 ) | |
18 parser.add_argument( | |
19 "--output-prefix", type=str, default="output", help="Output prefix" | |
20 ) | |
21 | |
22 args = parser.parse_args() | |
23 | |
24 # Read input file | |
25 if args.input_file.endswith(".tsv"): | |
26 auc_mtx = pd.read_csv(args.input_file, sep="\t", index_col=0) | |
27 elif args.input_file.endswith(".csv"): | |
28 auc_mtx = pd.read_csv(args.input_file, index_col=0) | |
29 else: | |
30 raise ValueError("Input file must be a TSV or CSV file") | |
31 | |
32 auc_mtx.apply(pd.to_numeric) | |
33 # Parse threshold overrides | |
34 threshold_overrides = None | |
35 if args.threshold_overrides: | |
36 import json | |
37 | |
38 threshold_overrides = json.loads(args.threshold_overrides) | |
39 | |
40 # Call binarize function | |
41 binarized_mtx, thresholds = binarize( | |
42 auc_mtx, threshold_overrides, args.seed, args.num_workers | |
43 ) | |
44 | |
45 # set column name for thresholds | |
46 thresholds.rename("threshold", inplace=True) | |
47 | |
48 # Save output files | |
49 binarized_mtx.to_csv(f"{args.output_prefix}/binarized_mtx.tsv", sep="\t") | |
50 thresholds.to_csv(f"{args.output_prefix}/thresholds.tsv", sep="\t") |