[Tutor] Phyton script for fasta file (seek help)

Ali Torkamani torkamani at gmail.com
Wed Apr 10 17:16:22 CEST 2013


I have written the following function for reading fasta files, I hope this
helps:

Ali

def ReadFasta(filename):

    dictFasta=dict()
    prevLine='';
    try:

        f = open(filename, "r")

        for line in f:
            print line
            line=line.lower()
            line=line.strip()
            if len(line)==0: continue
            if (not(line[0]>='a' and line[0]<='z')) and line[0]!='>':
continue
            if line[0]=='>':
                prevLine=line[1:]
                dictFasta[prevLine]=''
            else:
                dictFasta[prevLine]=dictFasta[prevLine]+line

        f.close()
    except IOError:
        print 'error opening %s'%(filename)
        pass
    return dictFasta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130410/8edfaf66/attachment.html>


More information about the Tutor mailing list