class MgNu::Genbank

Constants

Locus
STRUCTURE

Attributes

accession[RW]
comment[RW]
definition[RW]
features[RW]
geninfo_identifier[RW]
keywords[RW]
locus[RW]
references[RW]
secondary_accession[RW]
segment[RW]
sequence[RW]
source[RW]
version[RW]

Public Class Methods

new() click to toggle source

create a new Genbank object

# File lib/mgnu/genbank.rb, line 36
def initialize
  @locus               = nil
  @definition          = ''
  @accession           = ''
  @secondary_accession = []
  @dblink              = ''
  @version             = ''
  @geninfo_identifier  = ''
  @keywords            = nil
  @segment             = ''
  @source              = nil
  @references          = []
  @comment             = ''
  @features            = []
  @sequence            = ''
end

Public Instance Methods

to_s() click to toggle source

string representation

# File lib/mgnu/genbank.rb, line 57
def to_s
  str = ''
  STRUCTURE.each do |part|
    p = send(part)
    p_exists = false
    case part
    when :locus, :source
      if p
        p_exists = true
        str << p.to_s
      end
    when :definition, :dblink, :segment, :comment
      if p && !p.empty?
        p_exists = true
        str << part.to_s.upcase.ljust(12)
        str << p.print_multiline
        str << '.' if part == :definition
      end
    when :accession
      if p && !p.empty?
        p_exists = true
        str += 'ACCESSION'.ljust(12)
        str += accession
        if secondary_accession.any?
          str += " #{secondary_accession.join(' ')}"
        end
      end
    when :version
      if p && !p.empty?
        p_exists = true
        str += 'VERSION'.ljust(12)
        str += version
        str += "  GI:#{geninfo_identifier}" if geninfo_identifier
      end
    when :features, :references
      unless p.empty?
        p_exists = true
        str += "FEATURES             Location/Qualifiers\n" if part == :features
        temp = p.collect { |x| x.to_s }
        str += temp.join("\n")
      end
    when :sequence
      unless p.value.empty?
        p_exists = true
        str << "#{'ORIGIN'.ljust(12)}\n"
        str << @sequence.to_genbank
      end
    when :keywords
      p_exists = true
      str << 'KEYWORDS'.ljust(12)
      str << p.join('; ').print_multiline if p
      str << '.'
    end
    # print newline character if there are more parts
    str << "\n" if p_exists && STRUCTURE[STRUCTURE.index(part) + 1]
  end
  str << '//'
end