1212
1313from Bio import Entrez
1414
15- from microSALT .config import Folders , Threshold , PubMLSTCredentials , PasteurCredentials , Singularity , Containers
15+ from microSALT .config import (
16+ Folders ,
17+ Threshold ,
18+ PubMLSTCredentials ,
19+ PasteurCredentials ,
20+ Singularity ,
21+ Containers ,
22+ )
1623from microSALT .store .db_manipulator import DB_Manipulator
1724from microSALT .utils .pubmlst .client import BaseClient , get_client
1825from microSALT .utils .pubmlst .exceptions import InvalidURLError , PubMLSTError
1926from microSALT .utils .pubmlst .helpers import get_service_by_url
2027
2128
2229class Referencer :
23- def __init__ (self , log , folders : Folders , threshold : Threshold , pubmlst : PubMLSTCredentials , pasteur : PasteurCredentials , singularity : Singularity = None , containers : Containers = None , sampleinfo = {}, force = False ):
30+ def __init__ (
31+ self ,
32+ log ,
33+ folders : Folders ,
34+ threshold : Threshold ,
35+ pubmlst : PubMLSTCredentials ,
36+ pasteur : PasteurCredentials ,
37+ singularity : Singularity = None ,
38+ containers : Containers = None ,
39+ sampleinfo = {},
40+ force = False ,
41+ ):
2442 self .folders = folders
2543 self .threshold = threshold
2644 self .pubmlst = pubmlst
@@ -55,7 +73,9 @@ def __init__(self, log, folders: Folders, threshold: Threshold, pubmlst: PubMLST
5573
5674 def set_client (self , service : str , database : str = None ):
5775 """Set the client for PubMLST API interactions."""
58- self .client : BaseClient = get_client (service , database , self .folders , self .pubmlst , self .pasteur )
76+ self .client : BaseClient = get_client (
77+ service , database , self .folders , self .pubmlst , self .pasteur
78+ )
5979
6080 def _singularity_exec (self , tool : str , command : str ) -> str :
6181 """Return command wrapped with singularity exec for the given tool container."""
@@ -81,8 +101,7 @@ def identify_new(self, cg_id="", project=False):
81101 if ref not in self .organisms and org not in neworgs :
82102 neworgs .append (org )
83103 if (
84- f"{ entry .get ('reference' )} .fasta"
85- not in os .listdir (self .folders .genomes )
104+ f"{ entry .get ('reference' )} .fasta" not in os .listdir (self .folders .genomes )
86105 and entry .get ("reference" ) not in newrefs
87106 ):
88107 newrefs .append (entry .get ("reference" ))
@@ -133,20 +152,20 @@ def index_db(self, full_dir, suffix):
133152 try :
134153 # Resistence files
135154 if ".fsa" in suffix :
136- bash_cmd = self ._singularity_exec ('blast' ,
137- f"makeblastdb -in { full_dir } /{ os .path .basename (file )} -dbtype nucl -out { os .path .basename (base )} "
155+ bash_cmd = self ._singularity_exec (
156+ "blast" ,
157+ f"makeblastdb -in { full_dir } /{ os .path .basename (file )} -dbtype nucl -out { os .path .basename (base )} " ,
138158 )
139159 # MLST locis
140160 else :
141- bash_cmd = self ._singularity_exec ('blast' ,
142- f"makeblastdb -in { full_dir } /{ os .path .basename (file )} -dbtype nucl -parse_seqids -out { os .path .basename (base )} "
161+ bash_cmd = self ._singularity_exec (
162+ "blast" ,
163+ f"makeblastdb -in { full_dir } /{ os .path .basename (file )} -dbtype nucl -parse_seqids -out { os .path .basename (base )} " ,
143164 )
144165 proc = subprocess .Popen (bash_cmd .split (), cwd = full_dir , stdout = subprocess .PIPE )
145166 proc .communicate ()
146167 except Exception :
147- self .logger .error (
148- f"Unable to index requested target { file } in { full_dir } "
149- )
168+ self .logger .error (f"Unable to index requested target { file } in { full_dir } " )
150169 if reindexation :
151170 self .logger .info (f"Re-indexed contents of { full_dir } " )
152171
@@ -268,11 +287,7 @@ def _update_external_organism(self, update_info: dict) -> None:
268287 # Step 4: Create new indexes
269288 self .index_db (output , ".tfa" )
270289
271- self .db_access .upd_rec (
272- {"name" : f"profile_{ organ } " },
273- "Versions" ,
274- {"version" : last_updated },
275- )
290+ self .db_access .update_version (name = f"profile_{ organ } " , version = last_updated )
276291 self .db_access .reload_profiletable (organ )
277292
278293 def fetch_external (self ) -> None :
@@ -425,15 +440,15 @@ def download_ncbi(self, reference):
425440 output = f"{ self .folders .genomes } /{ reference } .fasta"
426441 with open (output , "w" ) as f :
427442 f .write (sequence )
428- bwaindex = self ._singularity_exec (' bwa' , f"bwa index { output } " )
443+ bwaindex = self ._singularity_exec (" bwa" , f"bwa index { output } " )
429444 proc = subprocess .Popen (
430445 bwaindex .split (),
431446 cwd = self .folders .genomes ,
432447 stdout = DEVNULL ,
433448 stderr = DEVNULL ,
434449 )
435450 out , err = proc .communicate ()
436- samindex = self ._singularity_exec (' samtools' , f"samtools faidx { output } " )
451+ samindex = self ._singularity_exec (" samtools" , f"samtools faidx { output } " )
437452 proc = subprocess .Popen (
438453 samindex .split (),
439454 cwd = self .folders .genomes ,
@@ -481,9 +496,7 @@ def add_pubmlst(self, organism: str):
481496 )
482497 elif counter < 1.0 :
483498 # add external
484- raise Exception (
485- f"Unable to find requested organism '{ errorg } ' in pubMLST database"
486- )
499+ raise Exception (f"Unable to find requested organism '{ errorg } ' in pubMLST database" )
487500 else :
488501 truename = desc .lower ().split (" " )
489502 truename = f"{ truename [0 ]} _{ truename [1 ]} "
@@ -657,9 +670,5 @@ def fetch_pubmlst(self, force=False):
657670 f"pubMLST reference for { key .replace ('_' , ' ' ).capitalize ()} updated to { external_ver } from { internal_ver } "
658671 )
659672 self .download_pubmlst (key , val , force )
660- self .db_access .upd_rec (
661- {"name" : f"profile_{ key } " },
662- "Versions" ,
663- {"version" : external_ver },
664- )
673+ self .db_access .update_version (name = f"profile_{ key } " , version = external_ver )
665674 self .db_access .refresh_profiletable (key )
0 commit comments