Commit eb4766d4 authored by pvskand's avatar pvskand
Browse files

Merge branch 'master' of https://github.com/deepchem/deepchem

merging with PR 1290 - addressing manual numpy install
parents fe97174a ea43d3c0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ install:
- conda config --add channels http://conda.binstar.org/omnia
- bash scripts/install_deepchem_conda.sh deepchem
- source activate deepchem
- pip install yapf==0.20.0
- pip install yapf==0.22.0
- pip install coveralls
- python setup.py install
script:
+5 −3
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ __license__ = "MIT"

import os
import unittest

import deepchem as dc


@@ -26,7 +27,8 @@ class TestFASTALoader(unittest.TestCase):
                              "../../data/tests/example.fasta")
    loader = dc.data.FASTALoader()
    sequences = loader.featurize(input_file)

    # example.fasta contains 3 sequences each of length 58.
    # The one-hot encoding turns base-pairs into vectors of length 4.
    # There is one "image channel")
    assert sequences.X.shape == (3, 4, 58, 1)
    # The one-hot encoding turns base-pairs into vectors of length 5 (ATCGN).
    # There is one "image channel".
    assert sequences.X.shape == (3, 5, 58, 1)
+15 −0
Original line number Diff line number Diff line
@@ -94,3 +94,18 @@ class CircularFingerprint(Featurizer):
          useBondTypes=self.bonds,
          useFeatures=self.features)
    return fp

  def __hash__(self):
    return hash((self.radius, self.size, self.chiral, self.bonds, self.features,
                 self.sparse, self.smiles))

  def __eq__(self, other):
    if not isinstance(self, other.__class__):
      return False
    return self.radius == other.radius and \
           self.size == other.size and \
           self.chiral == other.chiral and \
           self.bonds == other.bonds and \
           self.features == other.features and \
           self.sparse == other.sparse and \
           self.smiles == other.smiles
+11 −0
Original line number Diff line number Diff line
@@ -358,6 +358,17 @@ class ConvMolFeaturizer(Featurizer):
  def feature_length(self):
    return 75 + len(self.atom_properties)

  def __hash__(self):
    atom_properties = tuple(self.atom_properties)
    return hash((self.master_atom, self.use_chirality, atom_properties))

  def __eq__(self, other):
    if not isinstance(self, other.__class__):
      return False
    return self.master_atom == other.master_atom and \
           self.use_chirality == other.use_chirality and \
           tuple(self.atom_properties) == tuple(other.atom_properties)


class WeaveFeaturizer(Featurizer):
  name = ['weave_mol']
+35 −2
Original line number Diff line number Diff line
"""
Test featurizer class.
"""
import numpy as np
import unittest

from deepchem.feat import ConvMolFeaturizer, CircularFingerprint
from deepchem.feat.basic import MolecularWeight
from rdkit import Chem

from deepchem.feat.basic import MolecularWeight

class TestFeaturizer(unittest.TestCase):
  """
  Tests for Featurizer.
  """

  def setUp(self):
    """
    Set up tests.
@@ -34,3 +35,35 @@ class TestFeaturizer(unittest.TestCase):
    f = MolecularWeight()
    rval = f([self.mol])
    assert rval.shape == (1, 1)

  def test_convmol_hashable(self):
    featurizer1 = ConvMolFeaturizer(atom_properties=['feature'])
    featurizer2 = ConvMolFeaturizer(atom_properties=['feature'])
    featurizer3 = ConvMolFeaturizer()

    d = set()
    d.add(featurizer1)
    d.add(featurizer2)
    d.add(featurizer3)

    self.assertEqual(2, len(d))
    featurizers = [featurizer1, featurizer2, featurizer3]

    for featurizer in featurizers:
      self.assertTrue(featurizer in featurizers)

  def test_circularfingerprint_hashable(self):
    featurizer1 = CircularFingerprint()
    featurizer2 = CircularFingerprint()
    featurizer3 = CircularFingerprint(size=5)

    d = set()
    d.add(featurizer1)
    d.add(featurizer2)
    d.add(featurizer3)

    self.assertEqual(2, len(d))
    featurizers = [featurizer1, featurizer2, featurizer3]

    for featurizer in featurizers:
      self.assertTrue(featurizer in featurizers)
Loading