1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/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 <n@bioruby.org>
# License:: The Ruby License
#
#
require 'bio'
# returns folded sequence with <br>.
def br(i, width = 80)
return "<br\n>" if i % width == 0
""
end
# returns sequence html doc
def display(seq, cs)
html = '<p style="font-family: monospace">'
postfix = '</span>'
i = 0
seq.each_char do |c|
color = cs[c]
prefix = %Q(<span style="background:\##{color};">)
html += prefix + c + postfix
html += br(i += 1)
end
html + '</p>'
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 ['<div>', "<h3>#{cs}</h3>", html, '</div>']
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 = ['<html>',
'<header>', '<title>', title, '</title>', '</header>',
'<body>', '<h1>', title, '</h1>']
doc << ['<div>', '<h2>', 'Simple colors', '</h2>']
['Nucleotide'].each do |scheme|
doc << display_scheme(scheme, naseq, "")
end
doc << ['</div>']
['Zappo', 'Taylor' ].each do |scheme|
doc << display_scheme(scheme, "", aaseq)
end
doc << ['</div>']
doc << ['<div>', '<h2>', 'Score colors', '</h2>']
['Buried', 'Helix', 'Hydropathy', 'Strand', 'Turn'].each do |score|
doc << display_scheme(score, "", aaseq)
end
doc << ['</div>']
puts doc + ['</body>','</html>']
|