1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
require_relative "setup.rb"
class FeatureTest < MiniTest::Test
def test_opentox_feature
@feature = OpenTox::Feature.create(:name => "tost")
assert_equal true, OpenTox::Feature.where(name: "tost").exists?, "#{@feature.id} is not accessible."
assert_equal true, OpenTox::Feature.where(id: @feature.id).exists?, "#{@feature.id} is not accessible."
list = OpenTox::Feature.all
listsize1 = list.length
assert_equal true, list.collect{|f| f.id}.include?(@feature.id)
# modify feature
@feature2 = OpenTox::Feature.find(@feature.id)
assert_equal "tost", @feature2[:name]
assert_equal "tost", @feature2.name
assert_kind_of Feature, @feature2
@feature2[:name] = "feature2"
@feature2.save
list = OpenTox::Feature.all
listsize2 = list.length
assert_match "feature2", @feature2.name
refute_match "tost", @feature2.name
assert_equal listsize1, listsize2
id = @feature2.id
@feature2.delete
assert_nil OpenTox::Feature.find(id)
end
def test_duplicated_features
metadata = {
:name => "feature duplication test",
:nominal => true,
}
feature = NumericFeature.find_or_create_by metadata
dup_feature = NumericFeature.find_or_create_by metadata
assert_kind_of Feature, feature
assert !feature.id.nil?, "No Feature ID in #{feature.inspect}"
assert !feature.id.nil?, "No Feature ID in #{dup_feature.inspect}"
assert_equal feature.id, dup_feature.id
feature.delete
assert_nil OpenTox::Feature.find(feature.id)
assert_nil OpenTox::Feature.find(dup_feature.id)
end
def test_smarts_feature
feature = Smarts.find_or_create_by(:smarts => "CN")
assert feature.smarts, "CN"
assert_kind_of Smarts, feature
feature.smarts = 'cc'
assert feature.smarts, "cc"
original = Feature.where(:smarts => 'CN').first
assert original.smarts, "CN"
end
def test_physchem_description
assert_equal 355, PhysChem.descriptors.size
assert_equal 15, PhysChem.openbabel_descriptors.size
assert_equal 295, PhysChem.cdk_descriptors.size
assert_equal 45, PhysChem.joelib_descriptors.size
assert_equal 310, PhysChem.unique_descriptors.size
end
def test_physchem
assert_equal 355, PhysChem.descriptors.size
c = Compound.from_smiles "CC(=O)CC(C)C"
logP = PhysChem.find_or_create_by :name => "Openbabel.logP"
assert_equal 1.6215, logP.calculate(c)
jlogP = PhysChem.find_or_create_by :name => "Joelib.LogP"
assert_equal 3.5951, jlogP.calculate(c)
alogP = PhysChem.find_or_create_by :name => "Cdk.ALOGP.ALogP"
assert_equal 0.35380000000000034, alogP.calculate(c)
end
end
|