#!/usr/bin/env ruby # # color_scheme_na.rb - A Bio::ColorScheme demo script for Nucleic Acids # sequences. # # Usage: # # % ruby color_scheme_na.rb > cs-seq-fna.html # # % cat seq.fna # >DNA_sequence # acgtgtgtcatgctagtcgatcgtactagtcgtagctagtca # % ruby color_scheme_na.rb seq.fna > colored-seq-fna.html # # # Copyright:: Copyright (C) 2005 # Mitsuteru C. Nakao # License:: The Ruby License # # require 'bio' # returns folded sequence with
. def br(i, width = 80) return "" if i % width == 0 "" end # returns sequence html doc def display(seq, cs) html = '

' postfix = '' i = 0 seq.each_char do |c| color = cs[c] prefix = %Q() html += prefix + c + postfix html += br(i += 1) end html + '

' end # returns scheme wise html doc def display_scheme(scheme, naseq, aaseq) html = '' cs = Bio::ColorScheme.const_get(scheme.intern) [naseq, aaseq].each do |seq| html += display(seq, cs) end return ['
', "

#{cs}

", html, '
'] end if fna = ARGV.shift naseq = Bio::FlatFile.open(fna) { |ff| ff.next_entry.naseq } aaseq = naseq.translate else naseq = Bio::Sequence::NA.new('acgtu' * 20).randomize aaseq = naseq.translate end title = 'Bio::ColorScheme for DNA sequences' doc = ['', '
', '', title, '', '
', '', '

', title, '

'] doc << ['
', '

', 'Simple colors', '

'] ['Nucleotide'].each do |scheme| doc << display_scheme(scheme, naseq, "") end doc << ['
'] ['Zappo', 'Taylor' ].each do |scheme| doc << display_scheme(scheme, "", aaseq) end doc << [''] doc << ['
', '

', 'Score colors', '

'] ['Buried', 'Helix', 'Hydropathy', 'Strand', 'Turn'].each do |score| doc << display_scheme(score, "", aaseq) end doc << ['
'] puts doc + ['','']