test/compound.rb in lazar-0.0.7 vs test/compound.rb in lazar-0.0.9
- old
+ new
@@ -52,23 +52,21 @@
File.unlink(testbild)
end
def test_inchikey
c = OpenTox::Compound.from_inchi "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"
- p c
assert_equal "UHOVQNZJYSORNB-UHFFFAOYSA-N", c.inchikey
end
def test_cid
c = OpenTox::Compound.from_inchi "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"
assert_equal "241", c.cid
end
def test_chemblid
c = OpenTox::Compound.from_inchi "InChI=1S/C6H6/c1-2-4-6-5-3-1/h1-6H"
- #assert_equal "CHEMBL277500", c.chemblid
- assert_equal "CHEMBL581676", c.chemblid
+ assert_equal "CHEMBL277500", c.chemblid
end
def test_sdf_storage
c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N"
c.sdf
@@ -76,25 +74,136 @@
end
def test_fingerprint
c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C#N"
- assert c.fp4.collect{|fid| Feature.find(fid).name}.include? ("1,3-Tautomerizable")
- assert_equal c.fp4.size, c.fp4_size
+ assert_equal 9, c.fingerprint("FP4").size
end
def test_neighbors
d = Dataset.from_csv_file File.join(DATA_DIR,"EPAFHM.csv")
d.compounds.each do |c|
- refute_nil c.fp4
+ refute_nil c.fingerprint("MP2D")
end
c = d.compounds[371]
- assert c.neighbors.size >= 19
+ n = c.fingerprint_neighbors({:type => "FP4", :min_sim => 0.7, :training_dataset_id => d.id })
+ assert n.size >= 18, "Neighbors size (#{n.size}) should be larger than 17"
end
def test_openbabel_segfault
inchi = "InChI=1S/C19H27NO7/c1-11-9-19(12(2)27-19)17(23)26-14-6-8-20(4)7-5-13(15(14)21)10-25-16(22)18(11,3)24/h5,11-12,14,24H,6-10H2,1-4H3/b13-5-/t11-,12-,14-,18-,19?/m1/s1"
c = Compound.from_inchi(inchi)
assert_equal inchi, c.inchi
+ end
+
+ def test_openbabel_fingerprint
+ [
+ "CC(=O)CC(C)C#N",
+ "CC(=O)CC(C)C",
+ "C(=O)CC(C)C#N",
+ ].each do |smi|
+ c = OpenTox::Compound.from_smiles smi
+ refute_nil c.fingerprint("FP4")
+ end
+ end
+
+ def test_fingerprint_neighbors
+ types = ["FP2", "FP3", "FP4", "MACCS"]
+ min_sim = 0.7
+ training_dataset = Dataset.from_csv_file File.join(DATA_DIR,"EPAFHM.csv")
+ [
+ "CC(=O)CC(C)C#N",
+ "CC(=O)CC(C)C",
+ "C(=O)CC(C)C#N",
+ ].each do |smi|
+ c = OpenTox::Compound.from_smiles smi
+ types.each do |type|
+ neighbors = c.fingerprint_neighbors({:type => type, :training_dataset_id => training_dataset.id, :min_sim => min_sim})
+ unless type == "FP2" and smi == "CC(=O)CC(C)C#N" or smi == "C(=O)CC(C)C#N" and (type == "FP2" or type == "MACCS")
+ refute_empty neighbors
+ end
+ end
+ end
+ end
+
+ def test_mna
+ c = OpenTox::Compound.from_smiles "N#[N+]C1=CC=CC=C1.F[B-](F)(F)F"
+ assert_equal 18, c.fingerprint("MNA").size
+ assert_equal 9, c.fingerprint("MNA").uniq.size
+ end
+
+ def test_mpd
+ c = OpenTox::Compound.from_smiles "N#[N+]C1=CC=CC=C1.F[B-](F)(F)F"
+ assert 13, c.fingerprint("MP2D").size
+ assert 7, c.fingerprint("MP2D").uniq.size
+ end
+
+ def test_fingerprint_count_neighbors
+ types = ["MP2D", "MNA"]
+ min_sim = 0.0
+ training_dataset = Dataset.from_csv_file File.join(DATA_DIR,"EPAFHM.csv")
+ [
+ "CC(=O)CC(C)C#N",
+ "CC(=O)CC(C)C",
+ "C(=O)CC(C)C#N",
+ ].each do |smi|
+ c = OpenTox::Compound.from_smiles smi
+ types.each do |type|
+ neighbors = c.fingerprint_count_neighbors({:type => type, :training_dataset_id => training_dataset.id, :min_sim => min_sim})
+ if type == "FP4"
+ fp4_neighbors = c.neighbors
+ neighbors.each do |n|
+ assert_includes fp4_neighbors, n
+ end
+ end
+ end
+ end
+ end
+
+ def test_fingerprint_db_neighbors
+ #skip
+ training_dataset = Dataset.from_csv_file File.join(DATA_DIR,"EPAFHM.csv")
+ [
+ "CC(=O)CC(C)C#N",
+ "CC(=O)CC(C)C",
+ "C(=O)CC(C)C#N",
+ ].each do |smi|
+ c = OpenTox::Compound.from_smiles smi
+ t = Time.now
+ neighbors = c.db_neighbors(:training_dataset_id => training_dataset.id, :min_sim => 0.2)
+ p Time.now - t
+ t = Time.now
+ neighbors2 = c.fingerprint_neighbors({:type => "MP2D", :training_dataset_id => training_dataset.id, :min_sim => 0.2})
+ p Time.now - t
+ p neighbors.size
+ p neighbors2.size
+ #p neighbors
+ #p neighbors2
+ #p neighbors2 - neighbors
+ #assert_equal neighbors, neighbors2
+ end
+ end
+
+ def test_molecular_weight
+ c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C"
+ assert_equal 100.15888, c.molecular_weight
+ end
+
+ def test_mg_conversions
+ # TODO fix!
+ skip
+ c = OpenTox::Compound.from_smiles "O"
+ mw = c.molecular_weight
+ assert_equal 18.01528, mw
+ assert_equal 0.8105107141417474, c.logmmol_to_mg(4.34688225631145, mw)
+ assert_equal 9007.64, c.mmol_to_mg(500, mw)
+ assert_equal 2437.9999984148976, c.logmg_to_mg(3.387033701)
+ end
+
+ def test_physchem
+ c = OpenTox::Compound.from_smiles "CC(=O)CC(C)C"
+ assert_equal PhysChem::OBDESCRIPTORS.size, c.physchem.size
+ assert_equal PhysChem::OBDESCRIPTORS.size, c.physchem(PhysChem.openbabel_descriptors).size
+ assert_equal PhysChem::unique_descriptors.size, c.physchem(PhysChem.unique_descriptors).size
end
end