Skip to content

Commit c347680

Browse files
committed
Open file handle for sequences filtered by length
1 parent 59a4787 commit c347680

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tango/search.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ def filter_seqs_by_len(infile, outfile, minlen):
4646

4747
from Bio.SeqIO import parse, write
4848
i = 0
49-
for record in tqdm.tqdm(parse(infile, 'fasta'), unit=" sequences", ncols=100, desc="Filtering sequences"):
50-
if len(record) >= minlen:
51-
write(record, outfile, "fasta")
52-
i += 1
49+
with open(outfile, 'w') as fh:
50+
for record in tqdm.tqdm(parse(infile, 'fasta'), unit=" sequences", ncols=100, desc="Filtering sequences"):
51+
if len(record) >= minlen:
52+
write(record, fh, "fasta")
53+
i += 1
5354
sys.stderr.write("{} sequences longer than {} written to {}\n".format(i, minlen, outfile))
5455

5556

0 commit comments

Comments
 (0)