88import logging
99from enum import IntFlag
1010from collections import defaultdict
11- from typing import Optional , Tuple , Sequence , Dict , Any , List , Union
11+ from typing import Optional , Any , Union
12+ from collections .abc import Sequence
1213from abc import ABC , abstractmethod
1314import time
1415
@@ -80,7 +81,7 @@ def __init__(self, adapter: "SingleAdapter"):
8081 self .adapter_type : str = adapter .descriptive_identifier ()
8182 self .allows_partial_matches : bool = adapter .allows_partial_matches
8283 # self.errors[l][e] == n iff a sequence of length l matching at e errors was removed n times
83- self .errors : Dict [int , Dict [int , int ]] = defaultdict (returns_defaultdict_int )
84+ self .errors : dict [int , dict [int , int ]] = defaultdict (returns_defaultdict_int )
8485 self .adjacent_bases = {"A" : 0 , "C" : 0 , "G" : 0 , "T" : 0 , "" : 0 }
8586 # TODO avoid hard-coding the list of classes
8687 self ._remove_prefix = isinstance (adapter , FrontAdapter )
@@ -111,7 +112,7 @@ def lengths(self):
111112 d = {length : sum (errors .values ()) for length , errors in self .errors .items ()}
112113 return d
113114
114- def random_match_probabilities (self , gc_content : float ) -> List [float ]:
115+ def random_match_probabilities (self , gc_content : float ) -> list [float ]:
115116 """
116117 Estimate probabilities that this adapter end matches a
117118 random sequence. Indels are not taken into account.
@@ -147,7 +148,7 @@ def __iadd__(self, other):
147148 pass
148149
149150 @abstractmethod
150- def end_statistics (self ) -> Tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
151+ def end_statistics (self ) -> tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
151152 pass
152153
153154 @abstractmethod
@@ -181,7 +182,7 @@ class FrontAdapterStatistics(SingleAdapterStatistics):
181182 def add_match (self , match : "RemoveBeforeMatch" ):
182183 self .end .errors [match .removed_sequence_length ()][match .errors ] += 1
183184
184- def end_statistics (self ) -> Tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
185+ def end_statistics (self ) -> tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
185186 return self .end , None
186187
187188
@@ -194,7 +195,7 @@ def add_match(self, match: "RemoveAfterMatch"):
194195 except KeyError :
195196 self .end .adjacent_bases ["" ] += 1
196197
197- def end_statistics (self ) -> Tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
198+ def end_statistics (self ) -> tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
198199 return None , self .end
199200
200201
@@ -242,7 +243,7 @@ def add_match(self, match: "LinkedMatch"):
242243 except KeyError :
243244 self .back .adjacent_bases ["" ] += 1
244245
245- def end_statistics (self ) -> Tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
246+ def end_statistics (self ) -> tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
246247 return self .front , self .back
247248
248249
@@ -281,23 +282,23 @@ def add_match(self, match: Union["RemoveBeforeMatch", "RemoveAfterMatch"]) -> No
281282 except KeyError :
282283 self .back .adjacent_bases ["" ] += 1
283284
284- def end_statistics (self ) -> Tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
285+ def end_statistics (self ) -> tuple [Optional [EndStatistics ], Optional [EndStatistics ]]:
285286 return self .front , self .back
286287
287288
288289class Match (ABC ):
289290 adapter : "Adapter"
290291
291292 @abstractmethod
292- def remainder_interval (self ) -> Tuple [int , int ]:
293+ def remainder_interval (self ) -> tuple [int , int ]:
293294 pass
294295
295296 @abstractmethod
296- def retained_adapter_interval (self ) -> Tuple [int , int ]:
297+ def retained_adapter_interval (self ) -> tuple [int , int ]:
297298 pass
298299
299300 @abstractmethod
300- def get_info_records (self , read ) -> List [ List ]:
301+ def get_info_records (self , read ) -> list [ list ]:
301302 pass
302303
303304 @abstractmethod
@@ -388,7 +389,7 @@ def wildcards(self, wildcard_char: str = "N") -> str:
388389 ]
389390 return "" .join (wildcards )
390391
391- def get_info_records (self , read ) -> List [ List ]:
392+ def get_info_records (self , read ) -> list [ list ]:
392393 seq = read .sequence
393394 qualities = read .qualities
394395 info = [
@@ -432,14 +433,14 @@ def rest(self) -> str:
432433 """
433434 return self .sequence [: self .rstart ]
434435
435- def remainder_interval (self ) -> Tuple [int , int ]:
436+ def remainder_interval (self ) -> tuple [int , int ]:
436437 """
437438 Return an interval (start, stop) that describes the part of the read that would
438439 remain after trimming
439440 """
440441 return self .rstop , len (self .sequence )
441442
442- def retained_adapter_interval (self ) -> Tuple [int , int ]:
443+ def retained_adapter_interval (self ) -> tuple [int , int ]:
443444 return self .rstart , len (self .sequence )
444445
445446 def trim_slice (self ):
@@ -465,14 +466,14 @@ def rest(self) -> str:
465466 """
466467 return self .sequence [self .rstop :]
467468
468- def remainder_interval (self ) -> Tuple [int , int ]:
469+ def remainder_interval (self ) -> tuple [int , int ]:
469470 """
470471 Return an interval (start, stop) that describes the part of the read that would
471472 remain after trimming
472473 """
473474 return 0 , self .rstart
474475
475- def retained_adapter_interval (self ) -> Tuple [int , int ]:
476+ def retained_adapter_interval (self ) -> tuple [int , int ]:
476477 return 0 , self .rstop
477478
478479 def trim_slice (self ):
@@ -710,7 +711,7 @@ def match_to(self, sequence: str):
710711 """
711712 if not self .kmer_finder .kmers_present (sequence ):
712713 return None
713- alignment : Optional [Tuple [int , int , int , int , int , int ]] = self .aligner .locate (
714+ alignment : Optional [tuple [int , int , int , int , int , int ]] = self .aligner .locate (
714715 sequence
715716 )
716717 if self ._debug :
@@ -762,7 +763,7 @@ def match_to(self, sequence: str):
762763 reversed_sequence = sequence [::- 1 ]
763764 if not self .kmer_finder .kmers_present (reversed_sequence ):
764765 return None
765- alignment : Optional [Tuple [int , int , int , int , int , int ]] = self .aligner .locate (
766+ alignment : Optional [tuple [int , int , int , int , int , int ]] = self .aligner .locate (
766767 reversed_sequence
767768 )
768769 if self ._debug :
@@ -818,7 +819,7 @@ def match_to(self, sequence: str):
818819 """
819820 if not self .kmer_finder .kmers_present (sequence ):
820821 return None
821- alignment : Optional [Tuple [int , int , int , int , int , int ]] = self .aligner .locate (
822+ alignment : Optional [tuple [int , int , int , int , int , int ]] = self .aligner .locate (
822823 sequence
823824 )
824825 if self ._debug :
@@ -866,7 +867,7 @@ def match_to(self, sequence: str):
866867 reversed_sequence = sequence [::- 1 ]
867868 if not self .kmer_finder .kmers_present (reversed_sequence ):
868869 return None
869- alignment : Optional [Tuple [int , int , int , int , int , int ]] = self .aligner .locate (
870+ alignment : Optional [tuple [int , int , int , int , int , int ]] = self .aligner .locate (
870871 reversed_sequence
871872 )
872873 if self ._debug :
@@ -1130,13 +1131,13 @@ def trimmed(self, read):
11301131 read = self .back_match .trimmed (read )
11311132 return read
11321133
1133- def remainder_interval (self ) -> Tuple [int , int ]:
1134+ def remainder_interval (self ) -> tuple [int , int ]:
11341135 matches = [
11351136 match for match in [self .front_match , self .back_match ] if match is not None
11361137 ]
11371138 return remainder (matches )
11381139
1139- def retained_adapter_interval (self ) -> Tuple [int , int ]:
1140+ def retained_adapter_interval (self ) -> tuple [int , int ]:
11401141 if self .front_match :
11411142 start = self .front_match .rstart
11421143 offset = self .front_match .rstop
@@ -1148,7 +1149,7 @@ def retained_adapter_interval(self) -> Tuple[int, int]:
11481149 end = len (self .front_match .sequence )
11491150 return start , end
11501151
1151- def get_info_records (self , read ) -> List [ List ]:
1152+ def get_info_records (self , read ) -> list [ list ]:
11521153 records = []
11531154 for match , namesuffix in [
11541155 (self .front_match , ";1" ),
@@ -1295,7 +1296,7 @@ class AdapterIndex:
12951296 Use the is_acceptable() method to check individual adapters.
12961297 """
12971298
1298- AdapterIndexDict = Dict [str , Tuple [SingleAdapter , int , int ]]
1299+ AdapterIndexDict = dict [str , tuple [SingleAdapter , int , int ]]
12991300
13001301 def __init__ (self , adapters , prefix : bool ):
13011302 """All given adapters must be of the same type"""
@@ -1387,7 +1388,7 @@ def is_acceptable(cls, adapter: SingleAdapter, prefix: bool):
13871388 return False
13881389 return True
13891390
1390- def _make_index (self ) -> Tuple [ List [int ], "AdapterIndexDict" , int ]:
1391+ def _make_index (self ) -> tuple [ list [int ], "AdapterIndexDict" , int ]:
13911392 start_time = time .time ()
13921393 max_k = max (
13931394 (
@@ -1404,7 +1405,7 @@ def _make_index(self) -> Tuple[List[int], "AdapterIndexDict", int]:
14041405 "Indexing could take long and use a lot of memory. "
14051406 "If this becomes a problem, try --no-indels and/or --no-index."
14061407 )
1407- index : Dict [str , Tuple [SingleAdapter , int , int ]] = dict ()
1408+ index : dict [str , tuple [SingleAdapter , int , int ]] = dict ()
14081409 lengths = set ()
14091410 ambiguous = {}
14101411 for adapter in self ._adapters :
@@ -1579,7 +1580,7 @@ def warn_duplicate_adapters(adapters):
15791580 d [key ] = adapter .name
15801581
15811582
1582- def remainder (matches : Sequence [Match ]) -> Tuple [int , int ]:
1583+ def remainder (matches : Sequence [Match ]) -> tuple [int , int ]:
15831584 """
15841585 Determine which section of the read would not be trimmed. Return a tuple (start, stop)
15851586 that gives the interval of the untrimmed part relative to the original read.
0 commit comments