Open main menu

Biolecture.org β

Changes

Fasta code

572 bytes added, 13:32, 8 December 2018
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..."
<pre>
def read_fasta(fp):
name, seq = None, []
for line in fp:
line = line.rstrip()
if line.startswith(&quot;&gt;&quot;):
if name: yield (name, &#39;&#39;.join(seq))
line=&quot;Genomics is great!&quot;
name, seq = line, []
else:
seq.append(line)
if name: yield (name, &#39;&#39;.join(seq))

seq=&#39;FASTA (10).fa.txt&#39;
fh=open(seq,&#39;r&#39;)
line=fh.read()
print(line)
with open(&#39;FASTA (10).fa.txt&#39;) as fp:
for name, seq in read_fasta(fp):
print(name,seq)
</pre>