rocker 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +8 -8
- data/Rakefile +0 -1
- data/ext/{rocker → rockerxx}/auc_info.h +0 -0
- data/ext/{rocker → rockerxx}/constants.h +0 -0
- data/ext/{rocker → rockerxx}/extconf.rb +2 -2
- data/ext/{rocker → rockerxx}/fetcher.h +34 -12
- data/ext/{rocker → rockerxx}/line_input_iterator.h +0 -0
- data/ext/{rocker/rocker.cpp → rockerxx/rockerxx.cpp} +5 -5
- data/ext/{rocker/rocker.h → rockerxx/rockerxx.h} +34 -32
- data/ext/{rocker → rockerxx}/updater.h +12 -14
- data/lib/rocker.rb +13 -3
- data/test/test_rocker_extn.rb +6 -7
- metadata +12 -12
data/Manifest.txt
CHANGED
@@ -9,11 +9,11 @@ script/destroy
|
|
9
9
|
script/generate
|
10
10
|
test/test_helper.rb
|
11
11
|
test/test_rocker.rb
|
12
|
-
ext/
|
13
|
-
ext/
|
14
|
-
ext/
|
15
|
-
ext/
|
16
|
-
ext/
|
17
|
-
ext/
|
18
|
-
ext/
|
19
|
-
ext/
|
12
|
+
ext/rockerxx/extconf.rb
|
13
|
+
ext/rockerxx/auc_info.h
|
14
|
+
ext/rockerxx/constants.h
|
15
|
+
ext/rockerxx/fetcher.h
|
16
|
+
ext/rockerxx/updater.h
|
17
|
+
ext/rockerxx/line_input_iterator.h
|
18
|
+
ext/rockerxx/rockerxx.h
|
19
|
+
ext/rockerxx/rockerxx.cpp
|
data/Rakefile
CHANGED
@@ -14,7 +14,6 @@ $hoe = Hoe.spec 'rocker' do
|
|
14
14
|
self.developer 'John Woods', 'john.woods@marcottelab.org'
|
15
15
|
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
16
|
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
17
|
-
|
18
17
|
end
|
19
18
|
|
20
19
|
require 'newgem/tasks'
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'mkmf-rice'
|
3
3
|
|
4
|
-
dir_config("
|
4
|
+
dir_config("rockerxx")
|
5
5
|
dir_config("boost")
|
6
6
|
|
7
7
|
have_library("stdc++")
|
@@ -12,4 +12,4 @@ if RUBY_VERSION =~ /1.9/ then
|
|
12
12
|
$CPPFLAGS += " -DRUBY_19"
|
13
13
|
end
|
14
14
|
|
15
|
-
create_makefile('
|
15
|
+
create_makefile('rockerxx')
|
@@ -1,9 +1,11 @@
|
|
1
1
|
#include <iostream>
|
2
2
|
#include <set>
|
3
3
|
#include <vector>
|
4
|
+
#include <map>
|
4
5
|
#include <string>
|
5
6
|
#include <sstream>
|
6
7
|
#include <pqxx/transactor.hxx>
|
8
|
+
#include <pqxx/nontransaction.hxx>
|
7
9
|
#include <pqxx/result.hxx>
|
8
10
|
|
9
11
|
using std::cout;
|
@@ -11,42 +13,49 @@ using std::cerr;
|
|
11
13
|
using std::endl;
|
12
14
|
using std::set;
|
13
15
|
using std::vector;
|
16
|
+
using std::map;
|
14
17
|
using std::string;
|
15
18
|
using std::ostringstream;
|
16
19
|
using pqxx::transactor;
|
20
|
+
using pqxx::nontransaction;
|
17
21
|
using pqxx::result;
|
18
22
|
|
19
23
|
typedef unsigned int uint;
|
20
24
|
|
21
25
|
|
22
|
-
class Fetcher : public transactor
|
26
|
+
class Fetcher : public transactor<nontransaction> {
|
23
27
|
public:
|
24
|
-
Fetcher(
|
28
|
+
Fetcher(uint m_id, map<uint, set<uint> >* known)
|
29
|
+
: transactor<nontransaction>("Fetcher"), matrix_id(m_id), known_correct(known)
|
30
|
+
{
|
31
|
+
cerr << "Constructed" << endl;
|
32
|
+
}
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
34
|
+
Fetcher(const Fetcher& rhs)
|
35
|
+
: query(rhs.query), matrix_id(rhs.matrix_id), known_correct(rhs.known_correct)
|
36
|
+
{
|
37
|
+
cerr << "Copy constructed" << endl;
|
38
|
+
}
|
39
|
+
|
40
|
+
~Fetcher() {
|
41
|
+
cerr << "De-allocate" << endl;
|
42
|
+
}
|
30
43
|
|
31
44
|
void operator()(argument_type &T) {
|
32
45
|
result R;
|
33
|
-
query = make_known_correct_query()
|
46
|
+
query = make_known_correct_query();
|
34
47
|
|
35
48
|
try {
|
36
49
|
R = T.exec(query);
|
37
50
|
|
38
|
-
vector< set<uint> > known(R.size());
|
39
|
-
|
40
51
|
// Get the row and add it to the results set
|
41
52
|
for (result::const_iterator it = R.begin(); it != R.end(); ++it) {
|
42
53
|
uint i; uint j;
|
43
54
|
(*it)[1].to(j); // Get column
|
44
55
|
(*it)[2].to(i); // Get gene
|
45
|
-
|
56
|
+
(*known_correct)[j].insert(i);
|
46
57
|
}
|
47
58
|
|
48
|
-
known_correct = known;
|
49
|
-
|
50
59
|
} catch (pqxx::sql_error e) {
|
51
60
|
cerr << "SQL error in Fetcher transactor." << endl;
|
52
61
|
cerr << "Query: " << e.query() << endl;
|
@@ -54,7 +63,20 @@ public:
|
|
54
63
|
}
|
55
64
|
}
|
56
65
|
|
66
|
+
set<uint>& operator[](size_t idx) {
|
67
|
+
return (*known_correct)[idx];
|
68
|
+
}
|
69
|
+
|
70
|
+
set<uint> operator[](size_t idx) const {
|
71
|
+
return (*known_correct).find(idx)->second;
|
72
|
+
}
|
73
|
+
|
57
74
|
protected:
|
75
|
+
string query;
|
76
|
+
uint matrix_id;
|
77
|
+
|
78
|
+
map<uint, set<uint> >* known_correct;
|
79
|
+
|
58
80
|
string make_known_correct_query() const {
|
59
81
|
ostringstream q;
|
60
82
|
q << "SELECT id, j, i FROM entries WHERE matrix_id = " << matrix_id
|
File without changes
|
@@ -33,7 +33,7 @@ using std::cout;
|
|
33
33
|
using std::endl;
|
34
34
|
using namespace Rice;
|
35
35
|
|
36
|
-
#include "
|
36
|
+
#include "rockerxx.h"
|
37
37
|
|
38
38
|
//#include "line_input_iterator.h"
|
39
39
|
|
@@ -41,15 +41,15 @@ typedef LineInputIterator<std::string> line_input_iterator;
|
|
41
41
|
|
42
42
|
|
43
43
|
extern "C"
|
44
|
-
void
|
44
|
+
void Init_rockerxx() {
|
45
45
|
|
46
46
|
// Expose Rocker class to Ruby
|
47
47
|
//database_string dbarg(DBNAME, USER, PASSWORD);
|
48
|
-
Data_Type<Rocker>
|
49
|
-
define_class<Rocker>("
|
48
|
+
Data_Type<Rocker> rb_cRockerxx =
|
49
|
+
define_class<Rocker>("Rockerxx")
|
50
50
|
.define_constructor(Constructor<Rocker,std::string,uint,uint>())
|
51
51
|
.define_method("process_results", &Rocker::process_results)
|
52
|
-
.define_method("
|
52
|
+
.define_method("fetch_column", &Rocker::fetch_column, (Arg("j")))
|
53
53
|
.define_method("calculate_statistic",
|
54
54
|
&Rocker::calculate_statistic,
|
55
55
|
(Arg("j"), Arg("threshold") = (double)(0.0)))
|
@@ -46,38 +46,39 @@ class Rocker {
|
|
46
46
|
public:
|
47
47
|
|
48
48
|
// Connect to the database and create the read transaction
|
49
|
-
Rocker(string dbarg, uint m_id, uint e_id)
|
49
|
+
Rocker(string dbarg, uint m_id, uint e_id)
|
50
|
+
: c(dbarg), known_(new map<uint, set<uint> >), fetch(m_id, known_), update(e_id)
|
51
|
+
{
|
50
52
|
// Make sure the fetcher knows which matrix to restrict queries to.
|
51
|
-
fetcher.matrix_id = m_id;
|
53
|
+
// fetcher.matrix_id = m_id;
|
52
54
|
|
53
55
|
// Set up a transaction
|
54
|
-
action = new pqxx::transaction<>(c, READ_TRANSACTION);
|
56
|
+
// action = new pqxx::transaction<>(c, READ_TRANSACTION);
|
55
57
|
|
56
|
-
|
58
|
+
c.perform(fetch);
|
59
|
+
// fetcher(*action); // Perform the fetch.
|
57
60
|
|
58
|
-
delete action;
|
61
|
+
// delete action;
|
62
|
+
update.aucs = process_results();
|
59
63
|
|
60
|
-
|
61
|
-
|
64
|
+
c.perform(update);
|
65
|
+
// action = new pqxx::transaction<>(c, WRITE_TRANSACTION);
|
62
66
|
|
63
|
-
|
67
|
+
// updater(*action);
|
64
68
|
|
65
|
-
|
66
|
-
|
67
|
-
// Make sure to actually save the results.
|
68
|
-
action->commit();
|
69
|
-
|
70
|
-
delete action;
|
69
|
+
// delete action;
|
71
70
|
}
|
72
71
|
|
73
72
|
|
74
73
|
//
|
75
|
-
~Rocker() {
|
74
|
+
~Rocker() {
|
75
|
+
delete known_;
|
76
|
+
}
|
76
77
|
|
77
78
|
|
78
79
|
// Return the mean AUC calculated -- requires that process_results was called,
|
79
80
|
// which happens in the constructor, so it's okay.
|
80
|
-
double mean_auc() { return
|
81
|
+
double mean_auc() { return update.mean_auc; }
|
81
82
|
|
82
83
|
// Go through the results directory
|
83
84
|
map<uint,auc_info> process_results() {
|
@@ -102,24 +103,32 @@ public:
|
|
102
103
|
|
103
104
|
// Calculate the mean AUC
|
104
105
|
if (divide_by > 0)
|
105
|
-
|
106
|
+
update.mean_auc = temp_auc_accum / (double)(divide_by);
|
106
107
|
else
|
107
|
-
|
108
|
+
update.mean_auc = 0;
|
108
109
|
|
109
110
|
return rocs;
|
110
111
|
}
|
111
112
|
|
112
113
|
|
113
114
|
// Get genes with a specific phenotype association (phenotype id = j).
|
114
|
-
set<uint>
|
115
|
-
return
|
115
|
+
set<uint> fetch_column(uint j) const {
|
116
|
+
return (*known_)[j];
|
116
117
|
}
|
117
118
|
|
118
119
|
|
119
120
|
// For some phenotype j, determine AUC, fp, tp, fn, tn, etc.
|
120
121
|
auc_info calculate_statistic(uint j, double threshold = 0.0) const {
|
121
|
-
set<uint> known_correct =
|
122
|
+
set<uint> known_correct = fetch_column(j);
|
122
123
|
gene_score_list candidates = read_candidates(j);
|
124
|
+
auc_info result;
|
125
|
+
|
126
|
+
if (known_correct.size() == 0) {
|
127
|
+
result.auc = 0;
|
128
|
+
return result;
|
129
|
+
}
|
130
|
+
|
131
|
+
|
123
132
|
//cerr << "Size of known_correct: " << known_correct.size() << endl;
|
124
133
|
|
125
134
|
// Attempted transcription of code from Ruby into C++, after having taken
|
@@ -129,7 +138,7 @@ public:
|
|
129
138
|
t.reserve(candidates.size()+1); t.push_back(0);
|
130
139
|
vector<size_t> f = t;
|
131
140
|
|
132
|
-
|
141
|
+
|
133
142
|
|
134
143
|
for (gene_score_list::const_iterator i = candidates.begin(); i != candidates.end(); ++i) {
|
135
144
|
if (known_correct.find(i->first) != known_correct.end()) {
|
@@ -216,15 +225,8 @@ public:
|
|
216
225
|
|
217
226
|
|
218
227
|
protected:
|
219
|
-
|
220
|
-
uint matrix_id;
|
221
|
-
uint experiment_id;
|
222
|
-
uint current_j;
|
223
228
|
pqxx::connection c;
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
Fetcher fetcher;
|
229
|
-
Updater updater;
|
229
|
+
map<uint, set<uint> >* known_;
|
230
|
+
Fetcher fetch;
|
231
|
+
Updater update;
|
230
232
|
};
|
@@ -45,12 +45,10 @@ typedef unsigned int uint;
|
|
45
45
|
|
46
46
|
class Updater : public transactor <> {
|
47
47
|
public:
|
48
|
-
Updater() : transactor<>("Updater") {}
|
48
|
+
Updater(uint exp_id) : transactor<>("Updater"), experiment_id(exp_id) {}
|
49
49
|
|
50
|
-
uint experiment_id;
|
51
50
|
map<uint,auc_info> aucs;
|
52
51
|
double mean_auc;
|
53
|
-
string insert_query, update_query;
|
54
52
|
|
55
53
|
void operator()(argument_type &T) {
|
56
54
|
result R;
|
@@ -60,19 +58,16 @@ public:
|
|
60
58
|
return;
|
61
59
|
}
|
62
60
|
|
63
|
-
|
64
|
-
update_query = make_update_total_auc_sql().c_str();
|
61
|
+
query = make_insertion_sql() + "\n" + make_update_total_auc_sql();
|
65
62
|
|
66
63
|
try {
|
67
64
|
// Insert the AUCs
|
68
|
-
R = T.exec(insert_query);
|
69
|
-
cout << "Query:" << endl;
|
70
|
-
cout << insert_query << endl;
|
71
|
-
|
72
65
|
// Update the average AUC
|
73
|
-
R = T.exec(
|
66
|
+
R = T.exec(query);
|
74
67
|
cout << "Query:" << endl;
|
75
|
-
cout <<
|
68
|
+
cout << query << endl;
|
69
|
+
|
70
|
+
T.commit();
|
76
71
|
} catch (pqxx::sql_error e) {
|
77
72
|
cerr << "SQL error in Updater transactor." << endl;
|
78
73
|
cerr << "Query: " << e.query() << endl;
|
@@ -82,14 +77,17 @@ public:
|
|
82
77
|
}
|
83
78
|
|
84
79
|
protected:
|
80
|
+
uint experiment_id;
|
81
|
+
string query;
|
82
|
+
|
85
83
|
string make_insertion_sql() const {
|
86
84
|
ostringstream q;
|
87
|
-
q << "INSERT INTO rocs " << AUC_COLUMNS << " VALUES
|
85
|
+
q << "INSERT INTO rocs " << AUC_COLUMNS << " VALUES ";
|
88
86
|
list<string> insertions;
|
89
87
|
for (map<uint,auc_info>::const_iterator i = aucs.begin(); i != aucs.end(); ++i) {
|
90
88
|
insertions.push_back( i->second.entry(experiment_id, i->first) );
|
91
89
|
}
|
92
|
-
q << join(insertions, "
|
90
|
+
q << join(insertions, ", ") << ';';
|
93
91
|
return q.str();
|
94
92
|
}
|
95
93
|
|
@@ -97,6 +95,6 @@ protected:
|
|
97
95
|
ostringstream q;
|
98
96
|
q << "UPDATE experiments SET total_auc = " << mean_auc
|
99
97
|
<< " WHERE experiments.id = " << experiment_id << ';';
|
100
|
-
|
98
|
+
return q.str();
|
101
99
|
}
|
102
100
|
};
|
data/lib/rocker.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
|
4
|
+
# STDERR.puts("__FILE__=#{__FILE__}\ndirname=#{File.dirname(__FILE__)}")
|
5
|
+
# $:.unshift(File.join(File.dirname(__FILE__),'..','ext','rocker'))
|
6
|
+
# STDERR.puts($:)
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
#require 'rockerxx'
|
9
|
+
|
10
|
+
module Rocker
|
11
|
+
VERSION = '0.0.9'
|
12
|
+
DBARGS = "dbname=crossval_development user=jwoods password=youwish1"
|
13
|
+
|
14
|
+
# Calculate AUCs in the current working directory
|
15
|
+
def self.calculate(matrix_id, experiment_id)
|
16
|
+
Rockerxx.new(DBARGS, matrix_id, experiment_id)
|
17
|
+
end
|
8
18
|
end
|
data/test/test_rocker_extn.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
require "test/unit"
|
2
2
|
|
3
|
-
$:.unshift File.dirname(__FILE__) + "/../ext/
|
4
|
-
require "
|
5
|
-
|
6
|
-
def database_string dbn = "crossval_development", u = "jwoods", p = "youwish1"
|
7
|
-
"dbname=#{dbn} user=#{u} password=#{p}"
|
8
|
-
end
|
3
|
+
$:.unshift File.dirname(__FILE__) + "/../ext/rockerxx"
|
4
|
+
require "rockerxx.so"
|
9
5
|
|
10
6
|
class TestRockerExtn < Test::Unit::TestCase
|
11
7
|
def test_working
|
12
|
-
t =
|
8
|
+
t = nil
|
9
|
+
#Dir.chdir("../crossval/tmp/work/matrix_1/experiment_167/results.20100318222010/") do
|
10
|
+
t = Rocker.calculate(1, 167)
|
11
|
+
#end
|
13
12
|
x = t.mean_auc
|
14
13
|
puts "Mean AUC was #{x}"
|
15
14
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Woods
|
@@ -59,7 +59,7 @@ email:
|
|
59
59
|
executables: []
|
60
60
|
|
61
61
|
extensions:
|
62
|
-
- ext/
|
62
|
+
- ext/rockerxx/extconf.rb
|
63
63
|
extra_rdoc_files:
|
64
64
|
- History.txt
|
65
65
|
- Manifest.txt
|
@@ -76,14 +76,14 @@ files:
|
|
76
76
|
- script/generate
|
77
77
|
- test/test_helper.rb
|
78
78
|
- test/test_rocker.rb
|
79
|
-
- ext/
|
80
|
-
- ext/
|
81
|
-
- ext/
|
82
|
-
- ext/
|
83
|
-
- ext/
|
84
|
-
- ext/
|
85
|
-
- ext/
|
86
|
-
- ext/
|
79
|
+
- ext/rockerxx/extconf.rb
|
80
|
+
- ext/rockerxx/auc_info.h
|
81
|
+
- ext/rockerxx/constants.h
|
82
|
+
- ext/rockerxx/fetcher.h
|
83
|
+
- ext/rockerxx/updater.h
|
84
|
+
- ext/rockerxx/line_input_iterator.h
|
85
|
+
- ext/rockerxx/rockerxx.h
|
86
|
+
- ext/rockerxx/rockerxx.cpp
|
87
87
|
has_rdoc: true
|
88
88
|
homepage: http://github.com/MarcotteLabGit/rocker
|
89
89
|
licenses: []
|
@@ -94,7 +94,7 @@ rdoc_options:
|
|
94
94
|
- README.rdoc
|
95
95
|
require_paths:
|
96
96
|
- lib
|
97
|
-
- ext/
|
97
|
+
- ext/rockerxx
|
98
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - ">="
|