Difference between revisions of "Fasta code"

From Biolecture.org
imported>Na kyung Jung
(Created page with "<pre> def read_fasta(fp): name, seq = None, [] for line in fp: line = line.rstrip() if line.startswith(">"): if name: yield (name...")
(No difference)

Revision as of 13:32, 8 December 2018

def read_fasta(fp):
    name, seq = None, []
    for line in fp:
        line = line.rstrip()
        if line.startswith(">"):
            if name: yield (name, ''.join(seq))
            line="Genomics is great!"
            name, seq = line, []
        else:
            seq.append(line)
    if name: yield (name, ''.join(seq))

seq='FASTA (10).fa.txt'
fh=open(seq,'r')
line=fh.read()
print(line)
with open('FASTA (10).fa.txt') as fp:
    for name, seq in read_fasta(fp):
        print(name,seq)