Module: MS::Rtgenerator

Defined in:
lib/ms/rt/rtgenerator.rb

Class Method Summary collapse

Class Method Details

.generateRT(one_d, db) ⇒ Object



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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ms/rt/rtgenerator.rb', line 13

def generateRT(one_d,db)
  prog = Progress.new("Generating retention times:")
  @r_times = Sim_Spectra.r_times

  # Gets retention times from the weka model
  MS::Weka.predict_rts(db)
  MS::Weka.predict_ints(db)


  #-----------------------------------------------------------------
  num = 0
  
  max_rt = 4*(@r_times.max/5)
  r_end = max_rt + (@r_times.max/5)/2
  r_start = @r_times.max/5
  peps = db.execute "SELECT Id,p_rt,abu,seq FROM peptides"
  total = peps.size
  step = total/100.0
  peps.each do |pep|
    ind = pep.delete_at(0)
    init_p_rt = pep[0]
    abu = pep[1]
    seq = pep[2]
    pep_p_rt = nil
    pep_p_rt_i = nil
    if ind > step * (num + 1)
      num = (((ind+1)/total.to_f)*100).to_i
      prog.update(num)
    end


    #Fit retention times into scan times
    p_rt = init_p_rt * 10**-2
    percent_time = p_rt 
    sx = RThelper.gaussian(percent_time,0.5,0.45,1.0) * Math.sqrt(abu) #need to figure out what these values should be
	

    if p_rt > 1
      pep_p_rt = @r_times.find {|i| i >= r_end}
      pep_p_rt_i = @r_times.index(pep_p_rt)
    else
      pep_p_rt = @r_times.find {|i| i >= (p_rt * max_rt)}
      pep_p_rt_i = @r_times.index(pep_p_rt)
    end
    
    a = nil
    b = nil

    if pep_p_rt == nil
      puts "\n\n\t#{seq} TIME-> #{p_rt*max_rt} :: Peptide not predicted in time range: try increasing run time\n\n."
    else

      #Give peptide retention times
      head_length = nil
      tail_length = nil
      if one_d
        head_length = 300.0
        tail_length = 701
      else
        head_length = 100.0 * sx
        tail_length = 300 * sx
      end

      a = @r_times.find {|i| i >= (pep_p_rt-head_length)}
      b = @r_times.find {|i| i >= (pep_p_rt+tail_length)}
      a = @r_times.index(a)
      b = @r_times.index(b)

      if a == nil
        a = @r_times[0]
      end

      if b == nil
        b = @r_times[@r_times.length-1]
      end

    end
    db.execute "UPDATE peptides SET p_rt=#{pep_p_rt},p_rt_index=#{pep_p_rt_i},sx=#{sx},rt_a=#{a},rt_b=#{b} WHERE Id='#{ind}'"
  end
  #-----------------------------------------------------------------
  prog.finish!
end