Class: GalaxyStager

Inherits:
Object
  • Object
show all
Defined in:
lib/protk/galaxy_stager.rb

Overview

A GalaxyStager object represents a single file whose path needs to be staged for use within galaxy

Staging occurs on init and generally involves creating a symlink from the original path to the staged path

By keeping GalaxyStager objects around until script completion it is possible to perform a restore_references operation in script output files.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_path, options = {}) ⇒ GalaxyStager

Initialize and perform staging



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/protk/galaxy_stager.rb', line 18

def initialize(original_path, options = {})
  options = { :name => nil, :extension => '', :force_copy => false }.merge(options)

  @extension = options[:extension]
  @original_path = Pathname.new(original_path)
  @wd = Dir.pwd
  @staged_name = options[:name] || @original_path.basename
  @staged_base_path = File.join(@wd, @staged_name)
  @staged_path = "#{@staged_base_path}#{@extension}"
  if options[:force_copy]
    FileUtils.copy(@original_path, @staged_path)
  else      
    File.symlink(@original_path, @staged_path) unless File.symlink?@staged_path
  end
end

Instance Attribute Details

#staged_base_pathObject

Returns the value of attribute staged_base_path.



14
15
16
# File 'lib/protk/galaxy_stager.rb', line 14

def staged_base_path
  @staged_base_path
end

#staged_pathObject

Returns the value of attribute staged_path.



13
14
15
# File 'lib/protk/galaxy_stager.rb', line 13

def staged_path
  @staged_path
end

Class Method Details

.replace_references(in_file, from_path, to_path) ⇒ Object



43
44
45
46
47
# File 'lib/protk/galaxy_stager.rb', line 43

def self.replace_references(in_file, from_path, to_path)
  puts "Replacing #{from_path} with #{to_path} in #{in_file}"
  cmd="ruby -pi -e \"gsub('#{from_path}', '#{to_path}')\" #{in_file}"
  %x[#{cmd}]
end

Instance Method Details

#replace_references(in_file, replacement) ⇒ Object



34
35
36
# File 'lib/protk/galaxy_stager.rb', line 34

def replace_references(in_file,replacement)
  GalaxyStager.replace_references(in_file, @original_path, replacement)
end

#restore_references(in_file, options = {}) ⇒ Object



38
39
40
41
# File 'lib/protk/galaxy_stager.rb', line 38

def restore_references(in_file, options = {})
  path = options[:base_only] ? @staged_path.gsub(/#{@extension}/,"") : @staged_path
  GalaxyStager.replace_references(in_file, path, @original_path)
end