Skip to content

Commit

Permalink
fix: check for paths and remove default file_type for stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Oct 25, 2023
1 parent abd90a0 commit 002d75b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ def _pysam_open(
:class:`~pysam.AlignmentFile`; may not include "mode".
"""

if isinstance(path, str) and open_for_reading and path in _STDIN_PATHS:
path = sys.stdin
elif isinstance(path, str) and not open_for_reading and path in _STDOUT_PATHS:
file_type = SamFileType.SAM if file_type is None else file_type
path = sys.stdout
elif isinstance(path, (str, Path)): # type: ignore
file_type = file_type or SamFileType.from_path(path)
path = str(path)
if isinstance(path, (str, Path)): # type: ignore
if str(path) in _STDIN_PATHS and open_for_reading:
path = sys.stdin
elif str(path) in _STDOUT_PATHS and not open_for_reading:
assert file_type is not None, "Must specify file_type when writing to stdout"
path = sys.stdout
else:
file_type = file_type or SamFileType.from_path(path)
path = str(path)
elif not isinstance(path, _IOClasses): # type: ignore
open_type = "reading" if open_for_reading else "writing"
raise TypeError(f"Cannot open '{type(path)}' for {open_type}.")
Expand Down

0 comments on commit 002d75b

Please sign in to comment.