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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
require_relative "setup.rb"
class NanoparticleTest < MiniTest::Test
def setup
#Import::Enanomapper.import File.join(File.dirname(__FILE__),"data","enm")
#`mongorestore --db=development #{File.join(File.dirname(__FILE__),"..","dump","production")}`
end
def test_create_model_with_feature_selection
training_dataset = Dataset.find_or_create_by(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles")
feature = Feature.find_or_create_by(name: "Net cell association", category: "TOX", unit: "mL/ug(Mg)")
model = Model::LazarRegression.create(feature, training_dataset, {:prediction_algorithm => "OpenTox::Algorithm::Regression.local_weighted_average", :neighbor_algorithm => "nanoparticle_neighbors", :feature_selection_algorithm => "correlation_filter"})
nanoparticle = training_dataset.nanoparticles[-34]
#p nanoparticle.neighbors
prediction = model.predict nanoparticle
p prediction
#p prediction
refute_nil prediction[:value]
end
def test_create_model
training_dataset = Dataset.find_or_create_by(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles")
feature = Feature.find_or_create_by(name: "Net cell association", category: "TOX", unit: "mL/ug(Mg)")
model = Model::LazarRegression.create(feature, training_dataset, {:prediction_algorithm => "OpenTox::Algorithm::Regression.local_weighted_average", :neighbor_algorithm => "nanoparticle_neighbors"})
nanoparticle = training_dataset.nanoparticles[-34]
prediction = model.predict nanoparticle
refute_nil prediction[:value]
assert_includes nanoparticle.dataset_ids, training_dataset.id
model.delete
end
def test_validate_model
training_dataset = Dataset.find_or_create_by(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles")
feature = Feature.find_or_create_by(name: "Net cell association", category: "TOX", unit: "mL/ug(Mg)")
model = Model::LazarRegression.create(feature, training_dataset, {:prediction_algorithm => "OpenTox::Algorithm::Regression.local_weighted_average", :neighbor_algorithm => "nanoparticle_neighbors", :neighbor_algorithm_parameters => {:min_sim => 0.5}})
cv = RegressionCrossValidation.create model
p cv
File.open("tmp.png","w+"){|f| f.puts cv.correlation_plot}
refute_nil cv.r_squared
refute_nil cv.rmse
end
def test_validate_pls_model
training_dataset = Dataset.find_or_create_by(:name => "Protein Corona Fingerprinting Predicts the Cellular Interaction of Gold and Silver Nanoparticles")
feature = Feature.find_or_create_by(name: "Net cell association", category: "TOX", unit: "mL/ug(Mg)")
model = Model::LazarRegression.create(feature, training_dataset, {:prediction_algorithm => "OpenTox::Algorithm::Regression.local_physchem_regression", :neighbor_algorithm => "nanoparticle_neighbors"})
cv = RegressionCrossValidation.create model
p cv
File.open("tmp.png","w+"){|f| f.puts cv.correlation_plot}
refute_nil cv.r_squared
refute_nil cv.rmse
end
def test_export
Dataset.all.each do |d|
puts d.to_csv
end
end
def test_summaries
datasets = Dataset.all
datasets = datasets.select{|d| !d.name.nil?}
datasets.each do |d|
p d.name
#p d.features.select{|f| f.name.match (/Total/)}
#p d.features.collect{|f| "#{f.name} #{f.unit} #{f.conditions}"}
p d.features.uniq.collect{|f| f.name}
end
assert_equal 9, datasets.size
=begin
skip
features = Feature.all.to_a
#p features.collect do |f|
#f if f.category == "TOX"
#end.to_a.flatten.size
toxcounts = {}
pccounts = {}
Nanoparticle.all.each do |np|
np.toxicities.each do |t,v|
toxcounts[t] ||= 0
toxcounts[t] += 1#v.uniq.size
end
np.physchem_descriptors.each do |t,v|
pccounts[t] ||= 0
pccounts[t] += 1#v.uniq.size
end
end
#puts counts.keys.collect{|i| Feature.find(i)}.to_yaml
#pccounts.each{|e,n| p Feature.find(e),n if n > 100}
#p toxcounts.collect{|e,n| Feature.find(e).name if n > 1}.uniq
toxcounts.each{|e,n| p Feature.find(e),n if n > 100}
=end
end
def test_import_ld
skip
dataset_ids = Import::Enanomapper.import_ld
end
end
|