module Bio::Sequence::Format::INSDFeatureHelper

Formatting helper methods for INSD (NCBI, EMBL, DDBJ) feature table

Constants

MonthStr

Private Instance Methods

fold(str, width) click to toggle source
    # File lib/bio/sequence/format.rb
302 def fold(str, width)
303   str.gsub(Regexp.new("(.{1,#{width}})"), "\\1\n")
304 end
fold_and_split_lines(str, width) click to toggle source
    # File lib/bio/sequence/format.rb
306 def fold_and_split_lines(str, width)
307   str.scan(Regexp.new(".{1,#{width}}"))
308 end
format_date(d) click to toggle source

formats a date from Date, DateTime, or Time object, or String.

    # File lib/bio/sequence/format.rb
360 def format_date(d)
361   begin
362     yy = d.year
363     mm = d.month
364     dd = d.day
365   rescue NoMethodError, NameError, ArgumentError, TypeError
366     return sprintf("%-11s", d)
367   end
368   sprintf("%02d-%-3s-%04d", dd, MonthStr[mm], yy)
369 end
format_feature(feature, prefix, indent, width) click to toggle source

format an INSD feature

    # File lib/bio/sequence/format.rb
266 def format_feature(feature, prefix, indent, width)
267   result = prefix + sprintf("%-16s", feature.feature)
268 
269   position = feature.position
270   #position = feature.locations.to_s
271 
272   result << wrap_and_split_lines(position, width).join("\n" + indent)
273   result << "\n"
274   result << format_qualifiers(feature.qualifiers, indent, width)
275   return result
276 end
format_features(features, prefix, indent, width) click to toggle source

format INSD featurs

    # File lib/bio/sequence/format.rb
257 def format_features(features, prefix, indent, width)
258   result = []
259   features.each do |feature|
260     result.push format_feature(feature, prefix, indent, width)
261   end
262   return result.join('')
263 end
format_features_embl(features) click to toggle source

INTERNAL USE ONLY, YOU SHOULD NOT CALL THIS METHOD. (And in any case, it would be difficult to successfully call this method outside its expected context).

Output the EMBL feature format string of the sequence. Used in Bio::Sequence#output.


Returns

String object

    # File lib/bio/sequence/format.rb
248 def format_features_embl(features)
249   prefix = 'FT   '
250   indent = prefix + ' ' * 16
251   fwidth = 80 - indent.length
252 
253   format_features(features, prefix, indent, fwidth)
254 end
format_features_genbank(features) click to toggle source

INTERNAL USE ONLY, YOU SHOULD NOT CALL THIS METHOD. (And in any case, it would be difficult to successfully call this method outside its expected context).

Output the Genbank feature format string of the sequence. Used in Bio::Sequence#output.


Returns

String object

    # File lib/bio/sequence/format.rb
232 def format_features_genbank(features)
233   prefix = ' ' * 5
234   indent = prefix + ' ' * 16
235   fwidth = 79 - indent.length
236 
237   format_features(features, prefix, indent, fwidth)
238 end
format_qualifiers(qualifiers, indent, width) click to toggle source

format qualifiers

    # File lib/bio/sequence/format.rb
279 def format_qualifiers(qualifiers, indent, width)
280   qualifiers.collect do |qualifier|
281     q = qualifier.qualifier
282     v = qualifier.value.to_s
283 
284     if v == true
285       lines = wrap_with_newline('/' + q, width)
286     elsif q == 'translation'
287       lines = fold("/#{q}=\"#{v}\"", width)
288     else
289       if v[/\D/] or q == 'chromosome'
290         #v.delete!("\x00-\x1f\x7f-\xff")
291         v.gsub!(/"/, '""')
292         v = '"' + v + '"'
293       end
294       lines = wrap_with_newline('/' + q + '=' + v, width)
295     end
296 
297     lines.gsub!(/^/, indent)
298     lines
299   end.join
300 end
null_date() click to toggle source

null date

    # File lib/bio/sequence/format.rb
372 def null_date
373   Date.new(0, 1, 1)
374 end
wrap(str, width = 80, prefix = '') click to toggle source
    # File lib/bio/sequence/format.rb
343 def wrap(str, width = 80, prefix = '')
344   actual_width = width - prefix.length
345   result = wrap_and_split_lines(str, actual_width)
346   result_string = result.join("\n#{prefix}")
347   result_string = prefix + result_string unless result_string.empty?
348   return result_string
349 end
wrap_and_split_lines(str, width) click to toggle source
    # File lib/bio/sequence/format.rb
310 def wrap_and_split_lines(str, width)
311   result = []
312   lefts = str.chomp.split(/(?:\r\n|\r|\n)/)
313   lefts.each do |left|
314     left.rstrip!
315     while left and left.length > width
316       line = nil
317       width.downto(1) do |i|
318         if left[i..i] == ' ' or /[\,\;]/ =~ left[(i-1)..(i-1)]  then
319           line = left[0..(i-1)].sub(/ +\z/, '')
320           left = left[i..-1].sub(/\A +/, '')
321           break
322         end
323       end
324       if line.nil? then
325         line = left[0..(width-1)]
326         left = left[width..-1]
327       end
328       result << line
329       left = nil if  left.to_s.empty?
330     end
331     result << left if left
332   end
333   return result
334 end
wrap_with_newline(str, width) click to toggle source
    # File lib/bio/sequence/format.rb
336 def wrap_with_newline(str, width)
337   result = wrap_and_split_lines(str, width)
338   result_string = result.join("\n")
339   result_string << "\n" unless result_string.empty?
340   return result_string
341 end