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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#
# = bio/sequence/compat.rb - methods for backward compatibility
#
# Copyright:: Copyright (C) 2006
# Toshiaki Katayama <k@bioruby.org>,
# Ryan Raaum <ryan@raaum.org>
# License:: The Ruby License
#
module Bio
require 'bio/sequence' unless const_defined?(:Sequence)
class Sequence
# Return sequence as
# String[http://corelib.rubyonrails.org/classes/String.html].
# The original sequence is unchanged.
#
# seq = Bio::Sequence.new('atgc')
# puts s.to_s #=> 'atgc'
# puts s.to_s.class #=> String
# puts s #=> 'atgc'
# puts s.class #=> Bio::Sequence
# ---
# *Returns*:: String object
def to_s
String.new(self.seq)
end
alias to_str to_s
module Common
# <b>Bio::Sequence#to_fasta is DEPRECATED</b>
# Do not use Bio::Sequence#to_fasta ! Use Bio::Sequence#output instead.
# Note that Bio::Sequence::NA#to_fasta, Bio::Sequence::AA#to_fasata,
# and Bio::Sequence::Generic#to_fasta <b>can still be used</b>,
# because there are no alternative methods.
#
# Output the FASTA format string of the sequence. The 1st argument is
# used as the comment string. If the 2nd option is given, the output
# sequence will be folded.
# ---
# *Arguments*:
# * (optional) _header_: String object
# * (optional) _width_: Fixnum object (default nil)
# *Returns*:: String
def to_fasta(header = '', width = nil)
warn "Bio::Sequence#to_fasta is obsolete. Use Bio::Sequence#output(:fasta) instead" if $DEBUG
">#{header}\n" +
if width
self.to_s.gsub(Regexp.new(".{1,#{width}}"), "\\0\n")
else
self.to_s + "\n"
end
end
end # Common
class NA
# Generate a new random sequence with the given frequency of bases.
# The sequence length is determined by their cumulative sum.
# (See also Bio::Sequence::Common#randomize which creates a new
# randomized sequence object using the base composition of an existing
# sequence instance).
#
# counts = {'a'=>1,'c'=>2,'g'=>3,'t'=>4}
# puts Bio::Sequence::NA.randomize(counts) #=> "ggcttgttac" (for example)
#
# You may also feed the output of randomize into a block
#
# actual_counts = {'a'=>0, 'c'=>0, 'g'=>0, 't'=>0}
# Bio::Sequence::NA.randomize(counts) {|x| actual_counts[x] += 1}
# actual_counts #=> {"a"=>1, "c"=>2, "g"=>3, "t"=>4}
# ---
# *Arguments*:
# * (optional) _hash_: Hash object
# *Returns*:: Bio::Sequence::NA object
def self.randomize(*arg, &block)
self.new('').randomize(*arg, &block)
end
def pikachu #:nodoc:
self.dna.tr("atgc", "pika") # joke, of course :-)
end
end # NA
class AA
# Generate a new random sequence with the given frequency of bases.
# The sequence length is determined by their cumulative sum.
# (See also Bio::Sequence::Common#randomize which creates a new
# randomized sequence object using the base composition of an existing
# sequence instance).
#
# counts = {'R'=>1,'L'=>2,'E'=>3,'A'=>4}
# puts Bio::Sequence::AA.randomize(counts) #=> "AAEAELALRE" (for example)
#
# You may also feed the output of randomize into a block
#
# actual_counts = {'R'=>0,'L'=>0,'E'=>0,'A'=>0}
# Bio::Sequence::AA.randomize(counts) {|x| actual_counts[x] += 1}
# actual_counts #=> {"A"=>4, "L"=>2, "E"=>3, "R"=>1}
# ---
# *Arguments*:
# * (optional) _hash_: Hash object
# *Returns*:: Bio::Sequence::AA object
def self.randomize(*arg, &block)
self.new('').randomize(*arg, &block)
end
end # AA
end # Sequence
end # Bio
|