Sha256: 00e6be9547a20197863a080e18e281986a9ad24d687c1fb0ac820a88db436fa0
Contents?: true
Size: 1.72 KB
Versions: 15
Compression:
Stored size: 1.72 KB
Contents
require 'ms/ident/search' require 'ms/ident/peptide_hit' module MS ; end module MS::Ident ; end class MS::Ident::PeptideHit module Qvalue FILE_EXTENSION = '.phq.tsv' FILE_DELIMITER = "\t" HEADER = %w(run_id id aaseq charge qvalue) class << self # writes to the file, adding an extension def to_phq(base, hits, qvalues=[]) to_file(base + FILE_EXTENSION, hits, qvalues) end # 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. 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 # returns an array of PeptideHit objects from a phq.tsv 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 alias_method :from_phq, :from_file end end # Qvalue end # Peptide Hit
Version data entries
15 entries across 15 versions & 1 rubygems