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...")
 
imported>Na kyung Jung
(Blanked the page)
 
Line 1: Line 1:
<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>
 

Latest revision as of 13:35, 8 December 2018