Module: Mspire::Ident::SearchGroup

Defined in:
lib/mspire/ident/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#searchesObject

an array of search objects



55
56
57
# File 'lib/mspire/ident/search.rb', line 55

def searches
  @searches
end

Instance Method Details

#extensionObject

the group's file extension (with no leading period)



58
59
60
# File 'lib/mspire/ident/search.rb', line 58

def extension
  'grp'
end

#from_file(file) ⇒ Object



71
72
73
# File 'lib/mspire/ident/search.rb', line 71

def from_file(file)
  from_filenames(to_paths(file))
end

#from_filenames(filenames) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/mspire/ident/search.rb', line 76

def from_filenames(filenames)
  filenames.each do |file|
    if !File.exist? file
      message = "File: #{file} does not exist!\n"
      message << "perhaps you need to modify the file with file paths"
      abort message
    end
    @searches << search_class.new(file)
  end
end

#initialize(arg = nil, opts = {}) {|_self| ... } ⇒ Object

takes an array of filenames or a single search filename (with extension defined by 'extendsion') or an array of objects passes any arguments to the initializer for each search the optional block yields the object for further processing

Yields:

  • (_self)

Yield Parameters:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mspire/ident/search.rb', line 92

def initialize(arg=nil, opts={})
  @peptide_hits = []
  @reference_hash = {}
  @searches = []

  if arg
    if arg.is_a?(String) && arg =~ /\.#{Regexp.escap(extension)}$/
      from_file(arg)
    elsif arg.is_a?(Array) && arg.first.is_a?(String)
      from_filenames(arg)
    elsif arg.is_a?(Array)
      @searches = array
    else
      raise ArgumentError, "must be file, array of filenames, or array of objs"
    end
    @searches << search_class.new(file, opts)
  end
  yield(self) if block_given?
end

#search_classObject



62
63
64
# File 'lib/mspire/ident/search.rb', line 62

def search_class
  Search
end

#to_paths(file) ⇒ Object

a simple formatted file with paths to the search files



67
68
69
# File 'lib/mspire/ident/search.rb', line 67

def to_paths(file)
  IO.readlines(file).grep(/\w/).reject {|v| v =~ /^#/}.map {|v| v.chomp }
end