Skip to content

Commit b39d718

Browse files
committed
Add support for gzipped FASTA files (.gz) as input
1 parent 748da65 commit b39d718

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

scripts/generation/generate_control_peptides.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22
import argparse
3+
import gzip
34
import random
45
import sys
56
from pathlib import Path
@@ -11,9 +12,17 @@ def generate_random_peptides(length: int, count: int) -> List[str]:
1112
return ["".join(random.choices(AMINO_ACIDS, k=length)) for _ in range(count)]
1213

1314
def parse_fasta_sequences(fasta_path: Path) -> List[str]:
15+
"""Parse FASTA sequences from plain text or gzipped files."""
1416
sequences = []
1517
seq = []
16-
with open(fasta_path, 'r') as f:
18+
19+
# Determine if file is gzipped based on extension
20+
if str(fasta_path).endswith('.gz'):
21+
open_func = lambda: gzip.open(fasta_path, 'rt') # 'rt' for text mode
22+
else:
23+
open_func = lambda: open(fasta_path, 'r')
24+
25+
with open_func() as f:
1726
for line in f:
1827
line = line.strip()
1928
if not line:

0 commit comments

Comments
 (0)