37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/ms/merger.rb', line 37
def self.merge(half_range,db)
prog = Progress.new("Merging Overlaps:")
db.execute "CREATE TABLE IF NOT EXISTS merged(merge_id INTEGER PRIMARY KEY, merged_vals TEXT, a_vals TEXT, b_vals TEXT)"
spectra = db.execute "SELECT * FROM spectra"
spectra = spectra.group_by{|spec| spec[2]}
total = spectra.size
merge_id = 0
k = 0
spectra.each do |rt,peaks|
if k.even?
num = (((k/total)*100).to_i)
prog.update(num)
end
peaks.sort_by!{|a| a[2]} peaks_t = peaks.transpose
pep_ids = peaks_t[1]
cent_ids = peaks_t[0]
mzs = peaks_t[3]
ints = peaks_t[4]
mzs.each_with_index do |mz,i|
o_mz = mz
range = (mz..mz+half_range)
if range.include?(mzs[i+1])
metaA_mz = [o_mz, mzs[i+1]]
meta_int = [ints[i],ints[i+1]]
sum = ints[i] + ints[i+1]
new_mz = w_avg(metaA_mz,meta_int)
db.execute "DELETE FROM spectra WHERE cent_id=#{cent_ids[i]}"
db.execute "DELETE FROM spectra WHERE cent_id=#{cent_ids[i+1]}"
db.execute "INSERT INTO spectra VALUES(#{cent_ids[i]},#{pep_ids[i]},#{rt},#{new_mz},#{sum},#{merge_id})"
db.execute "INSERT INTO merged VALUES(#{merge_id}, '#{cent_ids[i]},#{pep_ids[i]},#{rt},#{new_mz},#{sum}', '#{peaks[i]}', '#{peaks[i+1]}')"
merge_id += 1
end
end
k += 1
end
prog.finish!
end
|