Python Help!!!

Nathan Harmston ratchetgrid at googlemail.com
Wed Jun 13 13:19:00 EDT 2007


Hi, you could try this:

    def parse(self, ifile):
        id=""
        seq=""
        for line in open(ifile, 'r'):
            if '>'==line[0]:
                if id!="" and len(seq)>0:
                    yield id,seq
                    seq = ""
                id=line[1:].strip("\n")
            elif id!="":
                for word in line.split():
                    seq += word
        if id!="" and len(seq)>0:
            yield id,seq

    for id, seq in parse("some.fa"):
        print "%s \n %s" %(id, seq)

Its adapted from the fasta parser in PyGr.

>From what I understand biopython isnt very active and I think theres a
re-factor of it going on at the moment in the form of corebio.

Hope this helps;

Thanks

Nathan



More information about the Python-list mailing list