Class: MS::Sim_Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/ms/sim_feature.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts, one_d, db) ⇒ Sim_Feature

Returns a new instance of Sim_Feature.



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
# File 'lib/ms/sim_feature.rb', line 10

def initialize(opts,one_d,db)
  @db = db
  @one_d = one_d
  @opts = opts
  @max_mz = -1


  #------------------Each_Peptide_=>_Feature----------------------
  prog = Progress.new("Generating features:")
  num = 0
  @db.execute "CREATE TABLE IF NOT EXISTS spectra(cent_id INTEGER PRIMARY KEY,pep_id INTEGER,rt REAL,mzs REAL,ints REAL,merge_id INTEGER)"
  @cent_id = 0
  peps = @db.execute "SELECT * FROM peptides"
  total = peps.size
  step = total/100.0
  peps.each do |pep|
    ind = pep[0]
    if ind > step * (num + 1)
      num = (((ind+1)/total.to_f)*100).to_i
      prog.update(num)
    end
    
    getInts(pep)
  end
  prog.finish!
end

Instance Attribute Details

#cent_idObject

Returns the value of attribute cent_id.



37
38
39
# File 'lib/ms/sim_feature.rb', line 37

def cent_id
  @cent_id
end

#max_mzObject

Returns the value of attribute max_mz.



37
38
39
# File 'lib/ms/sim_feature.rb', line 37

def max_mz
  @max_mz
end

Instance Method Details

#getInts(pep) ⇒ Object

Intensities are shaped in the rt direction by a gaussian with a dynamic standard deviation. They are also shaped in the m/z direction by a simple gaussian curve (see ‘factor’ below).



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/ms/sim_feature.rb', line 45

def getInts(pep)
  pep_id = pep[0]
  p_int = pep[7] + RThelper.RandomFloat(-5,2)
  if p_int > 10
    p_int -= 10
  end
  predicted_int = (p_int * 10**-1) * 14183000.0 
  low = 0.1*predicted_int
  relative_ints = (@db.execute "SELECT ints FROM core_spec WHERE pep_id=#{pep_id}").flatten[0].gsub(/\[/,"").split(/,/).map{|val| val.to_f}
  core_mzs = (@db.execute "SELECT mzs FROM core_spec WHERE pep_id=#{pep_id}").flatten[0].gsub(/\[/,"").split(/,/).map{|val| val.to_f}
  avg = pep[5] #p_rt

  sampling_rate = @opts[:sampling_rate].to_f
  wobA = Distribution::Normal.rng(@opts[:wobA].to_f,0.0114199604).call #0.0014199604 is the standard deviation from Hek_cells_100904050914 file
  wobB = Distribution::Normal.rng(@opts[:wobB].to_f,0.01740082).call #1.20280082 is the standard deviation from Hek_cells_100904050914 file
  tail = Distribution::Normal.rng(@opts[:tail].to_f,0.018667495).call #0.258667495 is the standard deviation from Hek_cells_100904050914 file
  front = Distribution::Normal.rng(@opts[:front].to_f,0.01466692).call #4.83466692 is the standard deviation from Hek_cells_100904050914 file
  # These number didn't work. May need to get more samples or figure something else out. For now this will give us some
  # meta variance in any case
  mu = @opts[:mu].to_f

  index = 0
  sx = pep[9]
  sy = (sx**-1) * Math.sqrt(pep[8]) #abu

  shuff = RThelper.RandomFloat(0.05,1.0)
  core_mzs.each do |mzmu|

    relative_abundances_int = relative_ints[index]

    t_index = 1

    (Sim_Spectra::r_times[pep[10]..pep[11]]).each_with_index do |rt,i| 
      

      if !@one_d
        #-------------Tailing-------------------------
        shape = (tail * (t_index / sx)) + front
        int = (RThelper.gaussian((t_index / sx) ,mu ,shape,100.0))
        t_index += 1
        #---------------------------------------------

      else
        #-----------Random 1d data--------------------
        int = (relative_abundances_int * ints_factor) * shuff
        #---------------------------------------------
      end

      if int < 0.01
        int = RThelper.RandomFloat(0.001,0.4)
      end

=begin
if !@one_d
  #-------------M/Z Peak shape (Profile?)-------
  fraction = RThelper.gaussian(fin_mzs[i],mzmu,0.05,1)
  factor = fraction/1.0
  fin_ints[i] = fin_ints[i] * factor
  #---------------------------------------------
end
=end	  

      if int > 0.4
      #-------------Jagged-ness---------------------
      sd = (@opts[:jagA] * (1-Math.exp(-(@opts[:jagC]) * int)) + @opts[:jagB])/2
      diff = (Distribution::Normal.rng(0,sd).call)
      int += diff
      #---------------------------------------------
      end

      #-------------mz wobble-----------------------
      wobble_mz = nil
      if int > 0
        wobble_int = wobA*int**wobB
        wobble_mz = Distribution::Normal.rng(mzmu,wobble_int).call
        if wobble_mz < 0
          wobble_mz = 0.01
        end
      end
      #---------------------------------------------


      int = int*(predicted_int*(relative_abundances_int*10**-2)) * sy
      if int > low.abs and wobble_mz > 0
        @db.execute "INSERT INTO spectra VALUES(#{@cent_id},#{pep_id},#{rt},#{wobble_mz},#{int},NULL)"
        @cent_id += 1
        if @max_mz < wobble_mz
          @max_mz = wobble_mz
        end
      end
    end
    index += 1
  end
end