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
100 def comments_format_genbank(cmnts)
101   return '' if !cmnts or cmnts.empty?
102   cmnts = [ cmnts ] unless cmnts.kind_of?(Array)
103   a = []
104   cmnts.each do |str|
105     a.push "COMMENT     #{ genbank_wrap(str) }\n"
106   end
107   a.join('')
108 end
date_format_genbank() click to toggle source

formats date

    # File lib/bio/db/genbank/format_genbank.rb
123 def date_format_genbank
124   format_date(date_modified || date_created || null_date)
125 end
genbank_wrap(str) click to toggle source

string wrapper for GenBank format

   # File lib/bio/db/genbank/format_genbank.rb
20 def genbank_wrap(str)
21   wrap(str.to_s, 67).gsub(/\n/, "\n" + " " * 12)
22 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
25 def genbank_wrap_dot(str)
26   str = str.to_s
27   str = str + '.' unless /\.\z/ =~ str
28   genbank_wrap(str)
29 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
33 def genbank_wrap_words(array)
34   width = 67
35   result = []
36   str = nil
37   array.each do |x|
38     if str then
39       if str.length + 1 + x.length > width then
40         str = nil
41       else
42         str.concat ' '
43         str.concat x
44       end
45     end
46     unless str then
47       str = "#{x}"
48       result.push str
49     end
50   end
51   result.join("\n" + " " * 12)
52 end
mol_type_genbank() click to toggle source

moleculue type

    # File lib/bio/db/genbank/format_genbank.rb
128 def mol_type_genbank
129   if /(DNA|(t|r|m|u|sn|sno)?RNA)/i =~ molecule_type.to_s then
130     $1.sub(/[DR]NA/) { |x| x.upcase }
131   else
132     'NA'
133   end
134 end
ncbi_gi_number() click to toggle source

NCBI GI number

    # File lib/bio/db/genbank/format_genbank.rb
137 def ncbi_gi_number
138   ids = other_seqids
139   if ids and r = ids.find { |x| x.database == 'GI' } then
140     r.id
141   else
142     nil
143   end
144 end
reference_format_genbank(ref, num) click to toggle source

formats references

   # File lib/bio/db/genbank/format_genbank.rb
55     def reference_format_genbank(ref, num)
56       pos = ref.sequence_position.to_s.gsub(/\s/, '')
57       pos.gsub!(/(\d+)\-(\d+)/, "\\1 to \\2")
58       pos.gsub!(/\s*\,\s*/, '; ')
59       if pos.empty?
60         pos = ''
61       else
62         pos = " (bases #{pos})"
63       end
64       volissue = "#{ref.volume.to_s}"
65       volissue += " (#{ref.issue})" unless ref.issue.to_s.empty? 
66       journal = "#{ref.journal.to_s}"
67       journal += " #{volissue}" unless volissue.empty? 
68       journal += ", #{ref.pages}" unless ref.pages.to_s.empty?
69       journal += " (#{ref.year})" unless ref.year.to_s.empty?
70 
71       alist = ref.authors.collect do |x|
72         y = x.to_s.strip.split(/\, *([^\,]+)\z/)
73         y[1].gsub!(/\. +/, '.') if y[1]
74         y.join(',')
75       end
76       lastauthor = alist.pop
77       last2author = alist.pop
78       alist.each { |x| x.concat ',' }
79       alist.push last2author if last2author
80       alist.push "and" unless alist.empty?
81       alist.push lastauthor.to_s
82       result = <<__END_OF_REFERENCE__
83 REFERENCE   #{ genbank_wrap(sprintf('%-2d%s', num, pos))}
84   AUTHORS   #{ genbank_wrap_words(alist) }
85   TITLE     #{ genbank_wrap(ref.title.to_s) }
86   JOURNAL   #{ genbank_wrap(journal) }
87 __END_OF_REFERENCE__
88       unless ref.pubmed.to_s.empty? then
89         result.concat "   PUBMED   #{ genbank_wrap(ref.pubmed) }\n"
90       end
91       if ref.comments and !(ref.comments.empty?) then
92         ref.comments.each do |c|
93           result.concat "  REMARK    #{ genbank_wrap(c) }\n"
94         end
95       end
96       result
97     end
seq_format_genbank(str) click to toggle source

formats sequence lines as GenBank

    # File lib/bio/db/genbank/format_genbank.rb
111 def seq_format_genbank(str)
112   i = 1
113   result = str.gsub(/.{1,60}/) do |s|
114     s = s.gsub(/.{1,10}/, ' \0')
115     y = sprintf("%9d%s\n", i, s)
116     i += 60
117     y
118   end
119   result
120 end
strandedness_genbank() click to toggle source

strandedness

    # File lib/bio/db/genbank/format_genbank.rb
147 def strandedness_genbank
148   return nil unless strandedness
149   case strandedness
150   when 'single'; 'ss-'; 
151   when 'double'; 'ds-'; 
152   when 'mixed';  'ms-'; 
153   else; nil
154   end
155 end