summaryrefslogtreecommitdiff
path: root/test/fminer.rb
blob: 663aa0373bf2bb667fe1d2cd340d65b99e1c8038 (plain)
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
require_relative "setup.rb"

class FminerTest < MiniTest::Test

  def test_fminer_bbrc
    dataset = OpenTox::Dataset.new
    dataset.upload File.join(DATA_DIR,"hamster_carcinogenicity.csv")
    refute_nil dataset.id

    feature_dataset = OpenTox::Algorithm::Fminer.bbrc :dataset => dataset
    # TODO do we need tasks here?
    #task = OpenTox::Algorithm::Fminer.bbrc :dataset => dataset#.uri
    #task.wait
    #feature_dataset = task.result
    #p task.code
    #p feature_dataset.features
    assert_equal dataset.compounds.size, feature_dataset.compounds.size
    assert_equal 54, feature_dataset.features.size
    assert_equal '[#6&A]-[#6&A]-[#6&A]=[#6&A]', feature_dataset.features.first.title
    compounds = feature_dataset.compounds
    smarts = feature_dataset.features.collect{|f| f.smarts}
    match = OpenTox::Algorithm::Descriptor.smarts_match compounds, smarts
    compounds.each_with_index do |c,i|
      smarts.each_with_index do |s,j|
        assert_equal match[i][j], feature_dataset.data_entries[i][j].to_i
      end
    end

    dataset.delete
    feature_dataset.delete
  end

  def test_fminer_last
    dataset = OpenTox::Dataset.new
    dataset.upload File.join(DATA_DIR,"hamster_carcinogenicity.csv")
    feature_dataset = OpenTox::Algorithm::Fminer.last :dataset => dataset
    assert_equal dataset.compounds.size, feature_dataset.compounds.size
    assert_equal 21, feature_dataset.features.size
    assert_equal '[#6&A]-[#6&a]:[#6&a]:[#6&a]:[#6&a]:[#6&a]', feature_dataset.features.first.smarts

    compounds = feature_dataset.compounds
    smarts = feature_dataset.features.collect{|f| f.smarts}
    match = OpenTox::Algorithm::Descriptor.smarts_match compounds, smarts
    compounds.each_with_index do |c,i|
      smarts.each_with_index do |s,j|
        assert_equal match[i][j], feature_dataset.data_entries[i][j].to_i
      end
    end

    dataset.delete
    feature_dataset.delete
  end

end