Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

No option to flush VariantFile.write() (or at least undocumented) #1299

Closed
blex-max opened this issue Jul 11, 2024 · 2 comments
Closed

No option to flush VariantFile.write() (or at least undocumented) #1299

blex-max opened this issue Jul 11, 2024 · 2 comments

Comments

@blex-max
Copy link

blex-max commented Jul 11, 2024

Output is not written until the program completes. Is this something that could be added? Many thanks for your work.

@jmarshall
Copy link
Member

jmarshall commented Jul 12, 2024

Much as with ordinary Python I/O streams, you should call myvariantfile.close() when you have finished writing to it to ensure the output is flushed and the file closed in a timely fashion.

Alternatively VariantFile, AlignmentFile, etc can be used as context managers, so that the following would ensure the file is closed at the end of the with statement:

with pysam.VariantFile('foo.vcf', 'w') as f:
    f.write(record)
    …etc

Pysam could do more for flushing these files while writing them: there is an underlying HTSlib hts_flush() function that VariantFile, AlignmentFile, etc could expose as a flush() method. However I suspect most code would not really benefit from being able to do this.

@blex-max
Copy link
Author

In my case I'd like to be able to watch 'tail filename' output as it is produced, I find it useful for debugging

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants