Class: Oncotator
- Inherits:
-
Object
show all
- Defined in:
- lib/oncotator.rb
Defined Under Namespace
Classes: Transcript
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts) ⇒ Oncotator
Returns a new instance of Oncotator.
86
87
88
89
90
91
92
93
|
# File 'lib/oncotator.rb', line 86
def initialize(opts)
if opts[:key]
@mutation = opts[:key]
@onco = get_json_object
elsif opts[:text]
@onco = get_json_object opts[:text]
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/oncotator.rb', line 133
def method_missing(meth,*args,&block)
meth = meth.to_s
case
when @onco[meth]
@onco[meth]
when meth =~ /^txp_(.*)/
txp ? txp.send($1) : nil
else
nil
end
end
|
Instance Attribute Details
#mutation ⇒ Object
Returns the value of attribute mutation.
9
10
11
|
# File 'lib/oncotator.rb', line 9
def mutation
@mutation
end
|
Class Method Details
.db_cache ⇒ Object
22
23
24
25
|
# File 'lib/oncotator.rb', line 22
def self.db_cache
@db ||= Sequel.connect(db_opts)
@db[:onco_json_cache]
end
|
.db_connect(opts) ⇒ Object
14
15
16
|
# File 'lib/oncotator.rb', line 14
def self.db_connect opts
@db_opts = opts
end
|
.db_obj ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/oncotator.rb', line 35
def self.db_obj
if defined? Rails
OncoJsonCache
else
Oncotator.db_cache
end
end
|
.db_opts ⇒ Object
18
19
20
|
# File 'lib/oncotator.rb', line 18
def self.db_opts
@db_opts ||= GermConfig.get_conf :oncotator
end
|
.delete_key(cache_key) ⇒ Object
48
49
50
|
# File 'lib/oncotator.rb', line 48
def self.delete_key cache_key
db_obj.where(:CACHE_KEY => cache_key).delete
end
|
.find_key(cache_key) ⇒ Object
43
44
45
46
|
# File 'lib/oncotator.rb', line 43
def self.find_key cache_key
db_obj.where(:CACHE_KEY => cache_key).first
end
|
.insert_onco(onco) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/oncotator.rb', line 27
def self.insert_onco onco
if defined? Rails
OncoJsonCache.create onco
else
db_cache.insert_ignore.insert onco
end
end
|
.persistent_connection ⇒ Object
10
11
12
|
# File 'lib/oncotator.rb', line 10
def self.persistent_connection
@http ||= Net::HTTP::Persistent.new
end
|
Instance Method Details
#best_canonical_txp ⇒ Object
113
114
115
|
# File 'lib/oncotator.rb', line 113
def best_canonical_txp
@best_canonical_txp ||= Transcript.new(transcripts[best_canonical_transcript]) if best_canonical_transcript
end
|
#best_effect_txp ⇒ Object
109
110
111
|
# File 'lib/oncotator.rb', line 109
def best_effect_txp
@best_effect_txp ||= Transcript.new(transcripts[best_effect_transcript]) if best_effect_transcript
end
|
#empty? ⇒ Boolean
95
96
97
|
# File 'lib/oncotator.rb', line 95
def empty?
!@onco || @onco.size == 0
end
|
#get_json_object(text = nil) ⇒ Object
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
|
# File 'lib/oncotator.rb', line 56
def get_json_object text=nil
json = case text
when nil
result = Oncotator.find_key @mutation
result ? result[:RAW_JSON] : nil
else
text
end
begin
return JSON.parse(json) if json
rescue JSON::ParserError => e
Oncotator.delete_key @mutation
end
response = Oncotator.persistent_connection.request(onco_uri)
return {} if response.code != "200"
json = response.body
Oncotator.insert_onco(:CACHE_KEY => @mutation, :RAW_JSON => json)
return JSON.parse(json)
end
|
#is_cancerous ⇒ Object
129
130
131
|
# File 'lib/oncotator.rb', line 129
def is_cancerous
self.Cosmic_overlapping_mutations || self.CGC_Tumor_Types_Somatic || self.CCLE_ONCOMAP_total_mutations_in_gene
end
|
#is_snp ⇒ Object
117
118
119
|
# File 'lib/oncotator.rb', line 117
def is_snp
dbSNP_RS && dbSNP_Val_Status =~ /(byFrequency|by1000genomes)/
end
|
#onco_uri ⇒ Object
52
53
54
|
# File 'lib/oncotator.rb', line 52
def onco_uri
URI "http://69.173.64.101/oncotator/mutation/#{@mutation}/"
end
|
#pph2_class ⇒ Object
125
126
127
|
# File 'lib/oncotator.rb', line 125
def pph2_class
pph2 ? pph2["pph2_class"] : nil
end
|
#txp ⇒ Object
121
122
123
|
# File 'lib/oncotator.rb', line 121
def txp
best_effect_txp
end
|