Module: Ms::Ident::SearchGroup

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

Instance Attribute Summary collapse

Attributes included from Search

#peptides, #proteins

Instance Method Summary collapse

Methods included from Search

#merge!

Instance Attribute Details

#searchesObject

an array of search objects



46
47
48
# File 'lib/ms/ident/search.rb', line 46

def searches
  @searches
end

Instance Method Details

#extensionObject

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



49
50
51
# File 'lib/ms/ident/search.rb', line 49

def extension
  'grp'
end

#from_file(file) ⇒ Object



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

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

#from_filenames(filenames) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/ms/ident/search.rb', line 67

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:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ms/ident/search.rb', line 83

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



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

def search_class
  Search
end

#to_paths(file) ⇒ Object

a simple formatted file with paths to the search files



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

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