Class: ORF

Inherits:
Object
  • Object
show all
Includes:
ORFCommon
Defined in:
lib/orf.rb,
lib/orf_common.rb

Defined Under Namespace

Modules: ORFCommon

Constant Summary collapse

DEFAULT_CODON_TABLE =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ORFCommon

#range_to_s

Constructor Details

#initialize(sequence, options = {}, logger_file = nil) ⇒ ORF

class initializer that normalizes sequence to Bio::Sequence,

merges given options and creates logger


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/orf.rb', line 18

def initialize(sequence, options = {}, logger_file = nil)
  # logger for instance
  if logger_file.nil?
    @logger = Logger.new(STDOUT)
  else
    @logger = logger_file.clone
  end
  logger.progname = 'ORFCommon'
  logger.level    = (options[:debug] ? Logger::INFO : Logger::ERROR)
  #
  sequence = Bio::Sequence::NA.new(sequence) if sequence.class == String
  @sequence = sequence
  @seq = @sequence.to_s
  #
  self.options = ORFFinder::DEFAULT_OPTIONS.merge(options.nil? ? {} : options)
  logger.info 'ORF has been initialized'
  find
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/orf.rb', line 13

def logger
  @logger
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/orf.rb', line 13

def options
  @options
end

#seqObject (readonly)

Returns the value of attribute seq.



13
14
15
# File 'lib/orf.rb', line 13

def seq
  @seq
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



13
14
15
# File 'lib/orf.rb', line 13

def sequence
  @sequence
end

Class Method Details

.find(sequence, options = {}) ⇒ Object

For a given sequence, find longest ORF



40
41
42
43
44
45
# File 'lib/orf.rb', line 40

def self.find(sequence, options = {})
  # merge options with default
  orf = ORF.new(sequence, options)
  @result = orf.find
  #
end

Instance Method Details

#aa(codon_table = DEFAULT_CODON_TABLE) ⇒ Object

return aminoacid sequence



49
50
51
52
53
54
55
56
# File 'lib/orf.rb', line 49

def aa(codon_table = DEFAULT_CODON_TABLE)
  # return already generated aa sequence
  return @res_aa unless @res_aa.nil?
  # save result
  l = longest(codon_table)
  return l if @res_aa.nil?
  @res_aa
end

#findObject

finds all possible orfs in sequence



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
# File 'lib/orf.rb', line 68

def find
  # if sequence is nil or empty there is no point
  #  in trying to run the find algorithm
  return sequence if sequence.nil? || sequence.size == 0
  #
  orf = { frame1: {}, frame2: {}, frame3: {} }
  #
  start_idx = all_codons_indices(:start)
  stop_idx  = all_codons_indices(:stop)
  res       = all_sequences(start_idx, stop_idx, seq.size, [0, 1, 2])
  #
  logger.info "start codons idx: #{start_idx}"
  logger.info "stop codons idx: #{stop_idx}"
  logger.info res
  # iterate over each frame and range to return the
  #  longest above the minimum sequence length
  # these are the preferences:
  #  1: range that has start and stop codons
  #  2: range that only has start/stop
  #  3: full sequence
  res.each_with_index do |frame, index|
    find_longest(frame, index, orf)
  end
  # print ranges if debug is activated
  orf.each { |k, f| f[:orfs].each { |r| print_range(k, r) } } \
    if options[:debug]
  #
  @orf = orf
end

#nt(codon_table = DEFAULT_CODON_TABLE) ⇒ Object

return nucletotide sequence



60
61
62
63
# File 'lib/orf.rb', line 60

def nt(codon_table = DEFAULT_CODON_TABLE)
  return @res_nt unless @res_nt.nil?
  longest(codon_table)
end