Skip to content

Commit 68c1449

Browse files
authored
Update KMP.py
Updated the check on the FASTA format inputs, since other extensions than .fasta are possible for this type of files.
1 parent 1f1b9ab commit 68c1449

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

KMP.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,17 @@ def main():
138138

139139
if not os.path.exists(args2.DNA):
140140
errors.append(f"ERROR: DNA file '{args2.DNA}' not found")
141-
elif not args2.DNA.endswith(".fasta"):
142-
errors.append(f"ERROR: DNA file '{args2.DNA}' must be in FASTA format")
141+
else:
142+
with open(args2.DNA) as f:
143+
if not f.readline().startswith(">"):
144+
errors.append(f"ERROR: DNA file '{args2.DNA}' must be in FASTA format")
143145

144146
if not os.path.exists(args2.patterns):
145147
errors.append(f"ERROR: Pattern file '{args2.patterns}' not found")
146-
elif not args2.patterns.endswith(".fasta"):
147-
errors.append(f"ERROR: DNA file '{args2.patterns}' must be in FASTA format")
148+
else:
149+
with open(args2.patterns) as f:
150+
if not f.readline().startswith(">"):
151+
errors.append(f"ERROR: DNA file '{args2.patterns}' must be in FASTA format")
148152

149153
if errors:
150154
for error in errors:
@@ -191,4 +195,4 @@ def main():
191195
except EmptySequenceException as e:
192196
print(f"ERROR: {e.msg}")
193197
except ValueError as e:
194-
print(f"ERROR: {e}")
198+
print(f"ERROR: {e}")

0 commit comments

Comments
 (0)