Skip to content

Commit

Permalink
Merge pull request #1008 from marcelm/type-hints
Browse files Browse the repository at this point in the history
Start adding type hints
  • Loading branch information
AndreasHeger authored Mar 24, 2022
2 parents d94fe42 + 83e4873 commit 2a5e55e
Show file tree
Hide file tree
Showing 19 changed files with 1,269 additions and 20 deletions.
8 changes: 4 additions & 4 deletions pysam/Pileup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pysam

PileupSubstitution = collections.namedtuple("PileupSubstitution",
" ".join((
(
"chromosome",
"pos",
"reference_base",
Expand All @@ -13,10 +13,10 @@
"mapping_quality",
"coverage",
"read_bases",
"base_qualities")))
"base_qualities"))

PileupIndel = collections.namedtuple("PileupIndel",
" ".join((
(
"chromosome",
"pos",
"reference_base",
Expand All @@ -29,7 +29,7 @@
"second_allele",
"reads_first",
"reads_second",
"reads_diff")))
"reads_diff"))


def iterate(infile):
Expand Down
29 changes: 15 additions & 14 deletions pysam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sysconfig

from pysam.libchtslib import *
import pysam.libchtslib as libchtslib
from pysam.libcsamtools import *
from pysam.libcbcftools import *
from pysam.libcutils import *
Expand Down Expand Up @@ -31,21 +32,21 @@


# export all the symbols from separate modules
__all__ = \
libchtslib.__all__ +\
libcutils.__all__ +\
libctabix.__all__ +\
libcvcf.__all__ +\
libcbcf.__all__ +\
libcbgzf.__all__ +\
libcfaidx.__all__ +\
libctabixproxies.__all__ +\
libcalignmentfile.__all__ +\
libcalignedsegment.__all__ +\
libcsamfile.__all__ +\
["SamtoolsError"] +\
__all__ = (
libchtslib.__all__ + # type: ignore
libcutils.__all__ + # type: ignore
libctabix.__all__ + # type: ignore
libcvcf.__all__ + # type: ignore
libcbcf.__all__ + # type: ignore
libcbgzf.__all__ + # type: ignore
libcfaidx.__all__ + # type: ignore
libctabixproxies.__all__ + # type: ignore
libcalignmentfile.__all__ + # type: ignore
libcalignedsegment.__all__ + # type: ignore
libcsamfile.__all__ + # type: ignore
["SamtoolsError"] +
["Pileup"]

)
from pysam.version import __version__, __samtools_version__


Expand Down
216 changes: 216 additions & 0 deletions pysam/libcalignedsegment.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import enum
import re
import sys
from array import array
from typing import Any, List, Optional, Dict, Tuple, Union, overload

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal

from pysam import AlignmentHeader # type: ignore

CMATCH: int
CINS: int
CDEL: int
CREF_SKIP: int
CSOFT_CLIP: int
CHARD_CLIP: int
CPAD: int
CEQUAL: int
CDIFF: int
CBACK: int

FPAIRED: int
FPROPER_PAIR: int
FUNMAP: int
FMUNMAP: int
FREVERSE: int
FMREVERSE: int
FREAD1: int
FREAD2: int
FSECONDARY: int
FQCFAIL: int
FDUP: int
FSUPPLEMENTARY: int

CIGAR2CODE: Dict[int, str]
CIGAR_REGEX: re.Pattern
DATATYPE2FORMAT: Dict[int, Tuple[str, int]]
KEY_NAMES: List[str]

TagValue = Union[str, int, float, array]

class CIGAR_OPS(enum.IntEnum):
CBACK: int
CDEL: int
CDIFF: int
CEQUAL: int
CHARD_CLIP: int
CINS: int
CMATCH: int
CPAD: int
CREF_SKIP: int
CSOFT_CLIP: int

class SAM_FLAGS(enum.IntEnum):
FDUP: int
FMREVERSE: int
FMUNMAP: int
FPAIRED: int
FPROPER_PAIR: int
FQCFAIL: int
FREAD1: int
FREAD2: int
FREVERSE: int
FSECONDARY: int
FSUPPLEMENTARY: int
FUNMAP: int

class AlignedSegment:
header: AlignmentHeader
query_name: Optional[str]
flag: int
reference_name: Optional[str]
reference_id: int
reference_start: int
mapping_quality: int
cigarstring: Optional[str]
next_reference_id: int
next_reference_name: Optional[str]
next_reference_start: int
template_length: int
query_sequence: Optional[str]
query_qualities: Optional[array]
bin: int
is_paired: bool
is_proper_pair: bool
is_unmapped: bool
mate_is_unmapped: bool
is_reverse: bool
mate_is_reverse: bool
is_read1: bool
is_read2: bool
is_secondary: bool
is_qcfail: bool
is_duplicate: bool
is_supplementary: bool
cigartuples: Optional[List[Tuple[int, int]]]
def __init__(self, header: Optional[AlignmentHeader] = ...) -> None: ...
def compare(self, other: Any) -> int: ...
def to_string(self) -> str: ...
@classmethod
def fromstring(cls, sam: str, header: AlignmentHeader) -> AlignedSegment: ...
def to_dict(self) -> Dict: ...
@classmethod
def from_dict(cls, sam_dict: Dict[str, Any], header: AlignmentHeader) -> Any: ...
def get_reference_positions(self, full_length: bool = ...) -> List[int]: ...
@property
def query_length(self) -> int: ...
@property
def reference_end(self) -> Optional[int]: ...
@property
def reference_length(self) -> Optional[int]: ...
@property
def query_alignment_sequence(self) -> Optional[str]: ...
@property
def query_alignment_qualities(self) -> Optional[array]: ...
@property
def query_alignment_start(self) -> int: ...
@property
def query_alignment_end(self) -> int: ...
@property
def query_alignment_length(self) -> int: ...
def infer_query_length(self) -> Optional[int]: ...
def infer_read_length(self) -> Optional[int]: ...
def get_reference_sequence(self) -> str: ...
def get_forward_sequence(self) -> Optional[str]: ...
def get_forward_qualities(self) -> Optional[array]: ...
def get_aligned_pairs(
self, matches_only: bool = ..., with_seq: bool = ...
) -> List[Tuple[int, int]]: ...
def get_blocks(self) -> List[Tuple[int, int]]: ...
def get_overlap(self, start: int, end: int) -> Optional[int]: ...
def get_cigar_stats(self) -> Tuple[array, array]: ...
def set_tag(
self,
tag: str,
value: Union[int, float, str, bytes, array, List, Tuple, None],
value_type: Optional[
Literal["A", "i", "f", "Z", "H", "B", "c", "C", "s", "S", "I"]
] = ...,
replace: bool = ...,
) -> None: ...
def has_tag(self, tag: str) -> bool: ...
@overload
def get_tag(self, tag: str, with_value_type: Literal[False]) -> TagValue: ...
@overload
def get_tag(self, tag, with_value_type: Literal[True]) -> Tuple[TagValue, str]: ...
@overload
def get_tag(
self, tag, with_value_type: bool = ...
) -> Union[TagValue, Tuple[TagValue, str]]: ...
@overload
def get_tags(
self, with_value_type: Literal[False]
) -> List[Tuple[str, TagValue]]: ...
@overload
def get_tags(
self, with_value_type: Literal[True]
) -> List[Tuple[str, TagValue, str]]: ...
@overload
def get_tags(
self, with_value_type: bool = ...
) -> Union[List[Tuple[str, TagValue, str]], List[Tuple[str, TagValue]]]: ...
def set_tags(self, tags: Any) -> None: ...
def __eq__(self, other): ...
def __ge__(self, other): ...
def __gt__(self, other): ...
def __le__(self, other): ...
def __lt__(self, other): ...
def __ne__(self, other): ...

class PileupRead:
@property
def alignment(self) -> AlignedSegment: ...
@property
def query_position(self) -> Optional[int]: ...
@property
def query_position_or_next(self) -> int: ...
@property
def indel(self) -> int: ...
@property
def level(self) -> int: ...
@property
def is_del(self) -> int: ...
@property
def is_head(self) -> int: ...
@property
def is_tail(self) -> int: ...
@property
def is_refskip(self) -> int: ...

class PileupColumn:
nsegments: int
def set_min_base_quality(self, min_base_quality: int) -> None: ...
def __len__(self) -> int: ...
@property
def reference_id(self) -> int: ...
@property
def reference_name(self) -> Optional[str]: ...
@property
def reference_pos(self) -> int: ...
@property
def pileups(self) -> List[PileupRead]: ...
def get_num_aligned(self) -> int: ...
def get_query_sequences(
self,
mark_matches: bool = ...,
mark_ends: bool = ...,
add_indels: bool = ...,
) -> List[str]: ...
def get_query_qualities(self) -> List[int]: ...
def get_mapping_qualities(self) -> List[int]: ...
def get_query_positions(self) -> List[int]: ...
def get_query_names(self) -> List[str]: ...
Loading

0 comments on commit 2a5e55e

Please sign in to comment.