Class: Bio::Sequence::AA

Inherits:
Object
  • Object
show all
Defined in:
lib/isoelectric_point/aa.rb

Constant Summary collapse

CHARGED_GROUPS =
['K', 'R', 'H', 'D', 'E', 'C', 'Y']

Instance Method Summary collapse

Constructor Details

#initialize(sequence) ⇒ AA

Returns a new instance of AA.

Raises:

  • (ArgumentError)


6
7
8
9
# File 'lib/isoelectric_point/aa.rb', line 6

def initialize(sequence)
  raise ArgumentError.new("sequence is required") if sequence.nil? || sequence.strip == ''
  super(sequence.upcase.gsub(/\s/, ''))
end

Instance Method Details

#charge_at(ph, pka_name_or_set = 'dtaselect') ⇒ Object

Calculate the charge of the sequence at a given ph As a second argument you can pass the name of the PKA set or a custom PKA set



35
36
37
38
39
40
41
42
# File 'lib/isoelectric_point/aa.rb', line 35

def charge_at(ph, pka_name_or_set = 'dtaselect')
  ['K', 'R', 'H'].inject(partial_charge(select_pka(pka_name_or_set)['N_TERMINUS'], ph)) do |memo, item|
    memo += partial_charge(select_pka(pka_name_or_set)[item], ph) * charged_residue_frequencies[item]
  end -
  ['D', 'E', 'C', 'Y'].inject(partial_charge(ph, select_pka(pka_name_or_set)['C_TERMINUS'])) do |memo, item|
    memo += partial_charge(ph, select_pka(pka_name_or_set)[item]) * charged_residue_frequencies[item]
  end
end

#isoelectric_point(pka_name_or_set = 'dtaselect', places = 2, loop_limit = 100) ⇒ Object

Calculate the Isoelectric Point pka_name_or_set: the name of a PKA set or a custom PKA set places: specify the number of decimal places the value should be rounded to. loop_limit: how many iterations should be made to find the point. You should not need to tweak this.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/isoelectric_point/aa.rb', line 15

def isoelectric_point(pka_name_or_set = 'dtaselect', places = 2, loop_limit = 100)
  loops = 0
  ph = 7.5
  step = 3.5
  begin
    current_charge = charge_at(ph, pka_name_or_set)
    if current_charge > 0
      ph += step
    else
      ph -= step
    end
    step /= 2.0
    loops += 1
    raise "Could not find a result within #{loop_limit} loops using #{pka_name_or_set.inspect}" if loops == loop_limit
  end while not iep_reached?(current_charge)
  ph.round_to_places(places)
end