Unverified Commit 31a3d48f authored by mvdbeek's avatar mvdbeek
Browse files

Merge branch 'release_24.0' into release_24.1

parents 3bf2c268 bdcf09cd
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -570,7 +570,7 @@ class BamNative(CompressedArchive, _BamOrSam):
        :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)
@@ -638,7 +638,7 @@ class BamNative(CompressedArchive, _BamOrSam):
            [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
@@ -835,9 +835,9 @@ class Bam(BamNative):
            )
        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:
@@ -1028,7 +1028,7 @@ class CRAM(Binary):

    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)
+7 −3
Original line number Diff line number Diff line
import json

from pysam import (  # type: ignore[attr-defined]
from pysam import (  # type: ignore[attr-defined, unused-ignore]
    AlignmentFile,
    view,
)
@@ -16,8 +16,12 @@ from .util import (
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