Skip to content
Snippets Groups Projects
Commit 1b8ed5e9 authored by Vermaat's avatar Vermaat
Browse files

Improve file type detection when reading DNA

parent 7f009cbd
No related branches found
No related tags found
No related merge requests found
...@@ -357,15 +357,28 @@ def guess_file_type(handle): ...@@ -357,15 +357,28 @@ def guess_file_type(handle):
""" """
Guess the file type of an NGS data file. Guess the file type of an NGS data file.
We assume that the stream is rewinded before use, after use, the input :arg file handle: Open readable handle to an NGS data file.
stream will be rewinded.
:arg stream handle: Open readable handle to an NGS data file.
:returns unicode: Either 'fasta', 'fastq' or 'text'. :returns unicode: Either 'fasta', 'fastq' or 'text'.
""" """
try:
extension = getattr(handle, 'name').split('.')[-1]
except AttributeError:
pass
else:
if extension in ('fastq', 'fq'):
return 'fastq'
elif extension in ('fasta', 'fa'):
return 'fasta'
try:
position = handle.tell()
handle.seek(0)
except IOError:
return 'text'
token = handle.read(1) token = handle.read(1)
handle.seek(0) handle.seek(position)
if token == '>': if token == '>':
return 'fasta' return 'fasta'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment