diff -r b442318ffd34 tools/fasta_tools/fasta_filter_by_length.py
--- a/tools/fasta_tools/fasta_filter_by_length.py	Mon Jan 12 14:52:30 2009 +0000
+++ b/tools/fasta_tools/fasta_filter_by_length.py	Wed Jan 14 16:17:38 2009 +0000
@@ -25,47 +25,35 @@ def __main__():
     except:
         stop_err( "Maximum length of the return sequence requires a numerical value." )
     output_filename = sys.argv[4]
-    tmp_title = tmp_seq = ''
+    output_handle = open( output_filename, 'w' )
+    
     tmp_seq_count = 0
-    seq_hash = {}
+    tmp_size = -1
+    tmp_buf = ''
+    at_least_one = 0
 
-    for i, line in enumerate( file( input_filename ) ):
-        line = line.rstrip( '\r\n' )
-        if not line or line.startswith( '#' ):
+    for line in file(input_filename):
+        if not line or line.startswith('#'):
             continue
         if line[0] == '>':
-            if len( tmp_seq ) > 0:
+            if min_length <= tmp_size <= max_length:
                 tmp_seq_count += 1
-                seq_hash[ ( tmp_seq_count, tmp_title ) ] = tmp_seq
-            tmp_title = line
-            tmp_seq = ''
+                output_handle.write(tmp_buf)
+                at_least_one = 1
+            tmp_buf = line
+            tmp_size = 0
+                                                                
         else:
-            tmp_seq = "%s%s" % ( tmp_seq, line ) 
-            if line.split()[0].isdigit():
-                tmp_seq = "%s " % tmp_seq
-    if len( tmp_seq ) > 0:
-        seq_hash[ ( tmp_seq_count, tmp_title ) ] = tmp_seq
+            if tmp_size < max_length:
+                tmp_size += len(line.rstrip('\r\n'))
+                tmp_buf += line
     
-    title_keys = seq_hash.keys()
-    title_keys.sort()
-    output_handle = open( output_filename, 'w' )
-    at_least_one = 0
-    for i, fasta_title in title_keys:
-        tmp_seq = seq_hash[ ( i, fasta_title ) ]
-        if max_length <= 0: 
-            compare_max_length = len( tmp_seq ) + 1
-        else:
-            compare_max_length = max_length
-        l = len( tmp_seq )
-        if l >= min_length and l <= compare_max_length:
-            at_least_one += 1
-            output_handle.write( "%s\n" % fasta_title )
-            c = 0
-            s = tmp_seq
-            while c < l:
-                b = min( c + 50, l )
-                output_handle.write( "%s\n" % s[ c:b ] )   
-                c = b
+    # final flush of buffer
+    if min_length <= tmp_size <= max_length:
+        tmp_seq_count += 1
+        output_handle.write(tmp_buf)
+        at_least_one = 1
+                                        
     output_handle.close()
 
     if at_least_one == 0:
diff -r b442318ffd34 tools/fasta_tools/fasta_to_tabular.py
--- a/tools/fasta_tools/fasta_to_tabular.py	Mon Jan 12 14:52:30 2009 +0000
+++ b/tools/fasta_tools/fasta_to_tabular.py	Wed Jan 14 16:17:38 2009 +0000
@@ -23,29 +23,20 @@ def __main__():
     else:
         keep_first += 1
 
-    for i, line in enumerate( open( infile ) ):
+    out = open(outfile, 'w')
+        
+    for (i, line) in enumerate(file(infile)):
         line = line.rstrip( '\r\n' )
         if not line or line.startswith( '#' ):
             continue
         if line.startswith( '>' ):
-            if sequence:
-                sequence_count += 1
-                seq_hash[( sequence_count, title )] = sequence
-            title = line
-            sequence = ''
+            if i: 
+                out.write('\n')
+            out.write(line[:keep_first])
+            out.write('\t')
         else:
-            sequence = "%s%s" % ( sequence, line )
-            if line.split() and line.split()[0].isdigit():
-                sequence += ' '
-    if sequence:
-        seq_hash[( sequence_count, title )] = sequence
-    # return only those lengths are in the range
-    title_keys = seq_hash.keys()
-    title_keys.sort()
-    out = open( outfile, 'w' )
-    for i, fasta_title in title_keys:
-        sequence = seq_hash[( i, fasta_title )]
-        out.write( "%s\t%s\n" %( fasta_title[ 1:keep_first ], sequence ) )
+            out.write(line)
+            
     out.close()
 
 if __name__ == "__main__" : __main__()
\ No newline at end of file
