Class: MS::Sequest::Sqt

Inherits:
Object
  • Object
show all
Includes:
Ident::SearchLike
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, _peptides|
  MS::Sequest::Sqt::Locus.new(_prot.locus, _prot.description, _peptides)
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)


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

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

Instance Attribute Details

#base_nameObject

Returns the value of attribute base_name.



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

def base_name
  @base_name
end

#headerObject

Returns the value of attribute header.



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

def header
  @header
end

#percolator_resultsObject

boolean



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

def percolator_results
  @percolator_results
end

#spectraObject

Returns the value of attribute spectra.



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

def spectra
  @spectra
end

Class Method Details

.db_info(dbfile) ⇒ Object

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



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

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. ++



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

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



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

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.



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/ms/sequest/sqt.rb', line 123

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, @peptides) = MS::Sequest::Sqt::Spectrum.spectra_from_handle(fh, @base_name, @percolator_results)
  end
end

#protein_classObject



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

def protein_class
  MS::Sequest::Sqt::Locus
end