immunoscore_results_aggregator 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +47 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/bin/immunoscore_cli.rb +76 -0
- data/config.rb +14 -0
- data/data_struct.rb +280 -0
- data/docs/aggregator.html +200 -0
- data/docs/analyzer.html +1121 -0
- data/docs/data_struct.html +504 -0
- data/docs/database_connection.html +93 -0
- data/docs/docco.css +506 -0
- data/docs/exporter.html +216 -0
- data/docs/immunoscore_results_loader.html +485 -0
- data/docs/public/fonts/aller-bold.eot +0 -0
- data/docs/public/fonts/aller-bold.ttf +0 -0
- data/docs/public/fonts/aller-bold.woff +0 -0
- data/docs/public/fonts/aller-light.eot +0 -0
- data/docs/public/fonts/aller-light.ttf +0 -0
- data/docs/public/fonts/aller-light.woff +0 -0
- data/docs/public/fonts/novecento-bold.eot +0 -0
- data/docs/public/fonts/novecento-bold.ttf +0 -0
- data/docs/public/fonts/novecento-bold.woff +0 -0
- data/docs/public/stylesheets/normalize.css +375 -0
- data/docs/semicolon_cleaner.html +231 -0
- data/immunoscore_results_aggregator.gemspec +32 -0
- data/immunoscore_results_aggregator.rb +9 -0
- data/lib/analyzer.rb +664 -0
- data/lib/data_struct.rb +280 -0
- data/lib/database_connection.rb +4 -0
- data/lib/exporter.rb +76 -0
- data/lib/immunoscore_results_aggregator/version.rb +3 -0
- data/lib/immunoscore_results_loader.rb +218 -0
- data/lib/mongo_aggregator.rb +106 -0
- data/lib/semicolon_cleaner.rb +68 -0
- data/license.txt +21 -0
- metadata +243 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (4.1.6)
|
5
|
+
activesupport (= 4.1.6)
|
6
|
+
builder (~> 3.1)
|
7
|
+
activesupport (4.1.6)
|
8
|
+
i18n (~> 0.6, >= 0.6.9)
|
9
|
+
json (~> 1.7, >= 1.7.7)
|
10
|
+
minitest (~> 5.1)
|
11
|
+
thread_safe (~> 0.1)
|
12
|
+
tzinfo (~> 1.1)
|
13
|
+
bicrypt (1.2.0)
|
14
|
+
bson (1.11.1)
|
15
|
+
bson_ext (1.11.1)
|
16
|
+
bson (~> 1.11.1)
|
17
|
+
builder (3.2.2)
|
18
|
+
chronic (0.10.2)
|
19
|
+
gibberish (1.4.0)
|
20
|
+
i18n (0.6.11)
|
21
|
+
json (1.8.1)
|
22
|
+
minitest (5.4.2)
|
23
|
+
mongo (1.11.1)
|
24
|
+
bson (= 1.11.1)
|
25
|
+
mongo_mapper (0.13.0)
|
26
|
+
activemodel (>= 3.0.0)
|
27
|
+
activesupport (>= 3.0)
|
28
|
+
mongo (~> 1.8)
|
29
|
+
plucky (~> 0.6.5)
|
30
|
+
plucky (0.6.6)
|
31
|
+
mongo (~> 1.5)
|
32
|
+
thor (0.19.1)
|
33
|
+
thread_safe (0.3.4)
|
34
|
+
tzinfo (1.2.2)
|
35
|
+
thread_safe (~> 0.1)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bicrypt
|
42
|
+
bson_ext
|
43
|
+
bundler
|
44
|
+
chronic
|
45
|
+
gibberish
|
46
|
+
mongo_mapper
|
47
|
+
thor
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
immunoscore_results_aggregator
|
2
|
+
===========================
|
3
|
+
|
4
|
+
|
5
|
+
- Extracts and aggregates results from the definiens immunoscore plugin to enable validation of region of interest selection and of hotspots
|
6
|
+
- Uploads results to a nosql database (mongodb)
|
7
|
+
|
8
|
+
Enables exporting of results as:
|
9
|
+
|
10
|
+
- Properly structured data directory containing essential files for review
|
11
|
+
- As a CSV statistics summary file containing datasets for further analysis (e.g. R)
|
12
|
+
|
13
|
+
|
14
|
+
### Mongodb datastructure
|
15
|
+
|
16
|
+
####Example of immunoscore qa/qc entries:
|
17
|
+
|
18
|
+
<img src='https://notationalvelocity.s3.amazonaws.com/1-2014-09-24-11-05-11--0700.png?AWSAccessKeyId=AKIAIHNTWDGBIXEE6HEA&Signature=pXx5128pctDb72XDfTru2QcNCCU%3D&Expires=2042733911' width=' ' height=' '> </img>
|
19
|
+
|
20
|
+
|
21
|
+
#### Example of data structure of each entry:
|
22
|
+
|
23
|
+
<img src='https://notationalvelocity.s3.amazonaws.com/3-2014-09-24-11-14-16--0700.png?AWSAccessKeyId=AKIAIHNTWDGBIXEE6HEA&Signature=DqQgv7WcgCbtjzh0g51dEUx75y8%3D&Expires=2042734457' width=' ' height=' '> </img>
|
24
|
+
|
25
|
+
Each entry contains file paths, a binary blob of the relevant snapshot, case number and relevant annotation.
|
26
|
+
|
27
|
+
|
28
|
+
Requirements
|
29
|
+
===========
|
30
|
+
*nix
|
31
|
+
ruby >= 1.9.3
|
32
|
+
mongodb
|
33
|
+
|
34
|
+
Installation
|
35
|
+
=========
|
36
|
+
gem install immunoscore_results_aggregator
|
37
|
+
|
38
|
+
|
39
|
+
Setup
|
40
|
+
=====
|
41
|
+
|
42
|
+
Edit config.rb to setup the root of the immunoscore directory tree, choose a mongodb name, and a name for the results export directory
|
43
|
+
|
44
|
+
immunoscore_cli.rb show_config
|
45
|
+
immunoscore_cli.rb edit_config
|
46
|
+
|
47
|
+
<img src='https://notationalvelocity.s3.amazonaws.com/4-2014-09-24-12-02-23--0700.png?AWSAccessKeyId=AKIAIHNTWDGBIXEE6HEA&Signature=R8oDkvDRMRCMZ5hgRFxNQ5pykTI%3D&Expires=2042737344' width=' ' height=' '> </img>
|
48
|
+
|
49
|
+
Run
|
50
|
+
====
|
51
|
+
|
52
|
+
immunoscore_cli.rb
|
53
|
+
Follow help intructions
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require "yaml"
|
4
|
+
require_relative "../immunoscore_results_aggregator"
|
5
|
+
#!/usr/bin/env ruby
|
6
|
+
# coding: utf-8
|
7
|
+
|
8
|
+
|
9
|
+
require "thor"
|
10
|
+
require "date"
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
def check_config
|
15
|
+
raise "cannot find definiens base directory. please check and edit configuration file" unless Dir.exists? BASE_DIR
|
16
|
+
Dir.mkdir config["export_dir"] unless Dir.exists? EXPORT_DIR
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
class CliSummary < Thor # [1]
|
21
|
+
package_name "Cli Summary" # [2]
|
22
|
+
#map "-L" => :list # [3]
|
23
|
+
|
24
|
+
# desc "install APP_NAME", "install one of the available apps" # [4]
|
25
|
+
# method_options :force => :boolean, :alias => :string # [5]
|
26
|
+
# def install(name)
|
27
|
+
# user_alias = options[:alias]
|
28
|
+
# if options.force?
|
29
|
+
# # do something
|
30
|
+
# end
|
31
|
+
# # other code
|
32
|
+
# end
|
33
|
+
|
34
|
+
# desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
|
35
|
+
# def list(search="")
|
36
|
+
# # list everything
|
37
|
+
# end
|
38
|
+
desc "export_summary_csv [N]", "merges and exports all stat results; export filename as an argument "
|
39
|
+
def export_summary_csv all_results_file_name="all_definiens_results_#{Date.today.to_s}.csv"
|
40
|
+
write_stats_csv all_results_file_name
|
41
|
+
puts "\n\n\n"
|
42
|
+
puts "Results are available in #{all_results_file_name}"
|
43
|
+
puts "\n\n\n"
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "upload_data", "uploads definines immunoscore directory into mongo; no arguments"
|
48
|
+
def upload_data
|
49
|
+
check_config
|
50
|
+
mongo_load_all
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "export_data_struct", "exports data structure of all uploaded datasets; no arguments"
|
54
|
+
def export_data_struct
|
55
|
+
check_config
|
56
|
+
export_mongo
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "show_config", "shows config filepath; no arguments"
|
60
|
+
def show_config
|
61
|
+
ShowConfig.show_config
|
62
|
+
end
|
63
|
+
desc "edit config", "edit config file; no argumens"
|
64
|
+
def edit_config
|
65
|
+
begin
|
66
|
+
`emacs #{ShowConfig.show_config}`
|
67
|
+
rescue
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
CliSummary.start(ARGV)
|
data/config.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# export destination directory for reformatted immunoscore results
|
2
|
+
EXPORT_DIR= "/Users/carlobifulco/Desktop/fda_amp"
|
3
|
+
|
4
|
+
# source immunoscore directory
|
5
|
+
BASE_DIR= "/Users/carlobifulco/Desktop/fda_amp"
|
6
|
+
# data base name
|
7
|
+
DATABASE_NAME= "immunoscore_results_aggregator"
|
8
|
+
|
9
|
+
module ShowConfig
|
10
|
+
def self.show_config
|
11
|
+
puts "PATH: #{File.absolute_path(__FILE__)}"
|
12
|
+
File.absolute_path(__FILE__)
|
13
|
+
end
|
14
|
+
end
|
data/data_struct.rb
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
#Copyright (c) 2014, Carlo B. Bifulco. All rights reserved.
|
2
|
+
|
3
|
+
require_relative "analyzer"
|
4
|
+
require_relative "immunoscore_results_loader"
|
5
|
+
|
6
|
+
require_relative "database_connection"
|
7
|
+
|
8
|
+
# module Show
|
9
|
+
# def show file_path=self.path
|
10
|
+
# tf=Tempfile.new ["temp",File.extname(file_path)]
|
11
|
+
# tf.write (File.read file_path)
|
12
|
+
# tf.close
|
13
|
+
# puts "#{tf.path}"
|
14
|
+
# fork do
|
15
|
+
# `open #{tf.path}`
|
16
|
+
|
17
|
+
# end
|
18
|
+
# puts Process.waitall
|
19
|
+
# tf.unlink
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
|
23
|
+
### Enables all Mongo classes listed below to have instances capable their own CD quicly
|
24
|
+
module CdIncluder
|
25
|
+
def get_cd
|
26
|
+
puts self.cd_type
|
27
|
+
if (self.cd_type and self.case_n) != nil
|
28
|
+
cd= Cd.get(self.cd_type, self.case_n)
|
29
|
+
end
|
30
|
+
puts cd
|
31
|
+
if cd
|
32
|
+
self.cd=cd
|
33
|
+
end
|
34
|
+
self.save
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
### enables loading and showing of binary datatsets
|
39
|
+
module BinManager
|
40
|
+
def load_bin
|
41
|
+
self.data_load=File.read path
|
42
|
+
end
|
43
|
+
|
44
|
+
def show graphic_data=self.data_load
|
45
|
+
tf=Tempfile.new ["temp",".jpg"]
|
46
|
+
tf.write graphic_data
|
47
|
+
tf.close
|
48
|
+
puts "#{tf.path}"
|
49
|
+
fork do
|
50
|
+
`open #{tf.path}`
|
51
|
+
end
|
52
|
+
Process.wait
|
53
|
+
tf.unlink
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class ImmunoScoreResults
|
58
|
+
include MongoMapper::Document
|
59
|
+
include DataUtilities
|
60
|
+
safe
|
61
|
+
timestamps!
|
62
|
+
many :cd
|
63
|
+
key :case_n, String
|
64
|
+
|
65
|
+
def self.get case_n
|
66
|
+
self.find_by_case_n(case_n) or self.create(:case_n=>case_n)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
class Cd
|
73
|
+
include MongoMapper::Document
|
74
|
+
include DataUtilities
|
75
|
+
safe
|
76
|
+
timestamps!
|
77
|
+
belongs_to :immuno_score_results
|
78
|
+
key :cd_type, String
|
79
|
+
key :case_n, String
|
80
|
+
many :ct_tile
|
81
|
+
many :im_tile
|
82
|
+
many :statistic
|
83
|
+
many :classification
|
84
|
+
many :original
|
85
|
+
many :density
|
86
|
+
many :histogram
|
87
|
+
|
88
|
+
#either get a brand new cd with its own Immunoscore Results instance of find a preexisting one
|
89
|
+
def self.get cd_type, case_n
|
90
|
+
self.find_by_cd_type_and_case_n(cd_type,case_n) or self.create(:case_n=>case_n,
|
91
|
+
:cd_type=>cd_type,
|
92
|
+
:immuno_score_results_id=>ImmunoScoreResults.get(case_n)._id)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
# {:cd=>"CD3",
|
100
|
+
# :path=>
|
101
|
+
# "/Volumes/LaCie/patient 1-5/patient 1-5/results/RS_SM02-2576-A4_CD3_2013-11-01 16_52_41.image_0000006553/View_Exports
|
102
|
+
# :tile=>"CT2",
|
103
|
+
# :case_n=>"SM02-2576-A4",
|
104
|
+
# :type=>:ct_tile}}
|
105
|
+
|
106
|
+
class CtTile
|
107
|
+
include MongoMapper::Document
|
108
|
+
include DataUtilities
|
109
|
+
include CdIncluder
|
110
|
+
include BinManager
|
111
|
+
extend ClassDataUtilities
|
112
|
+
safe
|
113
|
+
timestamps!
|
114
|
+
belongs_to :cd
|
115
|
+
key :tile, String
|
116
|
+
key :path, String
|
117
|
+
key :case_n, String
|
118
|
+
key :cd_type, String
|
119
|
+
key :data_load, Binary
|
120
|
+
before_save :load_bin
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
class ImTile
|
126
|
+
include MongoMapper::Document
|
127
|
+
include DataUtilities
|
128
|
+
include CdIncluder
|
129
|
+
include BinManager
|
130
|
+
extend ClassDataUtilities
|
131
|
+
safe
|
132
|
+
timestamps!
|
133
|
+
belongs_to :cd
|
134
|
+
key :tile, String
|
135
|
+
key :path, String
|
136
|
+
key :case_n, String
|
137
|
+
key :cd_type, String
|
138
|
+
key :data_load, Binary
|
139
|
+
before_save :load_bin
|
140
|
+
end
|
141
|
+
|
142
|
+
# {:case=>"SM02-2456-A6",
|
143
|
+
# :cd=>"CD8",
|
144
|
+
# :path=>
|
145
|
+
# "/Volumes/LaCie/patient 1-5/patient 1-5/results/RS_SM02-2456-A6_CD8_2013-11-01 14_27_27.image_0000006515/image_000000
|
146
|
+
# :type=>:classification},
|
147
|
+
class Classification
|
148
|
+
include MongoMapper::Document
|
149
|
+
include DataUtilities
|
150
|
+
include CdIncluder
|
151
|
+
include BinManager
|
152
|
+
extend ClassDataUtilities
|
153
|
+
safe
|
154
|
+
timestamps!
|
155
|
+
belongs_to :cd
|
156
|
+
key :path, String
|
157
|
+
key :case_n, String
|
158
|
+
key :cd_type, String
|
159
|
+
key :data_load, Binary
|
160
|
+
before_save :load_bin
|
161
|
+
end
|
162
|
+
|
163
|
+
class Original
|
164
|
+
include MongoMapper::Document
|
165
|
+
include DataUtilities
|
166
|
+
include CdIncluder
|
167
|
+
include BinManager
|
168
|
+
extend ClassDataUtilities
|
169
|
+
safe
|
170
|
+
timestamps!
|
171
|
+
belongs_to :cd
|
172
|
+
key :path, String
|
173
|
+
key :case_n, String
|
174
|
+
key :cd_type, String
|
175
|
+
key :data_load, Binary
|
176
|
+
before_save :load_bin
|
177
|
+
end
|
178
|
+
|
179
|
+
# {:case=>"RS_SM02-2576-A4_CD3_2013-11-01 16_52_41.image_0000006553",
|
180
|
+
# :path=>
|
181
|
+
# "/Volumes/LaCie/patient 1-5/patient 1-5/results/RS_SM02-2576-A4_CD3_2013-11-01 16_52_41.image_0000006553/Statistic_Exports/RS_SM02-2576-A4_CD3_2013-11-01 16_52_41.image_0000006553_Statistics.csv",
|
182
|
+
# :cd=>"CD3",
|
183
|
+
# :type=>:statistics}
|
184
|
+
|
185
|
+
class Statistic
|
186
|
+
include MongoMapper::Document
|
187
|
+
include DataUtilities
|
188
|
+
include CdIncluder
|
189
|
+
include BinManager
|
190
|
+
extend ClassDataUtilities
|
191
|
+
safe
|
192
|
+
timestamps!
|
193
|
+
belongs_to :cd
|
194
|
+
key :path, String
|
195
|
+
key :case_n, String
|
196
|
+
key :cd_type, String
|
197
|
+
key :data_load, Binary
|
198
|
+
before_save :load_bin
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
# {:path=>
|
203
|
+
# "/Volumes/LaCie/patient 1-5/patient 1-5/results/RS_SM02-2576-A4_CD3_2013-11-01 16_52_41.image_0000006553/View_Exports
|
204
|
+
# :case=>"SM02-2576-A4",
|
205
|
+
# :new_old=>"old",
|
206
|
+
# :cd=>"CD3",
|
207
|
+
# :type=>"density"}
|
208
|
+
class Density
|
209
|
+
include MongoMapper::Document
|
210
|
+
include DataUtilities
|
211
|
+
include CdIncluder
|
212
|
+
include BinManager
|
213
|
+
extend ClassDataUtilities
|
214
|
+
safe
|
215
|
+
timestamps!
|
216
|
+
belongs_to :cd
|
217
|
+
key :path, String
|
218
|
+
key :case_n, String
|
219
|
+
key :cd_type, String
|
220
|
+
key :new_old, String
|
221
|
+
key :data_load, Binary
|
222
|
+
before_save :load_bin
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
# {:path=>
|
227
|
+
# "/Volumes/LaCie/patient 1-5/patient 1-5/results/RS_SM02-2366-A5_CD8_2013-11-01 16_55_57.image_0000006556/View_Exports
|
228
|
+
# :case=>"SM02-2366-A5",
|
229
|
+
# :type=>:histogram,
|
230
|
+
# :cd=>"CD8"}
|
231
|
+
class Histogram
|
232
|
+
include MongoMapper::Document
|
233
|
+
include DataUtilities
|
234
|
+
include CdIncluder
|
235
|
+
include BinManager
|
236
|
+
extend ClassDataUtilities
|
237
|
+
safe
|
238
|
+
timestamps!
|
239
|
+
belongs_to :cd
|
240
|
+
key :path, String
|
241
|
+
key :case_n, String
|
242
|
+
key :cd_type, String
|
243
|
+
key :data_load, Binary
|
244
|
+
before_save :load_bin
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
class Test
|
249
|
+
include MongoMapper::Document
|
250
|
+
include DataUtilities
|
251
|
+
include CdIncluder
|
252
|
+
include BinManager
|
253
|
+
extend ClassDataUtilities
|
254
|
+
|
255
|
+
key :path, String
|
256
|
+
|
257
|
+
key :data_load, Binary
|
258
|
+
before_save :load_bin
|
259
|
+
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
### mapping from definiens file type to proper database entity
|
266
|
+
JSON_CLASS_MAPPER={:ct_tile=>CtTile,
|
267
|
+
:im_tile=>ImTile,
|
268
|
+
:classification=>Classification,
|
269
|
+
:original=>Original,
|
270
|
+
:statistic=>Statistic,
|
271
|
+
:density=>Density,
|
272
|
+
:histogram=>Histogram}
|
273
|
+
|
274
|
+
|
275
|
+
### resets all databases
|
276
|
+
def mm_clean_all
|
277
|
+
[ImmunoScoreResults, Cd, Histogram, Density, Statistic, Original, Classification, ImTile, CtTile].each do |mm_class|
|
278
|
+
mm_class.delete_all
|
279
|
+
end
|
280
|
+
end
|