Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Packages
signaturizer
Commits
8aeb4c34
Commit
8aeb4c34
authored
Jul 01, 2020
by
Martino Bertoni
🌋
Browse files
handling overwriting existing detination
parent
e55c0074
Changes
2
Hide whitespace changes
Inline
Side-by-side
signaturizer/signaturizer.py
View file @
8aeb4c34
...
...
@@ -68,6 +68,10 @@ class Signaturizer():
features
=
len
(
self
.
modules
)
*
128
results
=
SignaturizerResult
(
len
(
smiles
),
destination
,
features
)
if
results
.
readonly
:
raise
Exception
(
'Destination file already exists, '
+
'delete or rename to proceed.'
)
# predict by chunk
all_chunks
=
range
(
0
,
len
(
smiles
),
chunk_size
)
for
i
in
tqdm
(
all_chunks
,
disable
=
self
.
verbose
):
...
...
@@ -128,6 +132,7 @@ class SignaturizerResult():
be saved.
"""
self
.
dst
=
destination
self
.
readonly
=
False
if
self
.
dst
is
None
:
# simple numpy arrays
self
.
h5
=
None
...
...
@@ -138,6 +143,7 @@ class SignaturizerResult():
print
(
'HDF5 file %s exists, opening in read-only.'
%
self
.
dst
)
# this avoid overwriting by mistake
self
.
h5
=
h5py
.
File
(
self
.
dst
,
'r'
)
self
.
readonly
=
True
else
:
# create the datasets
self
.
h5
=
h5py
.
File
(
self
.
dst
,
'w'
)
...
...
tests/test_signaturizer.py
View file @
8aeb4c34
...
...
@@ -87,3 +87,12 @@ class TestSignaturizer(unittest.TestCase):
res
=
module
.
predict
(
self
.
test_smiles
)
self
.
assertEqual
(
res
.
signature
.
shape
[
0
],
2
)
self
.
assertEqual
(
res
.
signature
.
shape
[
1
],
128
*
25
)
def
test_overwrite
(
self
):
module_dir
=
os
.
path
.
join
(
self
.
data_dir
,
'B1'
)
module
=
Signaturizer
(
module_dir
)
destination
=
os
.
path
.
join
(
self
.
tmp_dir
,
'pred.h5'
)
module
.
predict
(
self
.
test_smiles
,
destination
)
# repeating writing will result in an exception
with
self
.
assertRaises
(
Exception
):
module
.
predict
(
self
.
test_smiles
,
destination
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment