class Bio::Sequence::Format::NucFormatter::Genbank
INTERNAL USE ONLY, YOU SHOULD NOT USE THIS CLASS. GenBank format output class for Bio::Sequence.
Private Instance Methods
comments_format_genbank(cmnts)
click to toggle source
formats comments lines as GenBank
# File lib/bio/db/genbank/format_genbank.rb, line 100 def comments_format_genbank(cmnts) return '' if !cmnts or cmnts.empty? cmnts = [ cmnts ] unless cmnts.kind_of?(Array) a = [] cmnts.each do |str| a.push "COMMENT #{ genbank_wrap(str) }\n" end a.join('') end
date_format_genbank()
click to toggle source
formats date
# File lib/bio/db/genbank/format_genbank.rb, line 123 def date_format_genbank format_date(date_modified || date_created || null_date) end
genbank_wrap(str)
click to toggle source
string wrapper for GenBank format
# File lib/bio/db/genbank/format_genbank.rb, line 20 def genbank_wrap(str) wrap(str.to_s, 67).gsub(/\n/, "\n" + " " * 12) end
genbank_wrap_dot(str)
click to toggle source
string wrap with adding a dot at the end of the string
# File lib/bio/db/genbank/format_genbank.rb, line 25 def genbank_wrap_dot(str) str = str.to_s str = str + '.' unless /\.\z/ =~ str genbank_wrap(str) end
genbank_wrap_words(array)
click to toggle source
Given words (an Array of String) are wrapping with EMBL style. Each word is never splitted inside the word.
# File lib/bio/db/genbank/format_genbank.rb, line 33 def genbank_wrap_words(array) width = 67 result = [] str = nil array.each do |x| if str then if str.length + 1 + x.length > width then str = nil else str.concat ' ' str.concat x end end unless str then str = "#{x}" result.push str end end result.join("\n" + " " * 12) end
mol_type_genbank()
click to toggle source
moleculue type
# File lib/bio/db/genbank/format_genbank.rb, line 128 def mol_type_genbank if /(DNA|(t|r|m|u|sn|sno)?RNA)/i =~ molecule_type.to_s then $1.sub(/[DR]NA/) { |x| x.upcase } else 'NA' end end
ncbi_gi_number()
click to toggle source
NCBI GI number
# File lib/bio/db/genbank/format_genbank.rb, line 137 def ncbi_gi_number ids = other_seqids if ids and r = ids.find { |x| x.database == 'GI' } then r.id else nil end end
reference_format_genbank(ref, num)
click to toggle source
formats references
# File lib/bio/db/genbank/format_genbank.rb, line 55 def reference_format_genbank(ref, num) pos = ref.sequence_position.to_s.gsub(/\s/, '') pos.gsub!(/(\d+)\-(\d+)/, "\\1 to \\2") pos.gsub!(/\s*\,\s*/, '; ') if pos.empty? pos = '' else pos = " (bases #{pos})" end volissue = "#{ref.volume.to_s}" volissue += " (#{ref.issue})" unless ref.issue.to_s.empty? journal = "#{ref.journal.to_s}" journal += " #{volissue}" unless volissue.empty? journal += ", #{ref.pages}" unless ref.pages.to_s.empty? journal += " (#{ref.year})" unless ref.year.to_s.empty? alist = ref.authors.collect do |x| y = x.to_s.strip.split(/\, *([^\,]+)\z/) y[1].gsub!(/\. +/, '.') if y[1] y.join(',') end lastauthor = alist.pop last2author = alist.pop alist.each { |x| x.concat ',' } alist.push last2author if last2author alist.push "and" unless alist.empty? alist.push lastauthor.to_s result = <<__END_OF_REFERENCE__ REFERENCE #{ genbank_wrap(sprintf('%-2d%s', num, pos))} AUTHORS #{ genbank_wrap_words(alist) } TITLE #{ genbank_wrap(ref.title.to_s) } JOURNAL #{ genbank_wrap(journal) } __END_OF_REFERENCE__ unless ref.pubmed.to_s.empty? then result.concat " PUBMED #{ genbank_wrap(ref.pubmed) }\n" end if ref.comments and !(ref.comments.empty?) then ref.comments.each do |c| result.concat " REMARK #{ genbank_wrap(c) }\n" end end result end
seq_format_genbank(str)
click to toggle source
formats sequence lines as GenBank
# File lib/bio/db/genbank/format_genbank.rb, line 111 def seq_format_genbank(str) i = 1 result = str.gsub(/.{1,60}/) do |s| s = s.gsub(/.{1,10}/, ' \0') y = sprintf("%9d%s\n", i, s) i += 60 y end result end
strandedness_genbank()
click to toggle source
strandedness
# File lib/bio/db/genbank/format_genbank.rb, line 147 def strandedness_genbank return nil unless strandedness case strandedness when 'single'; 'ss-'; when 'double'; 'ds-'; when 'mixed'; 'ms-'; else; nil end end