Module: Ms::Ident::PeptideHit::Qvalue
- Defined in:
- lib/ms/ident/peptide_hit/qvalue.rb
Constant Summary collapse
- FILE_EXTENSION =
'.phq.tsv'
- FILE_DELIMITER =
"\t"
- HEADER =
%w(run_id id aaseq charge qvalue)
Class Method Summary collapse
-
.from_file(filename) ⇒ Object
(also: from_phq)
returns an array of PeptideHit objects from a phq.tsv.
-
.to_file(filename, hits, qvalues = []) ⇒ Object
writes the peptide hits to a phq.tsv file.
-
.to_phq(base, hits, qvalues = []) ⇒ Object
writes to the file, adding an extension.
Class Method Details
.from_file(filename) ⇒ Object Also known as: from_phq
returns an array of PeptideHit objects from a phq.tsv
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ms/ident/peptide_hit/qvalue.rb', line 34 def from_file(filename) searches = Hash.new {|h,id| h[id] = Ms::Ident::Search.new(id) } peptide_hits = [] File.open(filename) do |io| header = io.readline.chomp.split(FILE_DELIMITER) raise "bad headers" unless header == HEADER io.each do |line| line.chomp! (run_id, id, aaseq, charge, qvalue) = line.split(FILE_DELIMITER) ph = Ms::Ident::PeptideHit.new ph.search = searches[run_id] ph.id = id; ph.aaseq = aaseq ; ph.charge = charge.to_i ; ph.qvalue = qvalue.to_f peptide_hits << ph end end peptide_hits end |
.to_file(filename, hits, qvalues = []) ⇒ Object
writes the peptide hits to a phq.tsv file. qvalues is a parallel array to hits that can provide qvalues if not inherent to the hits returns the filename.
23 24 25 26 27 28 29 30 31 |
# File 'lib/ms/ident/peptide_hit/qvalue.rb', line 23 def to_file(filename, hits, qvalues=[]) File.open(filename,'w') do |out| out.puts HEADER.join(FILE_DELIMITER) hits.zip(qvalues) do |hit, qvalue| out.puts [hit.search.id, hit.id, hit.aaseq, hit.charge, qvalue || hit.qvalue].join(FILE_DELIMITER) end end filename end |
.to_phq(base, hits, qvalues = []) ⇒ Object
writes to the file, adding an extension
16 17 18 |
# File 'lib/ms/ident/peptide_hit/qvalue.rb', line 16 def to_phq(base, hits, qvalues=[]) to_file(base + FILE_EXTENSION, hits, qvalues) end |