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

[24.0] Fix type annotations for pysam 0.23.0 #19571

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def merge(split_files: List[str], output_file: str) -> None:
:param split_files: List of bam file paths to merge
:param output_file: Write merged bam file to this location
"""
pysam.merge("-O", "BAM", output_file, *split_files) # type: ignore[attr-defined]
pysam.merge("-O", "BAM", output_file, *split_files) # type: ignore[attr-defined, unused-ignore]

def init_meta(self, dataset: HasMetadata, copy_from: Optional[HasMetadata] = None) -> None:
Binary.init_meta(self, dataset, copy_from=copy_from)
Expand Down Expand Up @@ -638,7 +638,7 @@ def groom_dataset_content(self, file_name: str) -> None:
[f"-@{slots}", file_name, "-T", tmp_sorted_dataset_file_name_prefix, "-O", "BAM", "-o", sorted_file_name]
)
try:
pysam.sort(*sort_args) # type: ignore[attr-defined]
pysam.sort(*sort_args) # type: ignore[attr-defined, unused-ignore]
except Exception:
shutil.rmtree(tmp_dir, ignore_errors=True)
raise
Expand Down Expand Up @@ -835,9 +835,9 @@ def set_meta(
)
if index_flag == "-b":
# IOError: No such file or directory: '-b' if index_flag is set to -b (pysam 0.15.4)
pysam.index("-o", index_file.get_file_name(), dataset.get_file_name()) # type: ignore [attr-defined]
pysam.index("-o", index_file.get_file_name(), dataset.get_file_name()) # type: ignore[attr-defined, unused-ignore]
else:
pysam.index(index_flag, "-o", index_file.get_file_name(), dataset.get_file_name()) # type: ignore [attr-defined]
pysam.index(index_flag, "-o", index_file.get_file_name(), dataset.get_file_name()) # type: ignore[attr-defined, unused-ignore]
dataset.metadata.bam_index = index_file

def sniff(self, filename: str) -> bool:
Expand Down Expand Up @@ -1028,7 +1028,7 @@ def get_cram_version(self, filename: str) -> Tuple[int, int]:

def set_index_file(self, dataset: HasFileName, index_file) -> bool:
try:
pysam.index("-o", index_file.get_file_name(), dataset.get_file_name()) # type: ignore [attr-defined]
pysam.index("-o", index_file.get_file_name(), dataset.get_file_name()) # type: ignore[attr-defined, unused-ignore]
return True
except Exception as exc:
log.warning("%s, set_index_file Exception: %s", self, exc)
Expand Down
10 changes: 7 additions & 3 deletions test/unit/data/datatypes/test_bam.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from pysam import ( # type: ignore[attr-defined]
from pysam import ( # type: ignore[attr-defined, unused-ignore]
AlignmentFile,
view,
)
Expand All @@ -16,8 +16,12 @@
def test_merge_bam():
with get_input_files("1.bam", "1.bam") as input_files, get_tmp_path() as outpath:
Bam.merge(input_files, outpath)
alignment_count_output = int(view("-c", outpath).strip())
alignment_count_input = int(view("-c", input_files[0]).strip()) * 2
ret = view("-c", outpath)
assert isinstance(ret, str)
alignment_count_output = int(ret.strip())
ret = view("-c", input_files[0])
assert isinstance(ret, str)
alignment_count_input = int(ret.strip()) * 2
assert alignment_count_input == alignment_count_output


Expand Down
Loading