diff GAFA.py @ 3:e17a3470c70a draft

planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/GAFA/ commit 988b1fc1cb8739e45648465adbf099f3fdaf87f8
author earlhaminst
date Fri, 03 Mar 2017 07:20:23 -0500
parents fc8ca4ade638
children 117fc7414307
line wrap: on
line diff
--- a/GAFA.py	Mon Feb 20 12:19:21 2017 -0500
+++ b/GAFA.py	Fri Mar 03 07:20:23 2017 -0500
@@ -12,20 +12,20 @@
 
 
 def FASTAReader_gen(fasta_filename):
-    fasta_file = open(fasta_filename)
-    line = fasta_file.readline()
-    while True:
-        if not line:
-            return
-        assert line.startswith('>'), "FASTA headers must start with >"
-        header = line.rstrip()
-        sequence_parts = []
+    with open(fasta_filename) as fasta_file:
         line = fasta_file.readline()
-        while line and line[0] != '>':
-            sequence_parts.append(line.rstrip())
+        while True:
+            if not line:
+                return
+            assert line.startswith('>'), "FASTA headers must start with >"
+            header = line.rstrip()
+            sequence_parts = []
             line = fasta_file.readline()
-        sequence = "".join(sequence_parts)
-        yield Sequence(header, sequence)
+            while line and line[0] != '>':
+                sequence_parts.append(line.rstrip())
+                line = fasta_file.readline()
+            sequence = "".join(sequence_parts)
+            yield Sequence(header, sequence)
 
 
 FASTA_MATCH_RE = re.compile(r'[^-]')