title: How to fix "AttributeError: 'Seq' object has no attribute 'tostring'" when processing FASTA encoding?
body: <pre><code> import pandas as pd
   import numpy as np
   from Bio import*
   from Bio import SeqIO
   import time 
   import h5py
  
  
  
   def vectorizeSequence(seq):
  # the order of the letters is not arbitrary.
  # Flip the matrix up-down and left-right for reverse compliment
    ltrdict = {'a':[1,0,0,0],'c':[0,1,0,0],'g':[0,0,1,0],'t':[0,0,0,1], 'n':[0,0,0,0]}
        return np.array([ltrdict[x] for x in seq])
  
  
    starttime = time.time()
    fasta_sequences = SeqIO.parse(open(&quot;contigs.fasta&quot;),'fasta')
  
   #fasta_sequences = str(seq.seq)
  
   #GC(fasta_sequences)
  
     with h5py.File('genomeEncoded.h5', 'w') as hf:
        for fasta in fasta_sequences:
      # get the fasta files.
      
      name, sequence = fasta.id, fasta.seq.tostring()  # HERE APPEARS ERROR
      # Write the chromosome name
      new_file.write(name)
      #  encoding scheme
      data = vectorizeSequence(sequence.lower())
      print (name + &quot; is one hot encoded!&quot;)
      # write to hdf5 
      hf.create_dataset(name, data=data)
      print (name + &quot; is written to dataset&quot;)
  
  
    endtime = time.time()       
    print (&quot;Encoding is done in &quot; + str(endtime))
  </code></pre>
  <p>Traceback (most recent call last):
  File &quot;FASTA_ENCODING4ML.py&quot;, line 30, in 
  name, sequence = fasta.id, fasta.seq.tostring()
  AttributeError: 'Seq' object has no attribute 'tostring'</p>