From 7d0149d445b2e613e91de5a0470a5c8e08f54057 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 31 Jul 2015 10:59:21 +0200 Subject: descriptor tests working --- test/compound.rb | 6 ++++++ test/descriptor.rb | 47 ++++++++++++++++++++--------------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/test/compound.rb b/test/compound.rb index 70271fc..86930b6 100644 --- a/test/compound.rb +++ b/test/compound.rb @@ -68,4 +68,10 @@ class CompoundTest < MiniTest::Test assert_equal "CHEMBL581676", c.chemblid end + def test_sdf_storage + c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N" + c.sdf + assert !c.sdf_id.nil? + end + end diff --git a/test/descriptor.rb b/test/descriptor.rb index 7ed0abd..e5b64e0 100644 --- a/test/descriptor.rb +++ b/test/descriptor.rb @@ -21,11 +21,11 @@ class DescriptorTest < MiniTest::Test def test_smarts c = OpenTox::Compound.from_smiles "N=C=C1CCC(=F=FO)C1" result = OpenTox::Algorithm::Descriptor.smarts_match c, "FF" - assert_equal [[1]], result + assert_equal [1], result smarts = ["CC", "C", "C=C", "CO", "FF", "C1CCCC1", "NN"] result = OpenTox::Algorithm::Descriptor.smarts_match c, smarts - assert_equal [[1, 1, 1, 0, 1, 1, 0]], result - smarts_count = [[10, 6, 2, 0, 2, 10, 0]] + assert_equal [1, 1, 1, 0, 1, 1, 0], result + smarts_count = [10, 6, 2, 0, 2, 10, 0] result = OpenTox::Algorithm::Descriptor.smarts_count c, smarts assert_equal smarts_count, result end @@ -33,57 +33,50 @@ class DescriptorTest < MiniTest::Test def test_compound_openbabel_single c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N" result = OpenTox::Algorithm::Descriptor.physchem c, ["Openbabel.logP"] - assert_equal 1, result[0].size - assert_equal 1.12518, result[0][0] + assert_equal [1.12518], result end def test_compound_cdk_single c = OpenTox::Compound.from_smiles "c1ccccc1" result = OpenTox::Algorithm::Descriptor.physchem c, ["Cdk.AtomCount"] - assert_equal 12, result[c]["Cdk.AtomCount.nAtom"] + assert_equal [12], result c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N" result = OpenTox::Algorithm::Descriptor.physchem c, ["Cdk.AtomCount"] - assert_equal 17, result[c]["Cdk.AtomCount.nAtom"] + assert_equal [17], result result = OpenTox::Algorithm::Descriptor.physchem c, ["Cdk.CarbonTypes"] c_types = {"Cdk.CarbonTypes.C1SP1"=>1, "Cdk.CarbonTypes.C2SP1"=>0, "Cdk.CarbonTypes.C1SP2"=>0, "Cdk.CarbonTypes.C2SP2"=>1, "Cdk.CarbonTypes.C3SP2"=>0, "Cdk.CarbonTypes.C1SP3"=>2, "Cdk.CarbonTypes.C2SP3"=>1, "Cdk.CarbonTypes.C3SP3"=>1, "Cdk.CarbonTypes.C4SP3"=>0} - assert_equal c_types, result[c] + assert_equal [1, 0, 0, 1, 0, 2, 1, 1, 0], result end def test_compound_joelib_single c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N" result = OpenTox::Algorithm::Descriptor.physchem c, ["Joelib.LogP"] - assert_equal 2.65908, result[c]["Joelib.LogP"] + assert_equal [2.65908], result end def test_compound_all c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N" result = OpenTox::Algorithm::Descriptor.physchem c - assert_equal 332, result[c].size - { - "Cdk.LongestAliphaticChain.nAtomLAC"=>5, - "Joelib.count.HeavyBonds"=>7, - "Openbabel.MR"=>30.905, - #"Cdk.LengthOverBreadthDescriptor.LOBMAX"=>1.5379006098352144, - #"Joelib.GeometricalShapeCoefficient"=>5.210533887682899, - }.each do |d,v| - assert_equal v, result[c][d] - end + assert_equal 332, result.size + assert_equal 30.8723, result[2] + assert_equal 1.12518, result[328] end def test_compound_descriptor_parameters c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N" - result = OpenTox::Algorithm::Descriptor.physchem c, [ "Openbabel.logP", "Cdk.AtomCount", "Cdk.CarbonTypes", "Joelib.LogP" ] - assert_equal 12, result[c].size - expect = {"Openbabel.logP"=>1.12518, "Cdk.AtomCount.nAtom"=>17, "Cdk.CarbonTypes.C1SP1"=>1, "Cdk.CarbonTypes.C2SP1"=>0, "Cdk.CarbonTypes.C1SP2"=>0, "Cdk.CarbonTypes.C2SP2"=>1, "Cdk.CarbonTypes.C3SP2"=>0, "Cdk.CarbonTypes.C1SP3"=>2, "Cdk.CarbonTypes.C2SP3"=>1, "Cdk.CarbonTypes.C3SP3"=>1, "Cdk.CarbonTypes.C4SP3"=>0, "Joelib.LogP"=>2.65908} - assert_equal expect, result[c] + result = OpenTox::Algorithm::Descriptor.physchem c, [ "Openbabel.logP", "Cdk.AtomCount", "Cdk.CarbonTypes", "Joelib.LogP" ], true + assert_equal 12, result.last.size + assert_equal ["Openbabel.logP", "Cdk.AtomCount.nAtom", "Cdk.CarbonTypes.C1SP1", "Cdk.CarbonTypes.C2SP1", "Cdk.CarbonTypes.C1SP2", "Cdk.CarbonTypes.C2SP2", "Cdk.CarbonTypes.C3SP2", "Cdk.CarbonTypes.C1SP3", "Cdk.CarbonTypes.C2SP3", "Cdk.CarbonTypes.C3SP3", "Cdk.CarbonTypes.C4SP3", "Joelib.LogP"], result.first + assert_equal [1.12518, 17, 1, 0, 0, 1, 0, 2, 1, 1, 0, 2.65908], result.last end def test_dataset_descriptor_parameters - dataset = OpenTox::Dataset.new - dataset.upload File.join(DATA_DIR,"hamster_carcinogenicity.mini.csv") + dataset = OpenTox::Dataset.from_csv_file File.join(DATA_DIR,"hamster_carcinogenicity.mini.csv") d = OpenTox::Algorithm::Descriptor.physchem dataset, [ "Openbabel.logP", "Cdk.AtomCount", "Cdk.CarbonTypes", "Joelib.LogP" ] - assert_equal dataset.compounds.size, d.keys.size - assert_equal 12, d.first.last.size + assert_kind_of Dataset, d + assert_equal dataset.compounds, d.compounds + assert_equal dataset.compounds.size, d.data_entries.size + assert_equal 12, d.data_entries.first.size end end -- cgit v1.2.3