comparison decoupler_pathway_inference.py @ 3:c6787c2aee46 draft

planemo upload for repository https://github.com/ebi-gene-expression-group/container-galaxy-sc-tertiary/ commit eea5c13f9e6e070a2359c59400773b01f9cd7567
author ebi-gxa
date Mon, 15 Jul 2024 10:56:37 +0000
parents 77d680b36e23
children 9864fd2cc1f0
comparison
equal deleted inserted replaced
2:82b7cd3e1bbd 3:c6787c2aee46
18 "-n", "--input_network", help="Network input file", required=True 18 "-n", "--input_network", help="Network input file", required=True
19 ) 19 )
20 20
21 # output file prefix 21 # output file prefix
22 parser.add_argument( 22 parser.add_argument(
23 "-o", "--output", 23 "-o",
24 "--output",
24 help="output files prefix", 25 help="output files prefix",
25 default=None, 26 default=None,
26 ) 27 )
27 28
28 # path to save Activities AnnData file 29 # path to save Activities AnnData file
29 parser.add_argument( 30 parser.add_argument(
30 "-a", "--activities_path", help="Path to save Activities AnnData file", default=None 31 "-a",
32 "--activities_path",
33 help="Path to save Activities AnnData file",
34 default=None,
31 ) 35 )
32 36
33 # Column name in net with source nodes 37 # Column name in net with source nodes
34 parser.add_argument( 38 parser.add_argument(
35 "-s", "--source", help="Column name in net with source nodes.", default="source" 39 "-s",
40 "--source",
41 help="Column name in net with source nodes.",
42 default="source",
36 ) 43 )
37 44
38 # Column name in net with target nodes 45 # Column name in net with target nodes
39 parser.add_argument( 46 parser.add_argument(
40 "-t", "--target", help="Column name in net with target nodes.", default="target" 47 "-t",
48 "--target",
49 help="Column name in net with target nodes.",
50 default="target",
41 ) 51 )
42 52
43 # Column name in net with weights. 53 # Column name in net with weights.
44 parser.add_argument( 54 parser.add_argument(
45 "-w", "--weight", help="Column name in net with weights.", default="weight" 55 "-w", "--weight", help="Column name in net with weights.", default="weight"
46 ) 56 )
47 57
48 # add boolean argument for use_raw 58 # add boolean argument for use_raw
49 parser.add_argument( 59 parser.add_argument(
50 "--use_raw", action="store_true", default=False, help="Whether to use the raw part of the AnnData object" 60 "--use_raw",
61 action="store_true",
62 default=False,
63 help="Whether to use the raw part of the AnnData object",
51 ) 64 )
52 65
53 # add argument for min_cells 66 # add argument for min_cells
54 parser.add_argument( 67 parser.add_argument(
55 "--min_n", help="Minimum of targets per source. If less, sources are removed.", default=5, type=int 68 "--min_n",
69 help="Minimum of targets per source. If less, sources are removed.",
70 default=5,
71 type=int,
56 ) 72 )
57 73
58 # add activity inference method option 74 # add activity inference method option
59 parser.add_argument( 75 parser.add_argument(
60 "-m", "--method", help="Activity inference method", default="mlm", required=True 76 "-m",
77 "--method",
78 help="Activity inference method",
79 default="mlm",
80 required=True,
61 ) 81 )
62 args = parser.parse_args() 82 args = parser.parse_args()
63 83
64 # check that either -o or --output is specified 84 # check that either -o or --output is specified
65 if args.output is None: 85 if args.output is None:
67 87
68 # read in the AnnData input file 88 # read in the AnnData input file
69 adata = ad.read_h5ad(args.input_anndata) 89 adata = ad.read_h5ad(args.input_anndata)
70 90
71 # read in the input file network input file 91 # read in the input file network input file
72 network = pd.read_csv(args.input_network, sep='\t') 92 network = pd.read_csv(args.input_network, sep="\t")
73 93
74 if ( 94 if (
75 args.source not in network.columns 95 args.source not in network.columns
76 or args.target not in network.columns 96 or args.target not in network.columns
77 or args.weight not in network.columns 97 or args.weight not in network.columns
90 source=args.source, 110 source=args.source,
91 target=args.target, 111 target=args.target,
92 weight=args.weight, 112 weight=args.weight,
93 verbose=True, 113 verbose=True,
94 min_n=args.min_n, 114 min_n=args.min_n,
95 use_raw=args.use_raw 115 use_raw=args.use_raw,
96 ) 116 )
97 117
98 if args.output is not None: 118 if args.output is not None:
99 # write adata.obsm[mlm_key] and adata.obsm[mlm_pvals_key] to the output network files 119 # write adata.obsm[mlm_key] and adata.obsm[mlm_pvals_key] to the
100 combined_df = pd.concat([adata.obsm["mlm_estimate"], adata.obsm["mlm_pvals"]], axis=1) 120 # output network files
121 combined_df = pd.concat(
122 [adata.obsm["mlm_estimate"], adata.obsm["mlm_pvals"]], axis=1
123 )
101 124
102 # Save the combined dataframe to a file 125 # Save the combined dataframe to a file
103 combined_df.to_csv(args.output + ".tsv", sep="\t") 126 combined_df.to_csv(args.output + ".tsv", sep="\t")
104 127
105 # if args.activities_path is specified, generate the activities AnnData and save the AnnData object to the specified path 128 # if args.activities_path is specified, generate the activities AnnData
129 # and save the AnnData object to the specified path
106 if args.activities_path is not None: 130 if args.activities_path is not None:
107 acts = dc.get_acts(adata, obsm_key="mlm_estimate") 131 acts = dc.get_acts(adata, obsm_key="mlm_estimate")
108 acts.write_h5ad(args.activities_path) 132 acts.write_h5ad(args.activities_path)
109 133
110 elif args.method == "ulm": 134 elif args.method == "ulm":
114 source=args.source, 138 source=args.source,
115 target=args.target, 139 target=args.target,
116 weight=args.weight, 140 weight=args.weight,
117 verbose=True, 141 verbose=True,
118 min_n=args.min_n, 142 min_n=args.min_n,
119 use_raw=args.use_raw 143 use_raw=args.use_raw,
120 ) 144 )
121 145
122 if args.output is not None: 146 if args.output is not None:
123 # write adata.obsm[mlm_key] and adata.obsm[mlm_pvals_key] to the output network files 147 # write adata.obsm[mlm_key] and adata.obsm[mlm_pvals_key] to the
124 combined_df = pd.concat([adata.obsm["ulm_estimate"], adata.obsm["ulm_pvals"]], axis=1) 148 # output network files
149 combined_df = pd.concat(
150 [adata.obsm["ulm_estimate"], adata.obsm["ulm_pvals"]], axis=1
151 )
125 152
126 # Save the combined dataframe to a file 153 # Save the combined dataframe to a file
127 combined_df.to_csv(args.output + ".tsv", sep="\t") 154 combined_df.to_csv(args.output + ".tsv", sep="\t")
128 155
129 # if args.activities_path is specified, generate the activities AnnData and save the AnnData object to the specified path 156 # if args.activities_path is specified, generate the activities AnnData
157 # and save the AnnData object to the specified path
130 if args.activities_path is not None: 158 if args.activities_path is not None:
131 acts = dc.get_acts(adata, obsm_key="ulm_estimate") 159 acts = dc.get_acts(adata, obsm_key="ulm_estimate")
132 acts.write_h5ad(args.activities_path) 160 acts.write_h5ad(args.activities_path)