Skip to content

Commit

Permalink
refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisacidic committed Jul 29, 2015
1 parent 8c19b55 commit 67f4e4e
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 35 deletions.
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[nosetests]
verbosity=3
with-doctest=1
with-yanc=1
with-coverage=1
103 changes: 69 additions & 34 deletions skchem/descriptors/fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,58 @@ def skchemize(func, columns=None, *args, **kwargs):
transform an RDKit fingerprinting function to work well with pandas
>>> from rdkit import Chem
>>> from skchem import *
>>> import skchem
>>> from skchem.descriptors import skchemize
>>> from skchem.core import Mol
>>> f = skchemize(Chem.RDKFingerprint)
>>> m = Mol.from_smiles('c1ccccc1')
>>> f(m)
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
...
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 0
11 0
12 0
13 0
14 0
15 0
16 0
17 0
18 0
19 0
20 0
21 0
22 0
23 0
24 0
25 0
26 0
27 0
28 0
29 0
..
2018 0
2019 0
2020 0
2021 0
2022 0
2023 0
2024 0
2025 0
2026 0
2027 0
2028 0
2029 0
2030 0
2031 0
2032 0
2033 0
2034 0
2035 0
Expand All @@ -56,22 +88,22 @@ def skchemize(func, columns=None, *args, **kwargs):
2045 0
2046 0
2047 0
Length: 2048, dtype: int64
>>> df = skchem.read_sdf('skchem/tests/test_resources/hydrocarbons.sdf')
dtype: int64
>>> from skchem.data import resource
>>> df = skchem.read_sdf(resource('test_sdf', 'multi_molecule-simple.sdf'))
>>> df.structure.apply(f)
0 1 2 3 4 5 6 7 8 9 ... 2038 \
Name ...
297 0 0 0 0 0 0 0 0 0 0 ... 0
6324 0 0 0 0 0 0 0 0 0 0 ... 0
6334 0 0 0 0 0 0 0 0 0 0 ... 0
2039 2040 2041 2042 2043 2044 2045 2046 2047
Name
297 0 0 0 0 0 0 0 0 0
6324 0 0 0 0 0 0 0 0 0
6334 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9 ... 2038 \\
name ...
297 0 0 0 0 0 0 0 0 0 0 ... 0
6324 0 0 0 0 0 0 0 0 0 0 ... 0
6334 0 0 0 0 0 0 0 0 0 0 ... 0
<BLANKLINE>
2039 2040 2041 2042 2043 2044 2045 2046 2047
name
297 0 0 0 0 0 0 0 0 0
6324 0 0 0 0 0 0 0 0 0
6334 0 0 0 0 0 0 0 0 0
<BLANKLINE>
[3 rows x 2048 columns]
"""
Expand Down Expand Up @@ -109,12 +141,15 @@ def calculate(self, obj):

""" calculate the fingerprint for the given object. """

if obj.__class__ is skc.core.Mol:
if isinstance(obj, skc.core.Mol):
return self._calculate_m(obj)

elif obj.__class__ in [pd.DataFrame, pd.Series]:
elif isinstance(obj, pd.DataFrame) or isinstance(obj, pd.Series):
return self._calculate_df(obj)

else:
raise NotImplementedError

def _calculate_m(self, m):

""" calculate the fingerprint for a molecule. """
Expand Down
2 changes: 1 addition & 1 deletion skchem/io/smiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse(smiles):
"""
return skchem.Mol.from_smiles(smiles)

df['structure'] = df['structure'].apply(parse)
df['structure'] = df['structure'].apply(str).apply(parse) #make sure is a string

if force:
df = df[df['structure'].notnull()]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 67f4e4e

Please sign in to comment.