Skip to content

Commit ac54083

Browse files
authored
added bobono command line and docs for it (#340)
Co-authored-by: violafanfani <viola.fanfani@gmail.com>
1 parent b651b81 commit ac54083

5 files changed

Lines changed: 87 additions & 6 deletions

File tree

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
Changelog
33
==========
44

5+
0.10.2
6+
-------------------------
7+
8+
- Fixed readthedocs
9+
- Removed save_memory from LIONESS (CLI). The first PANDA needs to keep the PANDA value in memory
10+
- Added BONOBO to CLI
11+
512
0.10.1
613
-------------------------
714

docs/functions/cli.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Commands
2323

2424
.. click:: netZooPy.cli:cli
2525
:prog: netzoopy
26-
:commands: panda,lioness,condor
26+
:commands: panda,lioness,condor,bonobo
2727
:nested: full
2828

2929

netZooPy/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ def cli():
1111
cli.add_command(cl.panda)
1212
cli.add_command(cl.lioness)
1313
cli.add_command(cl.condor)
14+
cli.add_command(cl.bonobo)

netZooPy/command_line.py

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import click
66
from netZooPy.panda.panda import Panda
77
from netZooPy.lioness import Lioness
8+
from netZooPy.ligress import Bonobo
89
from netZooPy.condor import condor_object
910

1011
#############################################################################
@@ -119,9 +120,9 @@ def panda(expression, motif, ppi, output, computing='cpu', precision='double',wi
119120
help='precision option')
120121
@click.option('--ncores', type=int, show_default=True, default=1,
121122
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.')
125126
@click.option('--save_tmp', is_flag=True, show_default=True,
126127
help='panda option')
127128
@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
198199
# Run PANDA
199200
print('Start Panda run ...')
200201

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)
202204
print('Panda saved. Computing Lioness...')
203205
panda_obj.save_panda_results(output_panda, save_adjacency=as_adjacency, old_compatible=old_compatible)
204206

@@ -269,3 +271,73 @@ def condor(
269271
co.tar_memb.to_csv(tar_output)
270272
co.reg_memb.to_csv(reg_output)
271273

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+

netZooPy/ligress/bonobo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def run_bonobo(
227227
precision (str, optional): matrix precision, defaults to single precision.
228228
sparsify (bool, optiona): if True, bonobo gets sparsified and relative pvalues are returned
229229
confidence (float, optional): if sparsify is True, this is the CI for the approximate zscore.
230+
save_pvals (bool, optional): if True, the pvalues are saved and returned
230231
"""
231232

232233
ligress_start = time.time()
@@ -238,7 +239,7 @@ def run_bonobo(
238239
elif precision == "double":
239240
atype = "float64"
240241
else:
241-
sys.exit("Precision %s unknonw" % str(precision))
242+
sys.exit("ERROR: Precision %s unknonw" % str(precision))
242243

243244
# let's sort the expression and ppi data
244245
self.expression_data = self.expression_data.astype(atype)

0 commit comments

Comments
 (0)