Class: Constants
- Inherits:
-
Object
show all
- Defined in:
- lib/protk/constants.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Read the global constants file and initialize our class @env variable Initialize loggers
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
# File 'lib/protk/constants.rb', line 229
def initialize
@data_lib_dir="#{File.dirname(__FILE__)}/data"
@protk_dir="#{Dir.home}/.protk"
if ( ENV['PROTK_INSTALL_DIR']!=nil )
p "Using protk install dir from shell"
@protk_dir=ENV['PROTK_INSTALL_DIR']
end
default_config_yml = YAML.load_file "#{File.dirname(__FILE__)}/data/default_config.yml"
throw "Unable to read the config file at #{File.dirname(__FILE__)}/data/default_config.yml" unless default_config_yml!=nil
user_config_yml = nil
user_config_yml = YAML.load_file "#{@protk_dir}/config.yml" if File.exist? "#{@protk_dir}/config.yml"
if ( user_config_yml !=nil )
@env = default_config_yml.merge user_config_yml
else
@env=default_config_yml
end
protk_roots = ["tpp","omssa","blast","pwiz","msgfplus","openms"]
protk_roots.each do |r|
env_value = ENV["PROTK_#{r.upcase}_ROOT"]
if ( env_value!=nil)
p "Using #{r} root #{env_value}"
@env["#{r}_root"]=env_value
end
end
throw "No data found in config file" unless @env!=nil
@info_level=default_config_yml['message_level']
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
Provides direct access to constants through methods of the same name This will be used for all constants other than paths
37
38
39
|
# File 'lib/protk/constants.rb', line 37
def method_missing(method)
@env[method.to_s]
end
|
Instance Attribute Details
#data_lib_dir ⇒ Object
Returns the value of attribute data_lib_dir.
32
33
34
|
# File 'lib/protk/constants.rb', line 32
def data_lib_dir
@data_lib_dir
end
|
#info_level ⇒ Object
Returns the value of attribute info_level.
30
31
32
|
# File 'lib/protk/constants.rb', line 30
def info_level
@info_level
end
|
#protk_dir ⇒ Object
Returns the value of attribute protk_dir.
31
32
33
|
# File 'lib/protk/constants.rb', line 31
def protk_dir
@protk_dir
end
|
Instance Method Details
#asaprationpvalueparser ⇒ Object
85
86
87
|
# File 'lib/protk/constants.rb', line 85
def asaprationpvalueparser
return "#{self.tpp_root}/bin/ASAPRatioPvalueParser"
end
|
#asapratiopeptideparser ⇒ Object
77
78
79
|
# File 'lib/protk/constants.rb', line 77
def asapratiopeptideparser
return "#{self.tpp_root}/bin/ASAPRatioPeptideParser"
end
|
#asapratioproteinparser ⇒ Object
81
82
83
|
# File 'lib/protk/constants.rb', line 81
def asapratioproteinparser
return "#{self.tpp_root}/bin/ASAPRatioProteinRatioParser"
end
|
#bin ⇒ Object
Some constants are paths. They need to be translated into real paths before being returned
44
45
46
|
# File 'lib/protk/constants.rb', line 44
def bin
return "#{@protk_dir}/bin"
end
|
#blast_root ⇒ Object
199
200
201
202
203
204
205
206
|
# File 'lib/protk/constants.rb', line 199
def blast_root
path=@env['blast_root']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['blast_root']}"
end
end
|
#current_database_for_name(dbname) ⇒ Object
Based on the database shortname and global database path, find the most current version of the required database If dbname corresponds to a folder in the dbroot this function returns the path of the database with an extension appropriate to the database type
If dbname is a full path to a file this tool will first import the file as a temporary database and will then return its full path
329
330
331
332
333
334
335
336
337
338
339
340
341
|
# File 'lib/protk/constants.rb', line 329
def current_database_for_name(dbname)
dbroot=self.protein_database_root
throw "Protein database directory not specified" unless dbroot!=nil
throw "Protein database directory #{dbroot} does not exist" unless Pathname(dbroot).exist?
dbroot.sub!(/(\/*\s*)$/,"")
return path_for_builtin_database(dbname)
end
|
#database_downloads ⇒ Object
195
196
197
|
# File 'lib/protk/constants.rb', line 195
def database_downloads
return "#{self.protein_database_root}/downloads"
end
|
#dbexist?(dbname) ⇒ Boolean
318
319
320
|
# File 'lib/protk/constants.rb', line 318
def dbexist?(dbname)
Pathname.new("#{self.protein_database_root}/#{dbname}").exist?
end
|
#executepipeline ⇒ Object
169
170
171
|
# File 'lib/protk/constants.rb', line 169
def executepipeline
return "#{self.openms_root}/bin/ExecutePipeline"
end
|
#featurefinderisotopewavelet ⇒ Object
165
166
167
|
# File 'lib/protk/constants.rb', line 165
def featurefinderisotopewavelet
return "#{self.openms_root}/bin/FeatureFinderIsotopeWavelet"
end
|
#gpmtandem ⇒ Object
182
183
184
|
# File 'lib/protk/constants.rb', line 182
def gpmtandem
return "#{self.tandem_root}/bin/tandem"
end
|
#idconvert ⇒ Object
148
149
150
|
# File 'lib/protk/constants.rb', line 148
def idconvert
return "#{self.pwiz_root}/idconvert"
end
|
#import_fasta_database(dbroot, path_to_fasta_file) ⇒ Object
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
# File 'lib/protk/constants.rb', line 365
def import_fasta_database(dbroot,path_to_fasta_file)
tmp_dbroot=Pathname.new("#{dbroot}/tmp/")
dest_fasta_file_name=Pathname.new(path_to_fasta_file).basename
dest_fasta_file_path=Pathname.new("#{tmp_dbroot}#{dest_fasta_file_name}")
if ( !dest_fasta_file_path.exist? )
Dir.mkdir(tmp_dbroot) unless tmp_dbroot.exist? && tmp_dbroot.directory?
throw "Unable to make temporary database directory #{tmp_dbroot}" unless tmp_dbroot.exist?
link_cmd = "ln -s #{path_to_fasta_file} #{dest_fasta_file_path}"
result= %x[#{link_cmd}]
p result
end
check_cmd="#{self.ncbi_tools_bin}/blastdbcmd -info -db #{dest_fasta_file_path}"
result = %x[#{check_cmd}]
if ( result=="")
throw "Unable to create temporary database #{dest_fasta_file_path}" unless dest_fasta_file_path.exist?
cmd="#{self.makeblastdb} -in #{dest_fasta_file_path} -parse_seqids"
p cmd
self.run_local(cmd)
end
return dest_fasta_file_path.to_s
end
|
#initialize_loggers ⇒ Object
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# File 'lib/protk/constants.rb', line 280
def initialize_loggers
log_dir = Pathname.new(self.log_file).dirname
log_dir.mkpath unless log_dir.exist?
@stdout_logger=Logger.new(STDOUT)
@file_logger=Logger.new(self.log_file)
throw "Unable to create file logger at path #{self.log_file}" unless @file_logger!=nil
throw "Unable to create stdout logger " unless @stdout_logger!=nil
case @info_level
when "info"
@stdout_logger.level=Logger::INFO
when "debug"
@stdout_logger.level=Logger::DEBUG
when "warn"
@stdout_logger.level=Logger::WARN
end
end
|
#interprophetparser ⇒ Object
69
70
71
|
# File 'lib/protk/constants.rb', line 69
def interprophetparser
return "#{self.tpp_root}/bin/InterProphetParser"
end
|
#librapeptideparser ⇒ Object
89
90
91
|
# File 'lib/protk/constants.rb', line 89
def librapeptideparser
return "#{self.tpp_root}/bin/LibraPeptideParser"
end
|
#libraproteinratioparser ⇒ Object
93
94
95
|
# File 'lib/protk/constants.rb', line 93
def libraproteinratioparser
return "#{self.tpp_root}/bin/LibraProteinRatioParser"
end
|
#log(message, level) ⇒ Object
Write a message to all logger objects
305
306
307
308
309
310
311
|
# File 'lib/protk/constants.rb', line 305
def log(message,level)
if ( @stdout_logger == nil || @file_logger == nil)
initialize_loggers
end
@stdout_logger.send(level,message)
@file_logger.send(level,message)
end
|
#log_file ⇒ Object
216
217
218
219
220
221
222
223
|
# File 'lib/protk/constants.rb', line 216
def log_file
path=@env['log_file']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['log_file']}"
end
end
|
#makeblastdb ⇒ Object
208
209
210
|
# File 'lib/protk/constants.rb', line 208
def makeblastdb
return "#{self.blast_root}/bin/makeblastdb"
end
|
#mascot2xml ⇒ Object
105
106
107
|
# File 'lib/protk/constants.rb', line 105
def mascot2xml
return "#{self.tpp_root}/bin/Mascot2XML"
end
|
#msconvert ⇒ Object
152
153
154
|
# File 'lib/protk/constants.rb', line 152
def msconvert
return "#{self.pwiz_root}/msconvert"
end
|
#msgfplus_root ⇒ Object
126
127
128
129
130
131
132
133
|
# File 'lib/protk/constants.rb', line 126
def msgfplus_root
path=@env['msgfplus_root']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['msgfplus_root']}"
end
end
|
#msgfplusjar ⇒ Object
135
136
137
|
# File 'lib/protk/constants.rb', line 135
def msgfplusjar
return "#{self.msgfplus_root}/MSGFPlus.jar"
end
|
#omssa2pepxml ⇒ Object
122
123
124
|
# File 'lib/protk/constants.rb', line 122
def omssa2pepxml
return "#{self.omssa_root}/omssa2pepXML"
end
|
#omssa_root ⇒ Object
109
110
111
112
113
114
115
116
|
# File 'lib/protk/constants.rb', line 109
def omssa_root
path=@env['omssa_root']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['omssa_root']}"
end
end
|
#omssacl ⇒ Object
118
119
120
|
# File 'lib/protk/constants.rb', line 118
def omssacl
return "#{self.omssa_root}/omssacl"
end
|
#openms_root ⇒ Object
156
157
158
159
160
161
162
163
|
# File 'lib/protk/constants.rb', line 156
def openms_root
path=@env['openms_root']
if ( path =~ /^\//)
return path
else
return "#{@protk_dir}/#{@env['openms_root']}"
end
end
|
#path_for_builtin_database(dbname) ⇒ Object
313
314
315
|
# File 'lib/protk/constants.rb', line 313
def path_for_builtin_database(dbname)
"#{self.protein_database_root}/#{dbname}/current.fasta"
end
|
#protein_database_root ⇒ Object
186
187
188
189
190
191
192
193
|
# File 'lib/protk/constants.rb', line 186
def protein_database_root
path=@env['protein_database_root']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['protein_database_root']}"
end
end
|
#proteinprophet ⇒ Object
73
74
75
|
# File 'lib/protk/constants.rb', line 73
def proteinprophet
return "#{self.tpp_root}/bin/ProteinProphet"
end
|
#pwiz_root ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'lib/protk/constants.rb', line 139
def pwiz_root
path=@env['pwiz_root']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['pwiz_root']}"
end
end
|
#run_local(command_string) ⇒ Object
Runs the given command in a local shell
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
# File 'lib/protk/constants.rb', line 346
def run_local(command_string)
self.log("Command: #{command_string} started",:info)
status = Open4::popen4("#{command_string} ") do |pid, stdin, stdout, stderr|
puts "PID #{pid}"
stdout.each { |line| self.log(line.chomp,:info) }
stderr.each { |line| self.log(line.chomp,:warn) }
end
if ( status!=0 )
self.log( "Command: #{command_string} exited with status #{status.to_s}",:error)
else
self.log( "Command: #{command_string} exited with status #{status.to_s}",:info)
end
status
end
|
#searchblastdb ⇒ Object
212
213
214
|
# File 'lib/protk/constants.rb', line 212
def searchblastdb
return "#{self.blast_root}/bin/blastdbcmd"
end
|
#tandem2xml ⇒ Object
65
66
67
|
# File 'lib/protk/constants.rb', line 65
def tandem2xml
return "#{self.tpp_root}/bin/Tandem2XML"
end
|
#tandem_root ⇒ Object
173
174
175
176
177
178
179
180
|
# File 'lib/protk/constants.rb', line 173
def tandem_root
path=@env['tandem_root']
if ( path =~ /^\//)
return path
else
return "#{@protk_dir}/#{@env['tandem_root']}"
end
end
|
#tpp_root ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/protk/constants.rb', line 48
def tpp_root
path=@env['tpp_root']
if ( path =~ /^\// )
return path
else
return "#{@protk_dir}/#{@env['tpp_root']}"
end
end
|
#update_user_config(dict) ⇒ Object
269
270
271
272
273
274
275
276
277
278
|
# File 'lib/protk/constants.rb', line 269
def update_user_config(dict)
user_config_yml = YAML.load_file "#{self.protk_dir}/config.yml" if File.exist? "#{self.protk_dir}/config.yml"
if ( user_config_yml !=nil )
dict = user_config_yml.merge dict
end
File.open("#{self.protk_dir}/config.yml", "w") {|file| file.puts(dict.to_yaml) }
end
|
#xinteract ⇒ Object
57
58
59
|
# File 'lib/protk/constants.rb', line 57
def xinteract
return "#{self.tpp_root}/bin/xinteract"
end
|
#xpresspeptideparser ⇒ Object
97
98
99
|
# File 'lib/protk/constants.rb', line 97
def xpresspeptideparser
return "#{self.tpp_root}/bin/XPressPeptideParser"
end
|
#xpressproteinratioparser ⇒ Object
101
102
103
|
# File 'lib/protk/constants.rb', line 101
def xpressproteinratioparser
return "#{self.tpp_root}/bin/XPressProteinRatioParser"
end
|
#xtandem ⇒ Object
61
62
63
|
# File 'lib/protk/constants.rb', line 61
def xtandem
return "#{self.tpp_root}/bin/tandem"
end
|