You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

370 rivejä
12 KiB

  1. import sys
  2. from typing import (
  3. Optional,
  4. Union,
  5. Any,
  6. Sequence,
  7. Tuple,
  8. Iterator,
  9. List,
  10. Iterable,
  11. Dict,
  12. overload,
  13. TypeVar,
  14. Mapping,
  15. Generic,
  16. )
  17. if sys.version_info < (3, 8):
  18. from typing_extensions import Literal
  19. else:
  20. from typing import Literal
  21. from pysam.libchtslib import HTSFile, _HasFileNo
  22. _D = TypeVar("_D")
  23. _K = TypeVar("_K", str, Union[int, str])
  24. _V = TypeVar("_V")
  25. class _Mapping(Generic[_K, _V]):
  26. def __len__(self) -> int: ...
  27. def __contains__(self, key: _K) -> bool: ...
  28. def __iter__(self) -> Iterator[_K]: ...
  29. def iterkeys(self) -> Iterator[_K]: ...
  30. def itervalues(self) -> Iterator[_V]: ...
  31. def iteritems(self) -> Iterator[Tuple[_K, _V]]: ...
  32. def keys(self) -> List[_K]: ...
  33. def items(self) -> List[Tuple[_K, _V]]: ...
  34. def values(self) -> List[_V]: ...
  35. def __bool__(self) -> bool: ...
  36. def __getitem__(self, key: _K) -> _V: ...
  37. def get(self, key: _K, default: _D = ...) -> Union[_D, _V]: ...
  38. class VariantHeaderRecord(_Mapping[str, str]):
  39. @property
  40. def header(self) -> VariantHeader: ...
  41. @property
  42. def type(self) -> Optional[str]: ...
  43. @property
  44. def key(self) -> Optional[str]: ...
  45. @property
  46. def value(self) -> Optional[str]: ...
  47. @property
  48. def attrs(self) -> Sequence[Tuple[str, str]]: ...
  49. def update(self, items: Union[Iterable, Dict] = ..., **kwargs) -> None: ...
  50. def pop(self, key: str, default: str = ...) -> str: ...
  51. def remove(self) -> None: ... # crashes
  52. class VariantHeaderRecords:
  53. @property
  54. def header(self) -> VariantHeader: ...
  55. def __len__(self) -> int: ...
  56. def __bool__(self) -> bool: ...
  57. def __getitem__(self, index) -> VariantHeaderRecord: ...
  58. def __iter__(self) -> Iterator[VariantHeaderRecord]: ...
  59. class VariantMetadata:
  60. @property
  61. def header(self) -> VariantHeader: ...
  62. @property
  63. def name(self) -> str: ...
  64. # @property # should this be exposed?
  65. # def id(self) -> int: ...
  66. @property
  67. def number(self) -> Optional[str]: ...
  68. @property
  69. def type(self) -> Optional[str]: ...
  70. @property
  71. def description(self) -> Optional[str]: ...
  72. @property
  73. def record(self) -> Optional[VariantHeaderRecord]: ...
  74. def remove_header(self) -> None: ...
  75. class VariantHeaderMetadata(_Mapping[str, VariantMetadata]):
  76. @property
  77. def header(self) -> VariantHeader: ...
  78. def add(
  79. self,
  80. id: str,
  81. number: Optional[Union[int, str]],
  82. type: Optional[str],
  83. description: str,
  84. **kwargs
  85. ) -> None: ...
  86. def remove_header(self, key: str) -> None: ...
  87. def clear_header(self) -> None: ...
  88. class VariantContig:
  89. @property
  90. def header(self) -> VariantHeader: ...
  91. @property
  92. def name(self) -> str: ...
  93. @property
  94. def id(self) -> int: ...
  95. @property
  96. def length(self) -> Optional[int]: ...
  97. @property
  98. def header_record(self) -> VariantHeaderRecord: ...
  99. def remove_header(self) -> None: ...
  100. class VariantHeaderContigs(_Mapping[Union[int, str], VariantContig]):
  101. @property
  102. def header(self) -> VariantHeader: ...
  103. def remove_header(self, key: Union[int, str]) -> None: ...
  104. def clear_header(self) -> None: ...
  105. def add(self, id: str, length: Optional[int] = ..., **kwargs) -> None: ...
  106. class VariantHeaderSamples:
  107. @property
  108. def header(self) -> VariantHeader: ...
  109. def __len__(self) -> int: ...
  110. def __bool__(self) -> bool: ...
  111. def __getitem__(self, index: int) -> str: ...
  112. def __iter__(self) -> Iterator[str]: ...
  113. def __contains__(self, key: str) -> bool: ...
  114. def add(self, name: str) -> None: ...
  115. class VariantHeader:
  116. def __init__(self) -> None: ...
  117. def __bool__(self) -> bool: ...
  118. def copy(self) -> VariantHeader: ...
  119. def merge(self, header: VariantHeader) -> None: ...
  120. @property
  121. def version(self) -> str: ...
  122. @property
  123. def samples(self) -> VariantHeaderSamples: ...
  124. @property
  125. def records(self) -> VariantHeaderRecords: ...
  126. @property
  127. def contigs(self) -> VariantHeaderContigs: ...
  128. @property
  129. def filters(self) -> VariantHeaderMetadata: ...
  130. @property
  131. def info(self) -> VariantHeaderMetadata: ...
  132. @property
  133. def formats(self) -> VariantHeaderMetadata: ...
  134. @property
  135. def alts(self) -> Dict[str, VariantHeaderRecord]: ...
  136. def new_record(
  137. self,
  138. contig: Optional[str] = ...,
  139. start: int = ...,
  140. stop: int = ...,
  141. alleles: Optional[Tuple[str, ...]] = ...,
  142. id: Optional[str] = ...,
  143. qual: Optional[float] = ...,
  144. filter: Optional[Any] = ...,
  145. info: Optional[Mapping[str, _InfoValue]] = ...,
  146. samples: Optional[Iterable[Optional[Mapping[str, _FormatValue]]]] = ...,
  147. **kwargs
  148. ) -> VariantRecord: ...
  149. def add_record(self, record: VariantHeaderRecord) -> None: ...
  150. def add_line(self, line: str) -> None: ...
  151. @overload
  152. def add_meta(
  153. self, key: str, value: None = ..., items: Iterable[Tuple[str, str]] = ...
  154. ) -> None: ...
  155. @overload
  156. def add_meta(self, key: str, value: str = ..., items: None = ...) -> None: ...
  157. def add_sample(self, name: str) -> None: ...
  158. def add_samples(self, *args: Union[str, Iterable[str]]) -> None: ...
  159. class VariantRecordFilter(_Mapping[Union[int, str], VariantMetadata]):
  160. def add(self, key: str) -> None: ...
  161. def __delitem__(self, key: Union[int, str]) -> None: ...
  162. def clear(self) -> None: ...
  163. def __eq__(self, other) -> bool: ...
  164. def __ne__(self, other) -> bool: ...
  165. class VariantRecordFormat(_Mapping[str, VariantMetadata]):
  166. def __delitem__(self, key: str) -> None: ...
  167. def clear(self) -> None: ...
  168. _InfoValue = Any # TODO see bcf_info_get_value
  169. class VariantRecordInfo(_Mapping[str, _InfoValue]):
  170. def __setitem__(self, key: str, object: _InfoValue) -> None: ...
  171. def __delitem__(self, key: str) -> None: ...
  172. def clear(self) -> None: ...
  173. def update(
  174. self, items: Optional[_Mapping[str, _InfoValue]] = ..., **kwargs
  175. ) -> None: ...
  176. def pop(self, key: str, default: _D = ...) -> Union[_D, _InfoValue]: ...
  177. def __eq__(self, other) -> bool: ...
  178. def __ne__(self, other) -> bool: ...
  179. class VariantRecordSamples(_Mapping[Union[str, int], "VariantRecordSample"]):
  180. def __eq__(self, other) -> bool: ...
  181. def __ne__(self, other) -> bool: ...
  182. # TODO Do these work? Isn’t the container read only?
  183. def update(
  184. self,
  185. items: Optional[Mapping[Union[str, int], VariantRecordSample]] = ...,
  186. **kwargs
  187. ) -> None: ...
  188. def pop(
  189. self, key: Union[str, int], default: _D = ...
  190. ) -> Union[_D, VariantRecordSample]: ...
  191. class VariantRecord:
  192. @property
  193. def header(self) -> VariantHeader: ...
  194. def copy(self) -> VariantRecord: ...
  195. def translate(self, dst_header: VariantHeader) -> None: ...
  196. rid: int
  197. chrom: str
  198. contig: str
  199. pos: int
  200. start: int
  201. stop: int
  202. rlen: int
  203. qual: Optional[float]
  204. id: Optional[str]
  205. ref: Optional[str]
  206. alleles: Optional[Tuple[str, ...]]
  207. alts: Optional[Tuple[str, ...]]
  208. @property
  209. def filter(self) -> VariantRecordFilter: ...
  210. @property
  211. def info(self) -> VariantRecordInfo: ...
  212. @property
  213. def format(self) -> VariantRecordFormat: ...
  214. @property
  215. def samples(self) -> VariantRecordSamples: ...
  216. def __eq__(self, other) -> bool: ...
  217. def __ne__(self, other) -> bool: ...
  218. _FormatValue = Any # TODO see bcf_format_get_value
  219. class VariantRecordSample(_Mapping[str, _FormatValue]):
  220. @property
  221. def index(self) -> int: ...
  222. @property
  223. def name(self) -> str: ...
  224. allele_indices: Optional[Tuple[Optional[int], ...]]
  225. alleles: Optional[Tuple[Optional[str], ...]]
  226. phased: bool
  227. def __setitem__(self, key: str, value: _FormatValue) -> None: ...
  228. def __delitem__(self, key: str) -> None: ...
  229. def clear(self) -> None: ...
  230. def update(
  231. self, items: Optional[Mapping[str, _FormatValue]] = ..., **kwargs
  232. ) -> None: ...
  233. def pop(self, key: str, default: _D = ...) -> Union[_D, _FormatValue]: ...
  234. def __eq__(self, other) -> Any: ...
  235. def __ne__(self, other) -> Any: ...
  236. class BaseIndex(_Mapping[Union[int, str], str]):
  237. refs: Sequence[str]
  238. refmap: Dict[str, str]
  239. def __init__(self) -> None: ...
  240. # TODO Do these work? Isn’t the container read only?
  241. def update(self, items: Optional[Mapping[str, str]] = ..., **kwargs) -> None: ...
  242. def pop(self, key: str, default: _D = ...) -> Union[_D, str]: ...
  243. class BCFIndex(BaseIndex):
  244. @property
  245. def header(self) -> VariantHeader: ...
  246. def __init__(self) -> None: ...
  247. def fetch(
  248. self,
  249. bcf: VariantFile,
  250. contig: str,
  251. start: Optional[int],
  252. stop: Optional[int],
  253. reopen: bool,
  254. ) -> BCFIterator: ...
  255. class TabixIndex(BaseIndex):
  256. def __init__(self) -> None: ...
  257. def fetch(
  258. self,
  259. bcf: VariantFile,
  260. contig: str,
  261. start: Optional[int],
  262. stop: Optional[int],
  263. reopen: bool,
  264. ) -> TabixIterator: ...
  265. class BaseIterator:
  266. def __init__(self) -> None: ...
  267. class BCFIterator(BaseIterator):
  268. def __init__(
  269. self,
  270. bcf: VariantFile,
  271. contig: str,
  272. start: Optional[int] = ...,
  273. stop: Optional[int] = ...,
  274. reopen: bool = ...,
  275. ) -> None: ...
  276. def __iter__(self) -> BCFIterator: ...
  277. def __next__(self) -> VariantRecord: ...
  278. class TabixIterator(BaseIterator):
  279. def __init__(
  280. self,
  281. bcf: VariantFile,
  282. contig: str,
  283. start: Optional[int] = ...,
  284. stop: Optional[int] = ...,
  285. reopen: bool = ...,
  286. ) -> None: ...
  287. def __iter__(self) -> TabixIterator: ...
  288. def __next__(self) -> VariantRecord: ...
  289. class VariantFile(HTSFile):
  290. @property
  291. def header(self) -> VariantHeader: ...
  292. @property
  293. def index(self) -> BaseIndex: ...
  294. @property
  295. def drop_samples(self) -> bool: ...
  296. @property
  297. def is_reading(self) -> bool: ...
  298. @property
  299. def header_written(self) -> bool: ...
  300. def __init__(
  301. self,
  302. filename: Union[str, bytes, int, _HasFileNo],
  303. mode: Optional[Literal["r", "w", "wh", "rb", "wb", "wbu", "wb0"]] = ...,
  304. index_filename: Optional[str] = ...,
  305. header: Optional[VariantHeader] = ...,
  306. drop_samples: bool = ...,
  307. duplicate_filehandle: bool = ...,
  308. ignore_truncation: bool = ...,
  309. threads: int = ...,
  310. ) -> None: ...
  311. def close(self) -> None: ...
  312. def __iter__(self) -> VariantFile: ...
  313. def __next__(self) -> VariantRecord: ...
  314. def copy(self) -> VariantFile: ...
  315. def open(
  316. self,
  317. filename: Union[str, bytes, int, _HasFileNo],
  318. mode: Optional[Literal["r", "w", "wh", "rb", "wb", "wbu", "wb0"]] = ...,
  319. index_filename: Optional[str] = ...,
  320. header: Optional[VariantHeader] = ...,
  321. drop_samples: bool = ...,
  322. duplicate_filehandle: bool = ...,
  323. ignore_truncation: bool = ...,
  324. threads: int = ...,
  325. ) -> None: ...
  326. def reset(self) -> None: ...
  327. def is_valid_tid(self, tid: int) -> bool: ...
  328. def get_tid(self, reference: str) -> int: ...
  329. def get_reference_name(self, tid: int) -> str: ...
  330. def fetch(
  331. self,
  332. contig: Optional[str] = ...,
  333. start: Optional[int] = ...,
  334. stop: Optional[int] = ...,
  335. region: Optional[str] = ...,
  336. reopen: bool = ...,
  337. end: Optional[int] = ...,
  338. reference: Optional[str] = ...,
  339. ) -> Iterator[VariantRecord]: ...
  340. def new_record(self, *args, **kwargs) -> Any: ...
  341. def write(self, record: VariantRecord) -> int: ...
  342. def subset_samples(self, include_samples: Iterable[str]) -> None: ...