Class: Ms::Sequest::Sqt

Inherits:
Object
  • Object
show all
Includes:
Id::Search
Defined in:
lib/ms/sequest/sqt.rb

Defined Under Namespace

Classes: Header, Locus, Match, Spectrum

Constant Summary collapse

PercolatorHeaderMatch =
/^Percolator v/
Delimiter =
"\t"
NEW_PROT =
lambda do |_prot, _peps| 
  Ms::Sequest::Sqt::Locus.new([_prot.locus, _prot.description, _peps])
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil, opts = {}) ⇒ Sqt

opts =

:percolator_results => false | true (default false)
:link_protein_hits => true | false (default true)

110
111
112
113
114
115
116
# File 'lib/ms/sequest/sqt.rb', line 110

def initialize(filename=nil, opts={})
  @peps = []
  @prots = []
  if filename
    from_file(filename, opts)
  end
end

Instance Attribute Details

#base_nameObject

Returns the value of attribute base_name


64
65
66
# File 'lib/ms/sequest/sqt.rb', line 64

def base_name
  @base_name
end

#headerObject

Returns the value of attribute header


62
63
64
# File 'lib/ms/sequest/sqt.rb', line 62

def header
  @header
end

#percolator_resultsObject

boolean


66
67
68
# File 'lib/ms/sequest/sqt.rb', line 66

def percolator_results
  @percolator_results
end

#spectraObject

Returns the value of attribute spectra


63
64
65
# File 'lib/ms/sequest/sqt.rb', line 63

def spectra
  @spectra
end

Class Method Details

.db_info(dbfile) ⇒ Object

assumes the file exists and is readable returns [DBSeqLength, DBLocusCount, DBMD5Sum]


98
99
100
101
# File 'lib/ms/sequest/sqt.rb', line 98

def self.db_info(dbfile)
  # returns the 3 member array
  self.db_seq_length_and_locus_count(dbfile) << self.db_md5sum(dbfile)
end

.db_md5sum(dbfile) ⇒ Object

– this is implemented separate from sequence length because seq length uses Archive which doesn't preserve carriage returns and newlines. ++


85
86
87
88
89
90
91
92
93
94
# File 'lib/ms/sequest/sqt.rb', line 85

def self.db_md5sum(dbfile)
  chunksize = 61440
  digest = Digest::MD5.new
  File.open(dbfile) do |io|
    while chunk = io.read(chunksize)
      digest << chunk 
    end
  end
  digest.hexdigest
end

.db_seq_length_and_locus_count(dbfile) ⇒ Object

returns [sequence_length, locus_count] of the fasta file


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ms/sequest/sqt.rb', line 69

def self.db_seq_length_and_locus_count(dbfile)
  total_sequence_length = 0
  fastasize = 0
  Ms::Fasta.open(dbfile) do |fasta|
    fasta.each do |entry| 
      total_sequence_length += entry.sequence.size 
      fastasize += 1
    end
  end
  [total_sequence_length, fastasize]
end

Instance Method Details

#from_file(filename, opts = {}) ⇒ Object

if the file contains the header key '/$Percolator v/' then the results will be interpreted as percolator results regardless of the value passed in.


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ms/sequest/sqt.rb', line 125

def from_file(filename, opts={})
  opts = {:percolator_results=>false, :link_protein_hits => true}.merge(opts)
  @percolator_results = opts[:percolator_results]
  @base_name = File.basename( filename.gsub('\\','/') ).sub(/\.\w+$/, '')
  File.open(filename) do |fh| 
    @header = Ms::Sequest::Sqt::Header.new.from_handle(fh)
    if @header.keys.any? {|v| v =~ PercolatorHeaderMatch }
      @percolator_results = true
    end
    (@spectra, @peps) = Ms::Sequest::Sqt::Spectrum.spectra_from_handle(fh, @base_name, @percolator_results)
  end
  if opts[:link_protein_hits]
    (@peps, @prots) = merge!([@peps], &NEW_PROT)
  end
end

#protein_classObject


103
104
105
# File 'lib/ms/sequest/sqt.rb', line 103

def protein_class
  Ms::Sequest::Sqt::Locus
end