Skip to content

Commit 3c01404

Browse files
committed
swap referencer with db manipulator for checking ref_lock
1 parent 7797393 commit 3c01404

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

microSALT/cli.py

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
By: Isak Sylvin, @sylvinite"""
33

44
#!/usr/bin/env python
5-
65
import json
76
import logging
87
import os
@@ -21,8 +20,9 @@
2120
get_scoped_session_registry,
2221
initialize_database,
2322
)
23+
from microSALT.store.db_manipulator import DB_Manipulator
2424
from microSALT.utils.job_creator import Job_Creator
25-
from microSALT.utils.pubmlst.get_credentials import main as get_bigsdb_credentials_main
25+
from microSALT.utils.pubmlst.get_credentials import get_bigsdb_access_token
2626
from microSALT.utils.referencer import Referencer
2727
from microSALT.utils.reporter import Reporter
2828
from microSALT.utils.scraper import Scraper
@@ -298,9 +298,7 @@ def refer(ctx):
298298
)
299299
@click.option("--output", help="Report output folder", default="")
300300
@pass_config
301-
def finish(
302-
config: MicroSALTConfig, sampleinfo_file, input, track, dry, email, skip_update, report, output
303-
):
301+
def finish(config: MicroSALTConfig, sampleinfo_file, input, track, dry, email, report, output):
304302
"""Sequence analysis, typing and resistance identification"""
305303
pool = []
306304
if email:
@@ -316,31 +314,12 @@ def finish(
316314
pool.append(subfolder)
317315

318316
sampleinfo = review_sampleinfo(sampleinfo_file)
319-
ext_refs = Referencer(
320-
log=logger,
321-
folders=config.folders,
322-
threshold=config.threshold,
323-
pubmlst=config.pubmlst,
324-
pasteur=config.pasteur,
325-
singularity=config.singularity,
326-
containers=config.containers,
327-
sampleinfo=sampleinfo,
328-
)
317+
db_manipulator = DB_Manipulator(log=logger, folders=config.folders, threshold=config.threshold)
329318
try:
330-
ext_refs.db_access.check_ref_lock()
319+
db_manipulator.check_ref_lock()
331320
except RefUpdateLockError as e:
332-
click.echo("ERROR - {}".format(e))
321+
click.echo(f"ERROR - {e}")
333322
click.Abort()
334-
click.echo("INFO - Checking versions of references..")
335-
try:
336-
if not skip_update:
337-
ext_refs.identify_new(project=True)
338-
ext_refs.update_refs()
339-
click.echo("INFO - Version check done. Creating sbatch jobs")
340-
else:
341-
click.echo("INFO - Skipping version check.")
342-
except Exception as e:
343-
click.echo(f"{e}")
344323

345324
res_scraper = Scraper(
346325
log=logger,
@@ -463,7 +442,7 @@ def report(config: MicroSALTConfig, sampleinfo_file, email, type, output, collec
463442
@pass_config
464443
def get_bigsdb_credentials(config: MicroSALTConfig, service, species):
465444
"""Obtain and store BIGSdb OAuth credentials for SERVICE (pubmlst or pasteur)"""
466-
get_bigsdb_credentials_main(service, config, species)
445+
get_bigsdb_access_token(service, config, species)
467446

468447

469448
@utils.command()

microSALT/utils/pubmlst/get_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def save_to_credentials_py(
7777
print(f"Tokens saved to {credentials_file}")
7878

7979

80-
def main(service: str, config: MicroSALTConfig, species: str | None = None):
80+
def get_bigsdb_access_token(service: str, config: MicroSALTConfig, species: str | None = None):
8181
try:
8282
service_config = get_service_config(service, pubmlst=config.pubmlst, pasteur=config.pasteur)
8383
bigsd_config = service_config["config"]

microSALT/utils/referencer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def add_pubmlst(self, organism: str):
464464
"""Checks pubmlst for references of given organism and downloads them"""
465465
# Organism must be in binomial format and only resolve to one hit
466466
errorg = organism
467+
self.db_access.check_ref_lock()
467468
try:
468469
organism = organism.lower().replace(".", " ")
469470
if organism.replace(" ", "_") in self.organisms and not self.force:

microSALT/utils/reporter.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,17 @@
2727

2828

2929
class Reporter:
30-
def __init__(self, log, folders: Folders, threshold: Threshold, regex: Regex, sampleinfo={}, name="", output="", collection=False):
30+
def __init__(
31+
self,
32+
log,
33+
folders: Folders,
34+
threshold: Threshold,
35+
regex: Regex,
36+
sampleinfo={},
37+
name="",
38+
output="",
39+
collection=False,
40+
):
3141
self.folders = folders
3242
self.threshold = threshold
3343
self.regex = regex
@@ -69,6 +79,7 @@ def create_subfolders(self):
6979
os.makedirs(f"{self.folders.reports}/analysis", exist_ok=True)
7080

7181
def report(self, type="default", customer="all"):
82+
self.db_pusher.check_ref_lock()
7283
self.create_subfolders()
7384
if type in ["default", "typing", "qc"]:
7485
# Only typing and qc reports are version controlled
@@ -152,7 +163,12 @@ def gen_typing(self, silent=False):
152163
self.logger.error(f"Project {self.name} does not exist")
153164
sys.exit(-1)
154165
try:
155-
content = typing_page(self.name, "all", threshold=self.threshold, verified_organisms=self.regex.verified_organisms)
166+
content = typing_page(
167+
self.name,
168+
"all",
169+
threshold=self.threshold,
170+
verified_organisms=self.regex.verified_organisms,
171+
)
156172
outfile = f"{self.sample.get('Customer_ID_project')}_Typing_{last_version}.html"
157173
local = f"{self.output}/{outfile}"
158174
output = f"{self.folders.reports}/analysis/{outfile}"

0 commit comments

Comments
 (0)