Skip to content

Commit e126565

Browse files
authored
Merge pull request #23 from multipaths/diff_input_processing_recoding
Input processing updates for the recoding in DiffuPath cross-validations
2 parents 3d42242 + e957419 commit e126565

7 files changed

Lines changed: 344 additions & 183 deletions

File tree

src/diffupy/cli.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import logging
77
import os
88
import pickle
9-
import sys
109
import time
1110

1211
import click
13-
from diffupy.process_network import get_kernel_from_network_path
12+
13+
from .process_network import get_kernel_from_network_path
1414

1515
from .constants import OUTPUT, METHODS, EMOJI, RAW, CSV, JSON
1616
from .diffuse import diffuse as run_diffusion
@@ -93,7 +93,7 @@ def kernel(
9393
'-o', '--output',
9494
type=click.File('w'),
9595
help="Output file",
96-
default=sys.stdout,
96+
default=OUTPUT,
9797
)
9898
@click.option(
9999
'-m', '--method',
@@ -107,8 +107,8 @@ def kernel(
107107
'-1). For scoring methods that accept quantitative values (i.e., raw & z), node labels can also be codified '
108108
'with LogFC (in this case, set binarize==False).',
109109
type=bool,
110-
default=True,
111-
show_default=True,
110+
default=False,
111+
show_default=False,
112112
)
113113
@click.option(
114114
'-t', '--threshold',
@@ -121,8 +121,8 @@ def kernel(
121121
help='Codify node labels by applying threshold to | logFC | in input. If absolute_value is set to False,'
122122
'node labels will be signed.',
123123
type=bool,
124-
default=True,
125-
show_default=True,
124+
default=False,
125+
show_default=False,
126126
)
127127
@click.option(
128128
'-p', '--p_value',
@@ -141,11 +141,11 @@ def kernel(
141141
def diffuse(
142142
input: str,
143143
network: str,
144-
output: str = sys.stdout,
144+
output: str = OUTPUT,
145145
method: str = RAW,
146-
binarize: bool = True,
146+
binarize: bool = False,
147147
threshold: float = None,
148-
absolute_value: bool = True,
148+
absolute_value: bool = False,
149149
p_value: float = 0.05,
150150
output_format: str = CSV
151151
):

src/diffupy/matrix.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
if init_value is not None and self.rows_labels and list(self.cols_labels):
6969
mat = np.full((len(self.rows_labels), len(self.cols_labels)), init_value)
7070

71-
elif not list(mat):
71+
elif mat is None:
7272
raise ValueError('A path matrix or initialization should be provided.')
7373

7474
self.mat = np.array(mat)
@@ -114,7 +114,9 @@ def __next__(self):
114114

115115
nxt = tuple()
116116
if len(self.rows_labels) == 1:
117-
nxt += (self.mat[self.j],)
117+
nxt += (self.mat[0, self.j],)
118+
elif len(self.cols_labels) == 1:
119+
nxt += (self.mat[self.i, 0],)
118120
else:
119121
nxt += (self.mat[self.i][self.j],)
120122

@@ -284,11 +286,21 @@ def delete_col_from_label(self, label):
284286

285287
def set_cell_from_labels(self, row_label, col_label, x):
286288
"""Set cell from labels."""
287-
self.mat[self.rows_labels_ix_mapping[row_label], self.cols_labels_ix_mapping[col_label]] = x
289+
if len(self.rows_labels) == 1:
290+
self.mat[0, self.cols_labels_ix_mapping[col_label]] = x
291+
elif len(self.cols_labels) == 1:
292+
self.mat[self.rows_labels_ix_mapping[row_label], 0] = x
293+
else:
294+
self.mat[self.rows_labels_ix_mapping[row_label], self.cols_labels_ix_mapping[col_label]] = x
288295

289296
def get_cell_from_labels(self, row_label, col_label):
290297
"""Get cell from labels."""
291-
return self.mat[self.rows_labels_ix_mapping[row_label], self.cols_labels_ix_mapping[col_label]]
298+
if len(self.rows_labels) == 1:
299+
return self.mat[0, self.cols_labels_ix_mapping[col_label]]
300+
elif len(self.cols_labels) == 1:
301+
return self.mat[self.rows_labels_ix_mapping[row_label], 0]
302+
else:
303+
return self.mat[self.rows_labels_ix_mapping[row_label], self.cols_labels_ix_mapping[col_label]]
292304

293305
"""Methods"""
294306

0 commit comments

Comments
 (0)