Class: Bio::Mutation

Inherits:
Object
  • Object
show all
Includes:
VepHgvs
Defined in:
lib/bio-sam-mutation/bio/mutation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VepHgvs

consequences_for_transcript, #vep

Constructor Details

#initialize(params = {position: 1,type: :uninitialized, reference: nil, mutant: nil, seqname: nil}) ⇒ Mutation

Returns a new instance of Mutation.



4
5
6
7
8
9
10
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 4

def initialize params={position: 1,type: :uninitialized, reference: nil, mutant: nil, seqname: nil}
  @position = params[:position]
  @type = params[:type]
  @reference = params[:reference]
  @mutant = params[:mutant]
  @seqname = params[:seqname]
end

Instance Attribute Details

#mutantObject

Returns the value of attribute mutant.



3
4
5
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 3

def mutant
  @mutant
end

#positionObject

Returns the value of attribute position.



3
4
5
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 3

def position
  @position
end

#referenceObject

Returns the value of attribute reference.



3
4
5
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 3

def reference
  @reference
end

#seqnameObject

Returns the value of attribute seqname.



3
4
5
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 3

def seqname
  @seqname
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 3

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
15
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 12

def <=> other
  return 0 if self.position == other.position
  self.position > other.position ? 1 : -1
end

#to_hgvs(reference_type = nil) ⇒ Object

www.hgvs.org/mutnomen/recs.html This gives just the annotation. To convert to a full allele description, needs to be combined with e.g. g. for genomic: g. - can supply this “g”, “c” as type to annotate a single mutation directly for compound mutants, need to join an array of annotations e.g. 1:g.



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
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 21

def to_hgvs(reference_type=nil)
  if reference_type
    hgvs_arr = [@seqname,":",reference_type,".",@position.to_s]
  else
    hgvs_arr = [@position.to_s]
  end

  case @type
    when :deletion
      if @reference.length == 1
        hgvs_arr << "del"+@reference
      else
        hgvs_arr = hgvs_arr + ["_",
                              (@position.to_i+@reference.length-1).to_s,
                              "del",
                              @reference]
      end
      hgvs_arr.join

    when :substitution
      if @reference.length > 1
        hgvs_arr = hgvs_arr + ["_",
                              (@position.to_i+@reference.length-1).to_s]
      end
      hgvs_arr << @reference+">"+@mutant
      hgvs_arr.join

    when :insertion
      hgvs_arr << "_" + (@position.to_i+1).to_s
      hgvs_arr << "ins"+@mutant
      hgvs_arr.join
      # TODO - distinguish duplications from insertions? Needs further input from ref.
  end
end

#to_jsonObject



56
57
58
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 56

def to_json
  Oj.dump self
end

#to_yamlObject



60
61
62
# File 'lib/bio-sam-mutation/bio/mutation.rb', line 60

def to_yaml
  YAML.dump self
end