-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3512 from mvdbeek/add_compressed_fastq_peek_and_p…
…review Add compressed fastq peek and preview
- Loading branch information
Showing
5 changed files
with
123 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import bz2 | ||
import gzip | ||
import zipfile | ||
|
||
from .checkers import ( | ||
is_bz2, | ||
is_gzip | ||
) | ||
|
||
|
||
def get_fileobj(filename, mode="r", gzip_only=False, bz2_only=False, zip_only=False): | ||
""" | ||
Returns a fileobj. If the file is compressed, return appropriate file reader. | ||
:param filename: path to file that should be opened | ||
:param mode: mode to pass to opener | ||
:param gzip_only: only open file if file is gzip compressed or not compressed | ||
:param bz2_only: only open file if file is bz2 compressed or not compressed | ||
:param zip_only: only open file if file is zip compressed or not compressed | ||
""" | ||
# the various compression readers don't support 'U' mode, | ||
# so we open in 'r'. | ||
if mode == 'U': | ||
cmode = 'r' | ||
else: | ||
cmode = mode | ||
if not bz2_only and not zip_only and is_gzip(filename): | ||
return gzip.GzipFile(filename, cmode) | ||
if not gzip_only and not zip_only and is_bz2(filename): | ||
return bz2.BZ2File(filename, cmode) | ||
if not bz2_only and not gzip_only and zipfile.is_zipfile(filename): | ||
return zipfile.os_zipfile(filename, cmode) | ||
return open(filename, mode) |