annotate pyscenic_binarize_aucell.py @ 0:31a8c822882f 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:34 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
31a8c822882f 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
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
2
31a8c822882f 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
31a8c822882f 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
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
5
31a8c822882f 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__":
31a8c822882f 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")
31a8c822882f 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")
31a8c822882f 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(
31a8c822882f 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",
31a8c822882f 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,
31a8c822882f 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",
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
13 )
31a8c822882f 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")
31a8c822882f 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(
31a8c822882f 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"
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
17 )
31a8c822882f 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(
31a8c822882f 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"
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
20 )
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
21
31a8c822882f 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()
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
23
31a8c822882f 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
31a8c822882f 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"):
31a8c822882f 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)
31a8c822882f 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"):
31a8c822882f 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)
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
29 else:
31a8c822882f 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")
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
31
31a8c822882f 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)
31a8c822882f 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
31a8c822882f 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
31a8c822882f 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:
31a8c822882f 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
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
37
31a8c822882f 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)
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
39
31a8c822882f 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
31a8c822882f 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(
31a8c822882f 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
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
43 )
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
44
31a8c822882f 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
31a8c822882f 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)
31a8c822882f planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit 6f7bc53bd9da7ee2a480b5aa2d1825209738c4c4
ebi-gxa
parents:
diff changeset
47
31a8c822882f 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
31a8c822882f 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")
31a8c822882f 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")