-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support stdin/stdout special cases in sam.reader/writer #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think we should remove it default to SAM when writing to stdout and keep the requirement that
file_type
must be given when writing (the Args needed to be updated otherwise). - See here for how pysam tests stdin/stdout:
https://github.com/pysam-developers/pysam/blob/cdc0ed12fbe2d7633b8fa47534ab2c2547f66b84/tests/StreamFiledescriptors_test.py#L47-L65
I would argue that it is helpful to set a default Essentially, I want to be able to do the following, and have it work sensibly whether def my_tool(
*,
in_bam: Path,
out_bam: Path,
):
"""
Run my tool.
"""
with (
reader(in_bam) as bam_reader,
writer(out_bam, header=bam_reader.header) as bam_writer
):
pass If |
I think it's a footgun to have it default to a SAM file type if writing to standard output in library code. Let's go without it defaulting to SAM please. |
I agree with Nils about not defaulting to SAM. If anything I would say it should default to uncompressed BAM as that's what I'd want when piping between tools ... and if a user wrote directly to stdout you'd quickly see it. But this points out why it should probably not have a default - because I'd argue for a different one. I think the PR also needs to handle what if a user passes e.g. |
Will circle back to add tests, but made the requested changes. Follow-up question: When opening from a filepath, should we require that the file type be inferred from the file extension, rather than giving the user the opportunity to specify a Line 255 in 002d75b
|
I think the follow-up question deserves a separate issue. See comment in the code pysam-developers/pysam#655 and a similar issue our other rust repo: fulcrumgenomics/fgoxide#9. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use standard output
versus stdout
in the docstrings etc.
chore: type hints fix: check for paths and remove default file_type for stdout doc: add docs Update fgpyo/sam/__init__.py Co-authored-by: Nils Homer <[email protected]> Update fgpyo/sam/__init__.py Co-authored-by: Nils Homer <[email protected]> Update fgpyo/sam/__init__.py Co-authored-by: Nils Homer <[email protected]> Update fgpyo/sam/__init__.py Co-authored-by: Nils Homer <[email protected]> Update fgpyo/sam/__init__.py Co-authored-by: Nils Homer <[email protected]> Update fgpyo/sam/__init__.py Co-authored-by: Nils Homer <[email protected]> chore: line wrap docstrings
Addressing #67
@nh13 @tfenne would you entertain something like this?
Two open questions
stdout
should default to SAM or BAMsys.stdin
I've usedpytest.MonkeyPatch
and aStringIO
, butpysam
doesn't support reading fromStringIO