Skip to content

Commit b336f80

Browse files
pykaoKen Kaokexinhuang12345
authored
solved the bug. convert_y_unit function supports Numpy Array as input (#66)
* solved diving by zero bug * solved the bug. Now it supports numpy array as input * Update utils.py Co-authored-by: Ken Kao <KenKao@Kens-MacBook-Pro.local> Co-authored-by: Kexin Huang <kexinhuang@hsph.harvard.edu> Co-authored-by: Kexin Huang <kh2383@nyu.edu>
1 parent be67b6b commit b336f80

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

DeepPurpose/utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -850,21 +850,26 @@ def generate_config(drug_encoding = None, target_encoding = None,
850850
return base_config
851851

852852
def convert_y_unit(y, from_, to_):
853+
array_flag = False
854+
if isinstance(y, (int, float)):
855+
y = np.array([y])
856+
array_flag = True
857+
y = y.astype(float)
853858
# basis as nM
854-
855859
if from_ == 'nM':
856860
y = y
857861
elif from_ == 'p':
858862
y = 10**(-y) / 1e-9
859863

860864
if to_ == 'p':
861-
if y == 0:
862-
y = -np.log10(10**-10)
863-
else:
864-
y = -np.log10(y*1e-9)
865+
zero_idxs = np.where(y == 0.)[0]
866+
y[zero_idxs] = 1e-10
867+
y = -np.log10(y*1e-9)
865868
elif to_ == 'nM':
866869
y = y
867-
870+
871+
if array_flag:
872+
return y[0]
868873
return y
869874

870875
def protein2emb_encoder(x):

0 commit comments

Comments
 (0)