|
5 | 5 | import click |
6 | 6 | from netZooPy.panda.panda import Panda |
7 | 7 | from netZooPy.lioness import Lioness |
| 8 | +from netZooPy.ligress import Bonobo |
8 | 9 | from netZooPy.condor import condor_object |
9 | 10 |
|
10 | 11 | ############################################################################# |
@@ -119,9 +120,9 @@ def panda(expression, motif, ppi, output, computing='cpu', precision='double',wi |
119 | 120 | help='precision option') |
120 | 121 | @click.option('--ncores', type=int, show_default=True, default=1, |
121 | 122 | help='Number of cores. Lioness CPU parallelizes over ncores') |
122 | | -@click.option('--save_memory', is_flag=True, show_default=False, |
123 | | - help='panda option. When true the result network is weighted adjacency matrix of size (nTFs, nGenes).\ |
124 | | - when false The result network has 4 columns in the form gene - TF - weight in motif prior - PANDA edge.') |
| 123 | +#@click.option('--save_memory', is_flag=True, show_default=False, |
| 124 | +# help='panda option. When true the result network is weighted adjacency matrix of size (nTFs, nGenes).\ |
| 125 | +# when false The result network has 4 columns in the form gene - TF - weight in motif prior - PANDA edge.') |
125 | 126 | @click.option('--save_tmp', is_flag=True, show_default=True, |
126 | 127 | help='panda option') |
127 | 128 | @click.option('--rm_missing', is_flag=True, show_default=False, |
@@ -198,7 +199,8 @@ def lioness(expression, motif, ppi, output_panda, output_lioness, el, fmt, compu |
198 | 199 | # Run PANDA |
199 | 200 | print('Start Panda run ...') |
200 | 201 |
|
201 | | - panda_obj = Panda(expression, motif, ppi, precision=precision, computing=computing, save_tmp=save_tmp, remove_missing=rm_missing, keep_expression_matrix=True, save_memory=save_memory, modeProcess=mode_process, start=panda_start, end=panda_end, with_header=with_header) |
| 202 | + # For now we keep save_memory=False always, otherwise we won't have the needed information for lioness |
| 203 | + panda_obj = Panda(expression, motif, ppi, precision=precision, computing=computing, save_tmp=save_tmp, remove_missing=rm_missing, keep_expression_matrix=True, save_memory=False, modeProcess=mode_process, start=panda_start, end=panda_end, with_header=with_header) |
202 | 204 | print('Panda saved. Computing Lioness...') |
203 | 205 | panda_obj.save_panda_results(output_panda, save_adjacency=as_adjacency, old_compatible=old_compatible) |
204 | 206 |
|
@@ -269,3 +271,73 @@ def condor( |
269 | 271 | co.tar_memb.to_csv(tar_output) |
270 | 272 | co.reg_memb.to_csv(reg_output) |
271 | 273 |
|
| 274 | + |
| 275 | + |
| 276 | +################################################ |
| 277 | +###### BONOBO ################################## |
| 278 | +################################################ |
| 279 | + |
| 280 | +@click.command() |
| 281 | +@click.option('-e', '--expression_file', 'expression_file', type=str, required=True, |
| 282 | + help='Path to file containing the gene expression data or pandas dataframe. By default, the expression file does not have a header, and the cells ares separated by a tab.') |
| 283 | +@click.option('--output_folder', type=str, show_default=True, default='bonobo/', |
| 284 | + help='Output folder for the bonobo files. If not specified, the bonobo files are saved in the current directory, in the bonobo subdirectory.') |
| 285 | +@click.option('--output_format', type=str, show_default=True, default='.h5', |
| 286 | + help='format of output bonobo matrix. By default it is an hdf file, can be a txt or csv.') |
| 287 | +@click.option('--keep_in_memory', is_flag=True, show_default=True, |
| 288 | + help='if True, the bonobo coexpression matrix is kept in memory, otherwise it is discarded after saving') |
| 289 | +@click.option('--delta', type=float, show_default=True, default=None, |
| 290 | + help='delta parameter. If default (None) delta is trained, otherwise pass a value.Recommended is 0.3.') |
| 291 | +@click.option('--sparsify', is_flag=True, show_default=True, |
| 292 | + help='if True, bonobo gets sparsified and relative pvalues are returned') |
| 293 | +@click.option('--confidence', type=float, show_default=True, default=0.05, |
| 294 | + help='if sparsify is True, this is the CI for the approximate zscore.') |
| 295 | +@click.option('--save_pvals', is_flag=True, show_default=True, |
| 296 | + help='if True, bonobo gets sparsified and relative pvalues are saved in the same format and folder of bonobo') |
| 297 | +@click.option('--precision', type=str, show_default=True, default='single', |
| 298 | + help='matrix precision (single or double), defaults to single precision.') |
| 299 | +@click.option('--sample_names', type=str, show_default=True, default='', |
| 300 | + help='Compute BONOBO only on a subset of samples. Pass a comma separated list of sample names. If not specified, all samples are used.') |
| 301 | +def bonobo( |
| 302 | + expression_file, |
| 303 | + output_folder = 'bonobo/', |
| 304 | + output_format = '.h5', |
| 305 | + keep_in_memory = False, |
| 306 | + delta = None, |
| 307 | + sparsify = False, |
| 308 | + confidence = 0.05, |
| 309 | + save_pvals = False, |
| 310 | + precision = 'single', |
| 311 | + sample_names = '', |
| 312 | +): |
| 313 | + """ |
| 314 | + Compute BONOBOs from an expression file. |
| 315 | + |
| 316 | + Parameters the user cannot access from the CLI: |
| 317 | + - computing: for now it is only CPU |
| 318 | + - cores: number of cores to use, for now there is no parallelization |
| 319 | + - online_coexpression: we have not implemented the online coexpression yet |
| 320 | + """ |
| 321 | + |
| 322 | + if sample_names!='': |
| 323 | + sample_names = sample_names.split(',') |
| 324 | + print('WARNING: computing BOBOBO only on a subset of samples. The sample names are:') |
| 325 | + print(sample_names) |
| 326 | + else: |
| 327 | + sample_names = [] |
| 328 | + |
| 329 | + print('Initializing BONOBO object ...') |
| 330 | + bonobo_obj_sparse = Bonobo(expression_file) |
| 331 | + print('Running BONOBO ...') |
| 332 | + print('Files saved in %s' %output_folder) |
| 333 | + |
| 334 | + bonobo_obj_sparse.run_bonobo(keep_in_memory=keep_in_memory, |
| 335 | + output_fmt=output_format, |
| 336 | + delta = delta, |
| 337 | + sparsify=sparsify, |
| 338 | + output_folder=output_folder, |
| 339 | + confidence = confidence, |
| 340 | + save_pvals=save_pvals, |
| 341 | + precision = precision, |
| 342 | + sample_names=sample_names) |
| 343 | + |
0 commit comments