Open main menu

Biolecture.org β

Fasta code

Revision as of 13:32, 8 December 2018 by 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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)