Unverified Commit faa752ed authored by Nicola Soranzo's avatar Nicola Soranzo
Browse files

Fix type annotations

parent ce0f385a
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -667,7 +667,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)

    def init_meta(self, dataset: HasMetadata, copy_from: Optional[HasMetadata] = None) -> None:
        Binary.init_meta(self, dataset, copy_from=copy_from)
@@ -735,7 +735,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)
        except Exception:
            shutil.rmtree(tmp_dir, ignore_errors=True)
            raise
@@ -932,9 +932,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())
        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())
        dataset.metadata.bam_index = index_file

    def sniff(self, filename: str) -> bool:
@@ -1125,7 +1125,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())
            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 (
    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


+3 −2
Original line number Diff line number Diff line
import os
from typing import Optional

from galaxy.app_unittest_utils.toolbox_support import (
    BaseToolBoxTestCase,
@@ -71,7 +72,7 @@ class TestToolPanelManager(BaseToolBoxTestCase):

    def test_add_twice(self):
        self._init_dynamic_tool_conf()
        previous_guid = None
        previous_guid: Optional[str] = None
        for v in "1", "2", "3":
            self.__toolbox = self.get_new_toolbox()
            changeset = f"0123456789abcde{v}"
@@ -107,7 +108,7 @@ class TestToolPanelManager(BaseToolBoxTestCase):
            # New GUID replaced old one in tool panel but both
            # appear in integrated tool panel.
            if previous_guid:
                assert (f"tool_{previous_guid}") not in section.panel_items()  # type: ignore[unreachable]
                assert (f"tool_{previous_guid}") not in section.panel_items()
            assert (f"tool_{guid}") in self.toolbox._integrated_tool_panel["tid1"].panel_items()
            previous_guid = guid

+3 −2
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ standard out; some statistics are written to standard error.
from __future__ import print_function

import sys
from typing import Optional

import bx.align.axt
import bx.align.lav
@@ -48,7 +49,7 @@ def main():

    # parse the command line

    primary = None
    primary: Optional[str] = None
    secondary = None
    silent = False

@@ -74,7 +75,7 @@ def main():
        elif primary is None and val is None:
            primary = arg
        elif secondary is None and val is None:
            secondary = arg  # type: ignore[unreachable]
            secondary = arg
        else:
            usage("unknown argument: %s" % arg)

+11 −6
Original line number Diff line number Diff line
@@ -2,11 +2,16 @@
from __future__ import print_function

import sys
from typing import (
    List,
    Optional,
    Tuple,
)

from galaxy.datatypes.util.gff_util import parse_gff_attributes


def get_bed_line(chrom, name, strand, blocks):
def get_bed_line(chrom, name, strand, blocks: List[Tuple[int, int]]):
    """Returns a BED line for given data."""

    if len(blocks) == 1:
@@ -66,9 +71,9 @@ def __main__():
    first_skipped_line = 0
    i = 0
    cur_transcript_chrome = None
    cur_transcript_id = None
    cur_transcript_id: Optional[str] = None
    cur_transcript_strand = None
    cur_transcripts_blocks = []  # (start, end) for each block.
    cur_transcripts_blocks: List[Tuple[int, int]] = []  # (start, end) for each block.
    with open(output_name, "w") as out, open(input_name) as in_fh:
        for i, line in enumerate(in_fh):
            line = line.rstrip("\r\n")
@@ -77,7 +82,7 @@ def __main__():
                    # GFF format: chrom source, name, chromStart, chromEnd, score, strand, attributes
                    elems = line.split("\t")
                    start = str(int(elems[3]) - 1)
                    coords = [int(start), int(elems[4])]
                    coords = (int(start), int(elems[4]))
                    strand = elems[6]
                    if strand not in ["+", "-"]:
                        strand = "+"
@@ -92,7 +97,7 @@ def __main__():
                        # Write previous transcript.
                        if cur_transcript_id:
                            # Write BED entry.
                            out.write(  # type: ignore[unreachable]
                            out.write(
                                get_bed_line(
                                    cur_transcript_chrome,
                                    cur_transcript_id,
@@ -120,7 +125,7 @@ def __main__():
                    # Write previous transcript.
                    if cur_transcript_id:
                        # Write BED entry.
                        out.write(  # type: ignore[unreachable]
                        out.write(
                            get_bed_line(
                                cur_transcript_chrome, cur_transcript_id, cur_transcript_strand, cur_transcripts_blocks
                            )