Class: MS::Sequest::Sqt::Header

Inherits:
Hash
  • Object
show all
Defined in:
lib/ms/sequest/sqt.rb

Overview

Inherits from hash, so all header stuff can be accessed by key. Multiline values will be pushed into an array. All header values are stored as (newline-removed) strings!

Constant Summary collapse

Leader =
'H'
Arrayed =

These will be in arrays no matter what: StaticMod, DynamicMod, Comment Any other keys repeated will be shoved into an array; otherwise a string

%w(DyanmicMod StaticMod Comment).to_set
HeaderKeys =
{
  :sqt_generator => 'SQTGenerator',
  :sqt_generator_version => 'SQTGeneratorVersion',
  :database => 'Database',
  :fragment_masses => 'FragmentMasses',
  :precursor_masses => 'PrecursorMasses',
  :start_time => 'StartTime',
  :db_seq_length => 'DBSeqLength',
  :db_locus_count => 'DBLocusCount',
  :db_md5sum => 'DBMD5Sum',
  :peptide_mass_tolerance => 'Alg-PreMassTol',
  :fragment_ion_tolerance => 'Alg-FragMassTol',
  # nonstandard (mine)
  :peptide_mass_units => 'Alg-PreMassUnits',
  :ion_series => 'Alg-IonSeries',
  :enzyme => 'Alg-Enzyme',
  # nonstandard (mine)
  :ms_model => 'Alg-MSModel',
  :static_mods => 'StaticMod',
  :dynamic_mods => 'DynamicMod',
  :comments => 'Comment'
}
KeysToAtts =
HeaderKeys.invert

Instance Method Summary collapse

Instance Method Details

#from_handle(fh) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/ms/sequest/sqt.rb', line 177

def from_handle(fh)
  Arrayed.each do |ky|
    self[ky] = []
  end
  pos = fh.pos 
  lines = []
  loop do 
    line = fh.gets
    if line && (line[0,1] == MS::Sequest::Sqt::Header::Leader )
      lines << line
    else # reset the fh.pos and we're done
      fh.pos = pos
      break
    end
    pos = fh.pos 
  end
  from_lines(lines)
end

#from_lines(array_of_header_lines) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/ms/sequest/sqt.rb', line 196

def from_lines(array_of_header_lines)
  array_of_header_lines.each do |line|
    line.chomp!
    (ky, *rest) = line.split(MS::Sequest::Sqt::Delimiter)[1..-1]
    # just in case they have any tabs in their field
    value = rest.join(MS::Sequest::Sqt::Delimiter)
    if Arrayed.include?(ky)
      self[ky] << value
    elsif self.key? ky  # already exists
      if self[ky].is_a? Array
        self[ky] << value
      else
        self[ky] = [self[ky], value]
      end
    else  # normal
      self[ky] = value
    end
  end
  KeysToAtts.each do |ky,methd|
    self.send("#{methd}=".to_sym, self[ky])
  end
  self
end