+++ /dev/null
-class BioPieces
- RECORD_DELIMITER = "\n---\n"
-
- class Record
- attr_reader :__hash__
-
- def initialize( data )
- @__hash__ = data
- end
-
- def method_missing( name, *args, &block )
- if args.empty? && @__hash__.has_key?( name ) then
- @__hash__[ name ]
- else
- super # get the original exception
- end
- end
-
- def to_s
- @__hash__.map { | key, value | "#{ key }: #{ value }" }.join( "\n" ) + RECORD_DELIMITER
- end
-
- def to_hash
- @__hash__.dup
- end
- end
-
- def self.file( path )
- bp = new( File.open( path ) )
- yield bp if block_given?
- bp
- ensure
- # if no block was given, the user wants the BioPieces instance
- # with a still open File so he can read it, so only close if a block
- # had been given.
- bp.close if block_given?
- end
-
- def initialize( stream )
- @stream = stream
- end
-
- def close
- @stream.close if @stream.respond_to? :close
- end
-
- def record_get
- return unless block = @stream.gets( RECORD_DELIMITER )
-
- block.chomp!( RECORD_DELIMITER )
- data = Hash[ *block.split( /: |\n/, 2 ) ]
- Record.new( data )
- end
-
- def each
- yield record_get until @stream.eof?
- self # not to have a messy return value
- end
-end
-
-
-__END__
--- /dev/null
+class BioPieces
+ RECORD_DELIMITER = "\n---\n"
+
+ class Record
+ attr_reader :__hash__
+
+ def initialize( data )
+ @__hash__ = data
+ end
+
+ def method_missing( name, *args, &block )
+ if args.empty? && @__hash__.has_key?( name ) then
+ @__hash__[ name ]
+ else
+ super # get the original exception
+ end
+ end
+
+ def to_s
+ @__hash__.map { | key, value | "#{ key }: #{ value }" }.join( "\n" ) + RECORD_DELIMITER
+ end
+
+ def to_hash
+ @__hash__.dup
+ end
+ end
+
+ def self.file( path )
+ bp = new( File.open( path ) )
+ yield bp if block_given?
+ bp
+ ensure
+ # if no block was given, the user wants the BioPieces instance
+ # with a still open File so he can read it, so only close if a block
+ # had been given.
+ bp.close if block_given?
+ end
+
+ def initialize( stream )
+ @stream = stream
+ end
+
+ def close
+ @stream.close if @stream.respond_to? :close
+ end
+
+ def record_get
+ return unless block = @stream.gets( RECORD_DELIMITER )
+
+ block.chomp!( RECORD_DELIMITER )
+ data = Hash[ *block.split( /: |\n/, 2 ) ]
+ Record.new( data )
+ end
+
+ def each
+ yield record_get until @stream.eof?
+ self # not to have a messy return value
+ end
+end
+
+
+__END__
assert_equal( :DNA, s.seq_type )
end
+ # Testing Seq#to_s
+ def test_to_s
+ s = Seq.new( "ATCG" )
+ assert_equal( "ATCG", s.to_s )
+ end
+
# Testing Seq#seq_type_guess
def test_seq_type_guess_DNA_uppercase
def test_wrap_with_0_args
s = Seq.new( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACGACTACGACT" )
- assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.wrap )
+ assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.wrap.to_s )
end
def test_wrap_with_1_args
s = Seq.new( "ATCG" )
- assert_equal( "AT\nCG", s.wrap( 2 ) )
+ assert_equal( "AT\nCG", s.wrap( 2 ).to_s )
end
def test_wrap_with_2_args
s = Seq.new( "ATCG" )
- assert_equal( "AT\rCG", s.wrap( 2, "\r" ) )
+ assert_equal( "AT\rCG", s.wrap( 2, "\r" ).to_s )
end
def test_wrap_dont_change_instance_var
s.wrap( 2 )
- assert_equal( "ATCG", s.seq )
+ assert_equal( "ATCG", s.to_s )
end
# Testing Seq#wrap!
s.wrap!
- assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.seq )
+ assert_equal( "ACTGACTAGCATCGACTACGACTGACACGACGACGACGACCGAACGATCGATCGCAGACGACGCAGCATGACGACGTACG\nACTACGACT", s.to_s )
end
def test_wrap_with_1_args!
s.wrap!( 2 )
- assert_equal( "AT\nCG", s.seq )
+ assert_equal( "AT\nCG", s.to_s )
end
def test_wrap_with_2_args!
s.wrap!( 2, "\r" )
- assert_equal( "AT\rCG", s.seq )
+ assert_equal( "AT\rCG", s.to_s )
end
# Testing Seq#generate
seq = s.generate( 40 )
- assert_equal( "", s.seq )
+ assert_equal( "", s.to_s )
end
# Testing Seq#generate!
def test_generate!
s = Seq.new( "", :AA )
- gen_seq = s.generate!( 40 )
+ gen_seq = s.generate!( 40 ).to_s
assert_equal( 40, gen_seq.length )
assert_equal( 40, s.seq.length )
- assert_equal( gen_seq, s.seq )
+ assert_equal( gen_seq, s.to_s )
end
# Testing Seq::AA#initialize
# test marked for deletion - too simple and not informative
def test_Seq_AA_initialize_with_0_args
s = Seq::AA.new
- assert_equal( "", s.seq )
+ assert_equal( "", s.to_s )
assert_equal( :AA, s.seq_type )
end
# test marked for deletion - too simple and not informative
def test_Seq_AA_initialize_with_1_args
s = Seq::AA.new( "SEQ" )
- assert_equal( "SEQ", s.seq )
+ assert_equal( "SEQ", s.to_s )
assert_equal( :AA, s.seq_type )
end
end