@@ -124,47 +124,52 @@ def get_by_fasta(self, fasta_sequence: str, threshold: float) -> Optional[Dict]:
124124 logger .error ("Empty FASTA sequence provided." )
125125 return None
126126
127- accession = None
128127 if self .use_local_blast :
129128 accession = self ._local_blast (seq , threshold )
130129 if accession :
131130 logger .debug ("Local BLAST found accession: %s" , accession )
131+ return self .get_by_accession (accession )
132+ logger .info (
133+ "Local BLAST found no match for sequence. "
134+ "API fallback disabled when using local database."
135+ )
136+ return None
132137
133- if not accession :
134- logger .debug ("Falling back to NCBIWWW.qblast." )
138+ # Fall back to network BLAST only if local BLAST is not enabled
139+ logger .debug ("Falling back to NCBIWWW.qblast." )
135140
136- # UniProtKB/Swiss-Prot BLAST API
137- try :
138- logger .debug (
139- "Performing BLAST searcher for the given sequence: %s" , seq
140- )
141- result_handle = NCBIWWW .qblast (
142- program = "blastp" ,
143- database = "swissprot" ,
144- sequence = seq ,
145- hitlist_size = 1 ,
146- expect = threshold ,
147- )
148- blast_record = NCBIXML .read (result_handle )
149- except RequestException :
150- raise
151- except Exception as e : # pylint: disable=broad-except
152- logger .error ("BLAST searcher failed: %s" , e )
153- return None
141+ # UniProtKB/Swiss-Prot BLAST API
142+ try :
143+ logger .debug (
144+ "Performing BLAST searcher for the given sequence: %s" , seq
145+ )
146+ result_handle = NCBIWWW .qblast (
147+ program = "blastp" ,
148+ database = "swissprot" ,
149+ sequence = seq ,
150+ hitlist_size = 1 ,
151+ expect = threshold ,
152+ )
153+ blast_record = NCBIXML .read (result_handle )
154+ except RequestException :
155+ raise
156+ except Exception as e : # pylint: disable=broad-except
157+ logger .error ("BLAST searcher failed: %s" , e )
158+ return None
154159
155- if not blast_record .alignments :
156- logger .info ("No BLAST hits found for the given sequence." )
157- return None
160+ if not blast_record .alignments :
161+ logger .info ("No BLAST hits found for the given sequence." )
162+ return None
158163
159- best_alignment = blast_record .alignments [0 ]
160- best_hsp = best_alignment .hsps [0 ]
161- if best_hsp .expect > threshold :
162- logger .info ("No BLAST hits below the threshold E-value." )
163- return None
164- hit_id = best_alignment .hit_id
164+ best_alignment = blast_record .alignments [0 ]
165+ best_hsp = best_alignment .hsps [0 ]
166+ if best_hsp .expect > threshold :
167+ logger .info ("No BLAST hits below the threshold E-value." )
168+ return None
165169
166- # like sp|P01308.1|INS_HUMAN
167- accession = hit_id .split ("|" )[1 ].split ("." )[0 ] if "|" in hit_id else hit_id
170+ # like sp|P01308.1|INS_HUMAN
171+ hit_id = best_alignment .hit_id
172+ accession = hit_id .split ("|" )[1 ].split ("." )[0 ] if "|" in hit_id else hit_id
168173 return self .get_by_accession (accession )
169174
170175 def _local_blast (self , seq : str , threshold : float ) -> Optional [str ]:
0 commit comments