2 # = lib/evo/sequence/sequence.rb - Sequence class
4 # Copyright:: Copyright (C) 2006-2007 Christian M. Zmasek
5 # License:: GNU Lesser General Public License (LGPL)
7 # $Id: sequence.rb,v 1.10 2009/01/07 02:48:20 cmzmasek Exp $
16 molecular_sequence_str,
18 accession_source = nil,
21 secondary_accession = nil,
22 secondary_accession_source = nil )
23 @name = String.new( name.strip() )
24 @molecular_sequence = String.new( molecular_sequence_str )
25 if ( accession == nil )
26 @accession = String.new()
28 @accession = String.new( accession.strip() )
30 if ( accession_source == nil )
31 @accession_source = String.new()
33 @accession_source = String.new( accession_source.strip() )
37 @symbol = String.new()
39 @symbol = String.new( symbol.strip() )
41 if ( secondary_accession == nil )
42 @secondary_accession = String.new()
44 @secondary_accession = String.new( secondary_accession.strip() )
46 if ( secondary_accession_source == nil )
47 @secondary_accession_source = String.new()
49 @secondary_accession_source = String.new( secondary_accession_source.strip() )
54 if get_taxonomy == nil
55 Sequence.new( get_name, get_sequence_as_string, get_accession, get_accession_source, nil, get_symbol, get_secondary_accession, get_secondary_accession_source )
57 Sequence.new( get_name, get_sequence_as_string, get_accession, get_accession_source, get_taxonomy.copy, get_symbol, get_secondary_accession, get_secondary_accession_source )
69 def get_sequence_as_string()
77 def get_accession_source()
81 def get_secondary_accession()
85 def get_secondary_accession_source()
86 @secondary_accession_source
98 @molecular_sequence.length
101 def get_residue( position )
102 get_slice( position, 1 )
105 def get_character_code( position )
106 @molecular_sequence.getbyte( position )
110 return get_gap_length().to_f / get_length()
115 for i in 0 ... get_length()
116 if ( Util.is_aa_gap_character?( get_character_code( i ) ) )
123 def delete_residue!( position )
124 if ( position < 0 || position >= get_length() )
125 error_msg = "attempt to delete residue at postion out of range"
126 raise ArgumentError, error_msg
128 @molecular_sequence.slice!( position )
131 def get_slice( start, length )
132 if ( start < 0 || start + length > get_length() )
133 error_msg = "attempt to get sequence residue(s) at postion out of range"
134 raise ArgumentError, error_msg
136 @molecular_sequence.slice( start, length )
139 def get_slice!( start, length )
140 if ( start < 0 || start + length > get_length() )
141 error_msg = "attempt to get sequence residue(s) at postion out of range"
142 raise ArgumentError, error_msg
144 @molecular_sequence.slice!( start, length )
147 def get_subsequence( first, last )
149 error_msg = "attempt to get subsequence from " + first + " to " + last
150 raise ArgumentError, error_msg
152 return Sequence.new( get_name, @molecular_sequence.slice( first, last - first + 1 ) )
155 def append!( molecular_sequence_str )
156 @molecular_sequence.concat( molecular_sequence_str )
160 return "[" + @name + "] " + @molecular_sequence
164 return ">" + @name + Constants::LINE_DELIMITER + @molecular_sequence