#From ftp://ftp.ncbi.nlm.nih.gov/refseq/R_norvegicus/mRNA_Prot/rat.protein.faa.gz
#fasta_filename = "/home/maubp/rat.protein.faa"
fasta_filename = r"c:\temp\rat.protein.faa"


import time
import Bio
import Bio.SeqIO
import Bio.SeqIO.FASTA
import Bio.FormatIO
import Bio.Fasta
from Bio.Alphabet import generic_alphabet
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord

def method_Fasta_SequenceParser(handle) :
    myIterator = Bio.Fasta.Iterator(handle, Bio.Fasta.SequenceParser())
    count = 0
    for myRecord in myIterator :
        count = count + 1
    del myIterator
    return "Fasta.SequenceParser (for record in interator)", str(myRecord.__class__), count

def time_method(method, filename) :
    input_file = open(filename, 'rU')

    start = time.time()
    name, returnclass, count = method(input_file)
    end = time.time()

    input_file.close()

    return name, returnclass, count, end - start

for method in [method_Fasta_SequenceParser] :
    #Run test several times...
    for j in range(0,6) :
        name, returnclass, count, seconds = time_method(method, fasta_filename)
        print "%0.2fs %s" % (seconds, name)
