Module: Ms::Ident::SearchGroup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#searchesObject

an array of search objects



51
52
53
# File 'lib/ms/ident/search.rb', line 51

def searches
  @searches
end

Instance Method Details

#extensionObject

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



54
55
56
# File 'lib/ms/ident/search.rb', line 54

def extension
  'grp'
end

#from_file(file) ⇒ Object



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

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

#from_filenames(filenames) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/ms/ident/search.rb', line 72

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:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ms/ident/search.rb', line 88

def initialize(arg=nil, opts={})
  @peptides = []
  @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



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

def search_class
  Search
end

#to_paths(file) ⇒ Object

a simple formatted file with paths to the search files



63
64
65
# File 'lib/ms/ident/search.rb', line 63

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