class MS::Txml_file_writer
Public Class Methods
write(db,file_name,opts)
click to toggle source
# File lib/ms/tr_file_writer.rb, line 5 def self.write(db,file_name,opts) prog = Progress.new("Writing xml:") file = File.open("#{file_name}_truth.xml","w") peps = db.execute "SELECT * FROM peptides" file.puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" file.puts "<simulated_peptides>" file.puts "<simulator_options>\n" opts.each do |k,v| file.puts "\t#{k}=#{v}," end file.puts "</simulator_options>\n" total = peps.size.to_f num = 0 step = total/100.0 peps.each do |pep| k = pep[0] if k > step * (num + 1) num = (((k/total)*100).to_i) prog.update(num) end sequence = pep[1] charge = pep[3] cents = db.execute "SELECT * FROM spectra WHERE pep_id=#{k}" file.puts "\t<simulated_peptide sequence=\"#{sequence}\" charge=\"#{charge.round}\">" tags = "" tags<<"\t\t<centroids>\n" centroids = "" cents.each do |cent| centroids<<"\t\t\tcent_id=#{cent[0]},pep_id=#{cent[1]},rt=#{cent[2]},mz=#{cent[3]},int=#{cent[4]},merge_id=#{cent[5]}\n" end tags<<centroids tags<<"\t\t</centroids>\n" file<<tags file.puts "\t</simulated_peptide>" end file.puts "</simulated_peptides>" file.close prog.finish! end