5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# 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
|