1+ # ruff: noqa: C901
2+ # TODO: Remove this noqa line and refactor/reduce code-complexity
3+
14import logging
25import os
36import re
47from datetime import datetime
58from enum import Enum
6- from pathlib import Path
79from typing import Any , Dict , Final , List , Literal , Optional , Tuple
810
911import Bio .SeqIO
1012import numpy as np
11- import typer
1213
1314from .models import (
1415 Alleles ,
@@ -342,7 +343,7 @@ def combine_stds(
342343 seq : List [int ],
343344 max_mismatch_threshold : Optional [int ],
344345 ) -> Dict [int , List [HLACombinedStandardResult ]]:
345- length = len (matching_stds [0 ].sequence )
346+ # length = len(matching_stds[0].sequence)
346347
347348 default_min = 9999
348349 if max_mismatch_threshold is None :
@@ -376,9 +377,9 @@ def combine_stds(
376377 computed_minimum_mismatches = max (
377378 mismatches , tmp_max_mismatch_threshold
378379 )
379- if not mismatches in combos :
380+ if mismatches not in combos :
380381 combos [mismatches ] = {}
381- if not combined_std_name in combos [mismatches ]:
382+ if combined_std_name not in combos [mismatches ]:
382383 combos [mismatches ][combined_std_name ] = []
383384 stds = [std_a .allele , std_b .allele ]
384385 stds .sort ()
@@ -423,11 +424,11 @@ def load_hla_frequencies(self, letter: HLA_TYPES) -> Dict[str, int]:
423424 with open (filepath , "r" , encoding = "utf-8" ) as f :
424425 for line in f .readlines ():
425426 column_id = EasyHLA .COLUMN_IDS [letter ]
426- l = line .strip ().split ("," )[column_id : column_id + 2 ]
427- _l = "," .join ([f"{ a [:2 ]} |{ a [- 2 :]} " for a in l ])
428- if hla_freqs .get (_l , None ) is None :
429- hla_freqs [_l ] = 0
430- hla_freqs [_l ] += 1
427+ line_array = line .strip ().split ("," )[column_id : column_id + 2 ]
428+ elements = "," .join ([f"{ a [:2 ]} |{ a [- 2 :]} " for a in line_array ])
429+ if hla_freqs .get (elements , None ) is None :
430+ hla_freqs [elements ] = 0
431+ hla_freqs [elements ] += 1
431432 return hla_freqs
432433
433434 # TODO: Convert this to a dictionary instead of a object that looks like:
@@ -449,9 +450,9 @@ def load_hla_stds(self, letter: HLA_TYPES) -> List[HLAStandard]:
449450
450451 with open (filepath , "r" , encoding = "utf-8" ) as f :
451452 for line in f .readlines ():
452- l = line .strip ().split ("," )
453- seq = self .nuc2bin ((l [1 ] + l [2 ]))
454- hla_stds .append (HLAStandard (allele = l [0 ], sequence = seq ))
453+ line_array = line .strip ().split ("," )
454+ seq = self .nuc2bin ((line_array [1 ] + line_array [2 ]))
455+ hla_stds .append (HLAStandard (allele = line_array [0 ], sequence = seq ))
455456 return hla_stds
456457
457458 def load_allele_definitions_last_modified_time (self ) -> datetime :
@@ -497,7 +498,7 @@ def interpret(
497498 return None
498499 if not self .check_bases (str (entry .seq ), samp ):
499500 return None
500- except ValueError as e :
501+ except ValueError :
501502 return None
502503
503504 is_exon = False
@@ -691,7 +692,7 @@ def run(
691692 f"{ npats } patients, { nseqs } sequences processed." , to_stdout = to_stdout
692693 )
693694
694- self .log .info (f "% patients, % sequences processed." , npats , nseqs )
695+ self .log .info ("% patients, % sequences processed." , npats , nseqs )
695696
696697 with open (output_filename , "w" , encoding = "utf-8" ) as f :
697698 f .write (
@@ -814,9 +815,9 @@ def get_mismatches(
814815 _seq = np .array ([int (nuc ) for nuc in hla_csr .standard .split ("-" )])
815816 # TODO: replace with https://stackoverflow.com/questions/16094563/numpy-get-index-where-value-is-true
816817 for idx in np .flatnonzero (_seq ^ seq ):
817- if not idx in correct_bases_at_pos :
818+ if idx not in correct_bases_at_pos :
818819 correct_bases_at_pos [idx ] = []
819- if not _seq [idx ] in correct_bases_at_pos [idx ]:
820+ if _seq [idx ] not in correct_bases_at_pos [idx ]:
820821 correct_bases_at_pos [idx ].append (_seq [idx ])
821822
822823 mislist : List [str ] = []
0 commit comments