Class: Mascot::DAT::Proteins

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mascot/dat/proteins.rb

Defined Under Namespace

Classes: ProteinEntry

Constant Summary collapse

PROT_REGEXP =
/(.+)\=(\d+\.\d+),(.+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dat_file, byteoffset, cache_index = true) ⇒ Proteins

Returns a new instance of Proteins.



16
17
18
19
20
21
22
23
24
25
# File 'lib/mascot/dat/proteins.rb', line 16

def initialize(dat_file,byteoffset,cache_index=true)
  @byteoffset = byteoffset
  @dat_file = File.new(dat_file, 'r')
  @dat_file.pos = byteoffset
  @endbytepos = @dat_file.stat.size
  @idx = {}
  if cache_index
    index_protein_positions
  end
end

Instance Attribute Details

#byteoffsetObject

Example proteins section

––gc0p4Jq0M2Yt08jU534c0p Content-Type: application/x-Mascot; name=”proteins”“accession string”=protein mass, “title text”…



14
15
16
# File 'lib/mascot/dat/proteins.rb', line 14

def byteoffset
  @byteoffset
end

#dat_fileObject

Example proteins section

––gc0p4Jq0M2Yt08jU534c0p Content-Type: application/x-Mascot; name=”proteins”“accession string”=protein mass, “title text”…



14
15
16
# File 'lib/mascot/dat/proteins.rb', line 14

def dat_file
  @dat_file
end

#endbyteposObject

Example proteins section

––gc0p4Jq0M2Yt08jU534c0p Content-Type: application/x-Mascot; name=”proteins”“accession string”=protein mass, “title text”…



14
15
16
# File 'lib/mascot/dat/proteins.rb', line 14

def endbytepos
  @endbytepos
end

#idxObject

Example proteins section

––gc0p4Jq0M2Yt08jU534c0p Content-Type: application/x-Mascot; name=”proteins”“accession string”=protein mass, “title text”…



14
15
16
# File 'lib/mascot/dat/proteins.rb', line 14

def idx
  @idx
end

Instance Method Details

#eachObject



42
43
44
45
46
# File 'lib/mascot/dat/proteins.rb', line 42

def each
  while @dat_file.pos < @endbytepos
    yield next_entry
  end
end

#next_entryObject



36
37
38
39
# File 'lib/mascot/dat/proteins.rb', line 36

def next_entry
  return nil if @dat_file.pos >= @endbytepos
  parse_entry(@dat_file.readline)
end

#protein(accession) ⇒ Object



31
32
33
34
# File 'lib/mascot/dat/proteins.rb', line 31

def protein(accession)
  @dat_file.pos = @idx[accession] if accession
  next_entry
end

#rewindObject



27
28
29
# File 'lib/mascot/dat/proteins.rb', line 27

def rewind
  @dat_file.pos = @byteoffset
end