Skip to content

Commit

Permalink
Merge pull request #19571 from nsoranzo/release_24.0_fix_annot
Browse files Browse the repository at this point in the history
[24.0] Fix type annotations for pysam 0.23.0
  • Loading branch information
mvdbeek authored Feb 10, 2025
2 parents 1dcfdec + 318aa57 commit bdcf09c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit bdcf09c

Please sign in to comment.