Skip to content
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

HTSlib warnings can't be suppressed? #1303

Open
ohickl opened this issue Aug 14, 2024 · 0 comments
Open

HTSlib warnings can't be suppressed? #1303

ohickl opened this issue Aug 14, 2024 · 0 comments

Comments

@ohickl
Copy link

ohickl commented Aug 14, 2024

Description:

Hi,

I'm encountering a persistent warning message when working with SAM/BAM files using pysam, and I'm seeking your advice on how to suppress or resolve it.

Issue Description

When processing my SAM/BAM files with pysam, I frequently receive the following warning message:

    [W::sam_hrecs_update_hashes] PG line with multiple ID tags. The first encountered was preferred ...

I understand that this warning is generated when pysam (or the underlying htslib library) encounters multiple PG (Program) lines in the file header with the same ID tag, and that the software defaults to using the first ID it encounters.
I know the reason for this in this instance and want to ignore it.

Steps I’ve Tried to Suppress the Warning

I’ve attempted several common methods to suppress or redirect this warning, including:

  • Using Python's warnings.filterwarnings:
    import warnings
    warnings.filterwarnings("ignore", message=".*PG line with multiple ID tags.*", category=UserWarning, module="pysam")

This approach did not suppress the warning, possibly because it's not using Python’s standard warning system.

  • Redirecting sys.stderr:
    import sys
    import os
    from contextlib import redirect_stderr

    with open(os.devnull, 'w') as fnull:
        with redirect_stderr(fnull):
            # Code that triggers the warning

This also did not work, which leads me to believe the message is being printed by the underlying C library in a way that bypasses Python’s standard output streams.

My Questions

  • Is there a recommended method to suppress or redirect this specific warning message?
  • If this is a common issue, would it be possible to add an option in pysam to suppress such warnings?

Any advice or guidance you can provide would be greatly appreciated. Thank you for your time and for maintaining this incredibly useful library!

Environment:

pysam version: 0.22.1
Python version: 3.12.4
Operating System: Nobara Linux 40 (KDE Plasma)

Best,

Oskar

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

No branches or pull requests

1 participant