mlstdb 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mlstdb might be problematic. Click here for more details.
- mlstdb/.bigsdb_tokens/access_tokens +7 -0
- mlstdb/.bigsdb_tokens/client_credentials +7 -0
- mlstdb/.bigsdb_tokens/session_tokens +7 -0
- mlstdb/__about__.py +4 -0
- mlstdb/__init__.py +3 -0
- mlstdb/__main__.py +8 -0
- mlstdb/cli/__init__.py +19 -0
- mlstdb/cli/fetch.py +156 -0
- mlstdb/cli/update.py +80 -0
- mlstdb/core/__init__.py +1 -0
- mlstdb/core/auth.py +177 -0
- mlstdb/core/config.py +40 -0
- mlstdb/core/download.py +393 -0
- mlstdb/data/__init__.py +0 -0
- mlstdb/data/scheme_uris.tab +145 -0
- mlstdb/utils.py +13 -0
- mlstdb-0.1.0.dist-info/METADATA +164 -0
- mlstdb-0.1.0.dist-info/RECORD +21 -0
- mlstdb-0.1.0.dist-info/WHEEL +4 -0
- mlstdb-0.1.0.dist-info/entry_points.txt +2 -0
- mlstdb-0.1.0.dist-info/licenses/LICENSE.txt +9 -0
mlstdb/__about__.py
ADDED
mlstdb/__init__.py
ADDED
mlstdb/__main__.py
ADDED
mlstdb/cli/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2025-present Himal Shrestha <stha.himal2007@gmail.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
from mlstdb.cli.fetch import fetch
|
|
7
|
+
from mlstdb.cli.update import update
|
|
8
|
+
from mlstdb.__about__ import __version__
|
|
9
|
+
|
|
10
|
+
@click.group()
|
|
11
|
+
@click.version_option(version=__version__)
|
|
12
|
+
|
|
13
|
+
@click.help_option('-h', '--help')
|
|
14
|
+
def mlstdb():
|
|
15
|
+
"""MLST Database Management Tool"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
mlstdb.add_command(fetch)
|
|
19
|
+
mlstdb.add_command(update)
|
mlstdb/cli/fetch.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import importlib.resources
|
|
4
|
+
from tqdm import tqdm
|
|
5
|
+
import configparser
|
|
6
|
+
import sys
|
|
7
|
+
import os
|
|
8
|
+
from mlstdb.core.auth import register_tokens, setup_client_credentials, remove_db_credentials
|
|
9
|
+
from mlstdb.core.download import (fetch_resources, get_matching_schemes,
|
|
10
|
+
sanitise_output, clear_file,
|
|
11
|
+
load_processed_databases,save_processed_database, load_scheme_uris)
|
|
12
|
+
from mlstdb.core.config import get_config_dir, BASE_API
|
|
13
|
+
from mlstdb.utils import error, success, info
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@click.command()
|
|
17
|
+
@click.help_option('-h', '--help')
|
|
18
|
+
@click.option('--db', '-d', type=click.Choice(['pubmlst', 'pasteur']),
|
|
19
|
+
help='Database to use (pubmlst or pasteur)')
|
|
20
|
+
@click.option('--exclude', '-e', default='cgMLST',
|
|
21
|
+
help='Scheme name must not include provided term (default: cgMLST)')
|
|
22
|
+
@click.option('--match', '-m', default='MLST',
|
|
23
|
+
help='Scheme name must include provided term (default: MLST)')
|
|
24
|
+
@click.option('--scheme-uris', '-s',
|
|
25
|
+
help='Optional: Path to custom scheme_uris.tab file')
|
|
26
|
+
@click.option('--filter', '-f',
|
|
27
|
+
help='Filter species or schemes using a wildcard pattern')
|
|
28
|
+
@click.option('--resume', '-r', is_flag=True,
|
|
29
|
+
help='Resume processing from where it stopped')
|
|
30
|
+
@click.option('--verbose', '-v', is_flag=True,
|
|
31
|
+
help='Enable verbose logging for debugging')
|
|
32
|
+
def fetch(db, exclude, match, scheme_uris, filter, resume, verbose):
|
|
33
|
+
"""BIGSdb Scheme Fetcher Tool
|
|
34
|
+
|
|
35
|
+
This tool downloads MLST scheme information from BIGSdb databases.
|
|
36
|
+
It will automatically handle authentication and save the results.
|
|
37
|
+
"""
|
|
38
|
+
# try:
|
|
39
|
+
# # If scheme_uris is not provided, use the package data
|
|
40
|
+
# if scheme_uris is None:
|
|
41
|
+
# with importlib.resources.path('mlstdb.data', 'scheme_uris.tab') as default_path:
|
|
42
|
+
# scheme_uris = str(default_path)
|
|
43
|
+
|
|
44
|
+
# try:
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
# If scheme_uris is not provided, use the package data
|
|
48
|
+
if scheme_uris is None:
|
|
49
|
+
with importlib.resources.path('mlstdb.data', 'scheme_uris.tab') as default_path:
|
|
50
|
+
scheme_uris = str(default_path)
|
|
51
|
+
|
|
52
|
+
# If db is not provided, prompt for it
|
|
53
|
+
if not db:
|
|
54
|
+
db = click.prompt(
|
|
55
|
+
"Which database would you like to use?",
|
|
56
|
+
type=click.Choice(['pubmlst', 'pasteur']),
|
|
57
|
+
default='pubmlst'
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Get client credentials
|
|
61
|
+
config_dir = get_config_dir()
|
|
62
|
+
client_creds_file = config_dir / "client_credentials"
|
|
63
|
+
session_tokens_file = config_dir / "session_tokens"
|
|
64
|
+
|
|
65
|
+
# Check if credentials exist, if not setup
|
|
66
|
+
if not client_creds_file.exists() or not session_tokens_file.exists():
|
|
67
|
+
register_tokens(db)
|
|
68
|
+
|
|
69
|
+
# Get credentials
|
|
70
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
71
|
+
|
|
72
|
+
# Read client credentials
|
|
73
|
+
config.read(client_creds_file)
|
|
74
|
+
if not config.has_section(db):
|
|
75
|
+
error(f"No client credentials found for {db}")
|
|
76
|
+
register_tokens(db)
|
|
77
|
+
config.read(client_creds_file)
|
|
78
|
+
|
|
79
|
+
client_key = config[db]["client_id"]
|
|
80
|
+
client_secret = config[db]["client_secret"]
|
|
81
|
+
|
|
82
|
+
# Read session tokens
|
|
83
|
+
config.read(session_tokens_file)
|
|
84
|
+
if not config.has_section(db):
|
|
85
|
+
error(f"No session token found for {db}")
|
|
86
|
+
register_tokens(db)
|
|
87
|
+
config.read(session_tokens_file)
|
|
88
|
+
|
|
89
|
+
session_token = config[db]["token"]
|
|
90
|
+
session_secret = config[db]["secret"]
|
|
91
|
+
|
|
92
|
+
output_file = f"mlst_schemes_{db}.txt"
|
|
93
|
+
processed_file = f"processed_dbs_{db}.txt"
|
|
94
|
+
|
|
95
|
+
if not resume:
|
|
96
|
+
clear_file(output_file)
|
|
97
|
+
clear_file(processed_file)
|
|
98
|
+
|
|
99
|
+
processed_dbs = load_processed_databases(processed_file)
|
|
100
|
+
|
|
101
|
+
base_uri = BASE_API[db]
|
|
102
|
+
resources = fetch_resources(base_uri, client_key, client_secret,
|
|
103
|
+
session_token, session_secret, verbose)
|
|
104
|
+
|
|
105
|
+
if not resources:
|
|
106
|
+
error("No resources found")
|
|
107
|
+
sys.exit(1)
|
|
108
|
+
|
|
109
|
+
success_count = 0
|
|
110
|
+
total_dbs = sum(1 for r in resources if 'databases' in r
|
|
111
|
+
for _ in r['databases'])
|
|
112
|
+
|
|
113
|
+
for resource in tqdm(resources, desc="Processing resources"):
|
|
114
|
+
if 'databases' in resource:
|
|
115
|
+
for database in resource['databases']:
|
|
116
|
+
if database['description'] in processed_dbs:
|
|
117
|
+
if verbose:
|
|
118
|
+
info(f"Skipping already processed database: {database['description']}")
|
|
119
|
+
success_count += 1
|
|
120
|
+
continue
|
|
121
|
+
|
|
122
|
+
try:
|
|
123
|
+
get_matching_schemes(database, match, exclude,
|
|
124
|
+
client_key, client_secret,
|
|
125
|
+
session_token, session_secret,
|
|
126
|
+
output_file, processed_file, verbose)
|
|
127
|
+
success_count += 1
|
|
128
|
+
except Exception as e:
|
|
129
|
+
error(f"Error processing {database['description']}: {e}")
|
|
130
|
+
continue
|
|
131
|
+
|
|
132
|
+
# Delete processed_file if all databases were processed successfully
|
|
133
|
+
if success_count == total_dbs:
|
|
134
|
+
try:
|
|
135
|
+
os.remove(processed_file)
|
|
136
|
+
if verbose:
|
|
137
|
+
info(f"Removed progress tracking file: {processed_file}")
|
|
138
|
+
except OSError as e:
|
|
139
|
+
error(f"Error removing progress file: {e}")
|
|
140
|
+
|
|
141
|
+
# After successful fetch, perform sanitisation
|
|
142
|
+
if Path(scheme_uris).exists():
|
|
143
|
+
sanitise_output(output_file, scheme_uris, filter, verbose)
|
|
144
|
+
else:
|
|
145
|
+
error(f"Scheme URIs file not found: {scheme_uris}")
|
|
146
|
+
error("Skipping sanitisation step")
|
|
147
|
+
|
|
148
|
+
success("Fetch completed successfully!")
|
|
149
|
+
|
|
150
|
+
except Exception as e:
|
|
151
|
+
error(f"An error occurred: {e}")
|
|
152
|
+
info("Progress file kept for resume capability")
|
|
153
|
+
if verbose:
|
|
154
|
+
import traceback
|
|
155
|
+
error(traceback.format_exc())
|
|
156
|
+
sys.exit(1)
|
mlstdb/cli/update.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from mlstdb.core.auth import get_client_credentials, retrieve_session_token
|
|
4
|
+
from mlstdb.core.download import get_mlst_files, create_blast_db
|
|
5
|
+
from mlstdb.core.config import check_dir
|
|
6
|
+
from mlstdb.utils import error, success, info
|
|
7
|
+
from tqdm import tqdm
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
@click.command()
|
|
11
|
+
@click.help_option('-h', '--help')
|
|
12
|
+
@click.option('--input', '-i', required=True,
|
|
13
|
+
help='Path to mlst_schemes_<db>.txt containing MLST scheme URLs')
|
|
14
|
+
@click.option('--directory', '-d', default='pubmlst',
|
|
15
|
+
help='Directory to save the downloaded MLST schemes (default: pubmlst)')
|
|
16
|
+
@click.option('--blast-directory', '-b',
|
|
17
|
+
help='Directory for BLAST database (default: relative to directory as ../blast)')
|
|
18
|
+
@click.option('--verbose', '-v', is_flag=True,
|
|
19
|
+
help='Enable verbose logging for debugging')
|
|
20
|
+
def update(input: str, directory: str, blast_directory: str, verbose: bool):
|
|
21
|
+
"""
|
|
22
|
+
Update MLST schemes and create BLAST database.
|
|
23
|
+
|
|
24
|
+
Downloads MLST schemes from the specified input file and creates a BLAST database
|
|
25
|
+
from the downloaded sequences. Authentication tokens should be set up using fetch.py.
|
|
26
|
+
"""
|
|
27
|
+
try:
|
|
28
|
+
# Read the input file
|
|
29
|
+
with open(input, 'r') as f:
|
|
30
|
+
# Skip header
|
|
31
|
+
header = next(f)
|
|
32
|
+
lines = f.readlines()
|
|
33
|
+
|
|
34
|
+
check_dir(directory)
|
|
35
|
+
|
|
36
|
+
# Process each scheme
|
|
37
|
+
for line in tqdm(lines, desc="Downloading MLST schemes", unit="scheme"):
|
|
38
|
+
parts = line.strip().split('\t')
|
|
39
|
+
if len(parts) != 5:
|
|
40
|
+
error(f"Skipping invalid line: {line}")
|
|
41
|
+
continue
|
|
42
|
+
|
|
43
|
+
database, species, scheme_desc, scheme, url = parts
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
# Get credentials for the specific database
|
|
47
|
+
client_key, client_secret = get_client_credentials(database.lower())
|
|
48
|
+
session_token, session_secret = retrieve_session_token(database.lower())
|
|
49
|
+
|
|
50
|
+
if not session_token or not session_secret:
|
|
51
|
+
error(f"No valid session token found for {database}. Please run fetch.py first to set up authentication.")
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
# scheme_dir = Path(directory) / sanitise_name(scheme)
|
|
55
|
+
scheme_dir = Path(directory) / scheme
|
|
56
|
+
check_dir(str(scheme_dir))
|
|
57
|
+
|
|
58
|
+
get_mlst_files(url, str(scheme_dir), client_key, client_secret,
|
|
59
|
+
session_token, session_secret, scheme,
|
|
60
|
+
verbose=verbose)
|
|
61
|
+
success(f"Successfully downloaded scheme: {scheme}")
|
|
62
|
+
|
|
63
|
+
except Exception as e:
|
|
64
|
+
error(f"Error downloading scheme {scheme}: {e}")
|
|
65
|
+
if verbose:
|
|
66
|
+
import traceback
|
|
67
|
+
error(traceback.format_exc())
|
|
68
|
+
continue
|
|
69
|
+
|
|
70
|
+
# Create BLAST database after all schemes are downloaded
|
|
71
|
+
info("\nCreating BLAST database from downloaded MLST schemes...")
|
|
72
|
+
create_blast_db(directory, blast_directory, verbose)
|
|
73
|
+
success("Update completed successfully!")
|
|
74
|
+
|
|
75
|
+
except Exception as e:
|
|
76
|
+
error(f"An error occurred: {e}")
|
|
77
|
+
if verbose:
|
|
78
|
+
import traceback
|
|
79
|
+
error(traceback.format_exc())
|
|
80
|
+
sys.exit(1)
|
mlstdb/core/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Core functionality for MLST database management."""
|
mlstdb/core/auth.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import configparser
|
|
2
|
+
import click
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Tuple
|
|
6
|
+
from rauth import OAuth1Service, OAuth1Session
|
|
7
|
+
from mlstdb.core.config import get_config_dir, BASE_API, BASE_WEB, DB_MAPPING
|
|
8
|
+
from mlstdb.utils import error, success, info
|
|
9
|
+
|
|
10
|
+
def setup_client_credentials(site: str) -> Tuple[str, str]:
|
|
11
|
+
"""Setup and save client credentials."""
|
|
12
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
13
|
+
file_path = get_config_dir() / "client_credentials"
|
|
14
|
+
|
|
15
|
+
if file_path.exists():
|
|
16
|
+
config.read(file_path)
|
|
17
|
+
|
|
18
|
+
info("\nPlease enter your client credentials:")
|
|
19
|
+
client_id = click.prompt("Client ID", type=str).strip()
|
|
20
|
+
while len(client_id) != 24:
|
|
21
|
+
error("Client IDs must be exactly 24 characters long")
|
|
22
|
+
client_id = click.prompt("Client ID", type=str).strip()
|
|
23
|
+
|
|
24
|
+
client_secret = click.prompt("Client Secret", type=str).strip()
|
|
25
|
+
while len(client_secret) != 42:
|
|
26
|
+
error("Client secrets must be exactly 42 characters long")
|
|
27
|
+
client_secret = click.prompt("Client Secret", type=str).strip()
|
|
28
|
+
|
|
29
|
+
config[site] = {"client_id": client_id, "client_secret": client_secret}
|
|
30
|
+
|
|
31
|
+
with open(file_path, "w") as configfile:
|
|
32
|
+
config.write(configfile)
|
|
33
|
+
success(f"\nClient credentials saved to {file_path}")
|
|
34
|
+
return client_id, client_secret
|
|
35
|
+
|
|
36
|
+
def register_tokens(db: str):
|
|
37
|
+
"""Setup authentication tokens by registering with the service."""
|
|
38
|
+
info(f"\nNo tokens found for {db}. Starting registration process...")
|
|
39
|
+
|
|
40
|
+
# Setup client credentials
|
|
41
|
+
client_id, client_secret = setup_client_credentials(db)
|
|
42
|
+
|
|
43
|
+
# Initialize OAuth service
|
|
44
|
+
service = OAuth1Service(
|
|
45
|
+
name="BIGSdb_downloader",
|
|
46
|
+
consumer_key=client_id,
|
|
47
|
+
consumer_secret=client_secret,
|
|
48
|
+
request_token_url=f"{BASE_API[db]}/db/{DB_MAPPING[db]}/oauth/get_request_token",
|
|
49
|
+
access_token_url=f"{BASE_API[db]}/db/{DB_MAPPING[db]}/oauth/get_access_token",
|
|
50
|
+
base_url=BASE_API[db],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Get request token
|
|
54
|
+
info("\nRequesting temporary token...")
|
|
55
|
+
r = service.get_raw_request_token(
|
|
56
|
+
params={"oauth_callback": "oob"},
|
|
57
|
+
headers={"User-Agent": "BIGSdb downloader"}
|
|
58
|
+
)
|
|
59
|
+
if r.status_code != 200:
|
|
60
|
+
error(f"Failed to get request token: {r.json()['message']}")
|
|
61
|
+
sys.exit(1)
|
|
62
|
+
|
|
63
|
+
request_token = r.json()["oauth_token"]
|
|
64
|
+
request_secret = r.json()["oauth_token_secret"]
|
|
65
|
+
success("Temporary token received")
|
|
66
|
+
|
|
67
|
+
# Get access token
|
|
68
|
+
click.secho("\nAuthorization Required", fg="yellow", bold=True)
|
|
69
|
+
info(
|
|
70
|
+
"\nPlease open this URL in your browser:\n"
|
|
71
|
+
f"{BASE_WEB[db]}?db={DB_MAPPING[db]}&page=authorizeClient&oauth_token={request_token}"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
verifier = click.prompt("\nEnter the verification code from the website", type=str)
|
|
75
|
+
|
|
76
|
+
info("\nRequesting access token...")
|
|
77
|
+
r = service.get_raw_access_token(
|
|
78
|
+
request_token,
|
|
79
|
+
request_secret,
|
|
80
|
+
params={"oauth_verifier": verifier},
|
|
81
|
+
headers={"User-Agent": "BIGSdb downloader"},
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if r.status_code != 200:
|
|
85
|
+
error(f"Failed to get access token: {r.json()['message']}")
|
|
86
|
+
sys.exit(1)
|
|
87
|
+
|
|
88
|
+
access_token = r.json()["oauth_token"]
|
|
89
|
+
access_secret = r.json()["oauth_token_secret"]
|
|
90
|
+
|
|
91
|
+
# Save access token
|
|
92
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
93
|
+
file_path = get_config_dir() / "access_tokens"
|
|
94
|
+
if file_path.exists():
|
|
95
|
+
config.read(file_path)
|
|
96
|
+
config[db] = {"token": access_token, "secret": access_secret}
|
|
97
|
+
with open(file_path, "w") as configfile:
|
|
98
|
+
config.write(configfile)
|
|
99
|
+
success(f"\nAccess token saved to {file_path}")
|
|
100
|
+
|
|
101
|
+
# Get session token
|
|
102
|
+
info("\nRequesting session token...")
|
|
103
|
+
url = f"{BASE_API[db]}/db/{DB_MAPPING[db]}/oauth/get_session_token"
|
|
104
|
+
|
|
105
|
+
session = OAuth1Session(
|
|
106
|
+
service.consumer_key,
|
|
107
|
+
service.consumer_secret,
|
|
108
|
+
access_token=access_token,
|
|
109
|
+
access_token_secret=access_secret
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
r = session.get(url, headers={"User-Agent": "BIGSdb downloader"})
|
|
113
|
+
|
|
114
|
+
if r.status_code != 200:
|
|
115
|
+
error(f"Failed to get session token: {r.json()['message']}")
|
|
116
|
+
sys.exit(1)
|
|
117
|
+
|
|
118
|
+
token = r.json()["oauth_token"]
|
|
119
|
+
secret = r.json()["oauth_token_secret"]
|
|
120
|
+
|
|
121
|
+
# Save session token
|
|
122
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
123
|
+
file_path = get_config_dir() / "session_tokens"
|
|
124
|
+
if file_path.exists():
|
|
125
|
+
config.read(file_path)
|
|
126
|
+
config[db] = {"token": token, "secret": secret}
|
|
127
|
+
with open(file_path, "w") as configfile:
|
|
128
|
+
config.write(configfile)
|
|
129
|
+
|
|
130
|
+
success(f"\nSession token saved to {file_path}")
|
|
131
|
+
return token, secret
|
|
132
|
+
|
|
133
|
+
def get_config_dir() -> Path:
|
|
134
|
+
"""Create and return the configuration directory."""
|
|
135
|
+
config_dir = Path.home() / ".config" / "mlstdb"
|
|
136
|
+
if not config_dir.exists():
|
|
137
|
+
config_dir.mkdir(parents=True, mode=0o700)
|
|
138
|
+
return config_dir
|
|
139
|
+
|
|
140
|
+
def get_client_credentials(key_name: str) -> Tuple[str, str]:
|
|
141
|
+
"""Get OAuth client credentials from config file."""
|
|
142
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
143
|
+
file_path = get_config_dir() / "client_credentials"
|
|
144
|
+
|
|
145
|
+
if file_path.is_file():
|
|
146
|
+
config.read(file_path)
|
|
147
|
+
if config.has_section(key_name):
|
|
148
|
+
return (config[key_name]["client_id"],
|
|
149
|
+
config[key_name]["client_secret"])
|
|
150
|
+
|
|
151
|
+
raise ValueError(f"Client credentials not found for {key_name}")
|
|
152
|
+
|
|
153
|
+
def remove_db_credentials(config_dir: Path, db: str) -> None:
|
|
154
|
+
"""Remove credentials for specific database while preserving others."""
|
|
155
|
+
for file_name in ["client_credentials", "session_tokens", "access_tokens"]:
|
|
156
|
+
file_path = config_dir / file_name
|
|
157
|
+
if file_path.exists():
|
|
158
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
159
|
+
config.read(file_path)
|
|
160
|
+
if db in config:
|
|
161
|
+
config.remove_section(db)
|
|
162
|
+
with open(file_path, 'w') as f:
|
|
163
|
+
config.write(f)
|
|
164
|
+
success(f"Removed {db} credentials from {file_name}")
|
|
165
|
+
|
|
166
|
+
def retrieve_session_token(key_name: str) -> Tuple[str, str]:
|
|
167
|
+
"""Get OAuth session token from config file."""
|
|
168
|
+
config = configparser.ConfigParser(interpolation=None)
|
|
169
|
+
file_path = get_config_dir() / "session_tokens"
|
|
170
|
+
|
|
171
|
+
if file_path.is_file():
|
|
172
|
+
config.read(file_path)
|
|
173
|
+
if config.has_section(key_name):
|
|
174
|
+
return (config[key_name]["token"],
|
|
175
|
+
config[key_name]["secret"])
|
|
176
|
+
|
|
177
|
+
return None, None
|
mlstdb/core/config.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import os
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
# # Constants
|
|
6
|
+
# BASE_WEB: Dict[str, str] = {
|
|
7
|
+
# "pubmlst": "https://pubmlst.org/bigsdb",
|
|
8
|
+
# "pasteur": "https://bigsdb.pasteur.fr/cgi-bin/bigsdb/bigsdb.pl",
|
|
9
|
+
# }
|
|
10
|
+
|
|
11
|
+
# Constants
|
|
12
|
+
BASE_WEB = {
|
|
13
|
+
"pubmlst": "https://pubmlst.org/bigsdb",
|
|
14
|
+
"pasteur": "https://bigsdb.pasteur.fr/cgi-bin/bigsdb/bigsdb.pl",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BASE_API = {
|
|
18
|
+
"pubmlst": "https://rest.pubmlst.org",
|
|
19
|
+
"pasteur": "https://bigsdb.pasteur.fr/api",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
DB_MAPPING = {
|
|
23
|
+
"pubmlst": "pubmlst_neisseria_seqdef",
|
|
24
|
+
"pasteur": "pubmlst_diphtheria_isolates"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def get_config_dir() -> Path:
|
|
28
|
+
"""Create and return the configuration directory."""
|
|
29
|
+
config_dir = Path.home() / ".config" / "mlstdb"
|
|
30
|
+
if not config_dir.exists():
|
|
31
|
+
config_dir.mkdir(parents=True, mode=0o700)
|
|
32
|
+
return config_dir
|
|
33
|
+
|
|
34
|
+
def check_dir(directory: str) -> None:
|
|
35
|
+
"""Ensure the directory exists and is writable."""
|
|
36
|
+
path = Path(directory)
|
|
37
|
+
if not path.exists():
|
|
38
|
+
path.mkdir(parents=True)
|
|
39
|
+
if not (path.is_dir() and os.access(directory, os.W_OK)):
|
|
40
|
+
raise PermissionError(f"Cannot write to directory: {directory}")
|
mlstdb/core/download.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import sys
|
|
4
|
+
import click
|
|
5
|
+
import requests
|
|
6
|
+
import subprocess
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Dict, Optional, List
|
|
9
|
+
from tqdm import tqdm
|
|
10
|
+
from rauth import OAuth1Session
|
|
11
|
+
from mlstdb.core.config import get_config_dir, BASE_API
|
|
12
|
+
from mlstdb.core.auth import remove_db_credentials
|
|
13
|
+
from mlstdb.utils import error, success, info
|
|
14
|
+
|
|
15
|
+
def fetch_json(url, client_key, client_secret, session_token, session_secret, verbose=False):
|
|
16
|
+
if verbose:
|
|
17
|
+
print(f"Fetching JSON from {url}")
|
|
18
|
+
|
|
19
|
+
session = OAuth1Session(
|
|
20
|
+
consumer_key=client_key,
|
|
21
|
+
consumer_secret=client_secret,
|
|
22
|
+
access_token=session_token,
|
|
23
|
+
access_token_secret=session_secret,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
session.headers.update({"User-Agent": "BIGSdb downloader"})
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
response = session.get(url)
|
|
30
|
+
if verbose:
|
|
31
|
+
print(f"Response code: {response.status_code}, URL: {url}")
|
|
32
|
+
if response.status_code == 404:
|
|
33
|
+
print(f"Resource not found at URL: {url}")
|
|
34
|
+
return None
|
|
35
|
+
response.raise_for_status()
|
|
36
|
+
return response.json()
|
|
37
|
+
except requests.exceptions.HTTPError as e:
|
|
38
|
+
if e.response.status_code in [401, 403]: # Handle both 401 and 403
|
|
39
|
+
config_dir = get_config_dir()
|
|
40
|
+
|
|
41
|
+
error(f"\nAuthentication Failed! (Status code: {e.response.status_code})")
|
|
42
|
+
if e.response.status_code == 401:
|
|
43
|
+
info("This usually means your tokens have expired. Please check your credentials.")
|
|
44
|
+
else:
|
|
45
|
+
info("This usually means you lack permissions for this resource. Please check your credentials.")
|
|
46
|
+
|
|
47
|
+
# Show credential locations
|
|
48
|
+
info("\nYour credentials are stored in:")
|
|
49
|
+
for cred_file in ["client_credentials", "session_tokens", "access_tokens"]:
|
|
50
|
+
info(f"- {config_dir}/{cred_file}")
|
|
51
|
+
|
|
52
|
+
# Inform user about next steps
|
|
53
|
+
info("\nTo fix authentication issues:")
|
|
54
|
+
info("1. You need to manually delete your credentials from the files above")
|
|
55
|
+
info("2. Run the script again to generate new credentials")
|
|
56
|
+
|
|
57
|
+
# Offer to delete credentials
|
|
58
|
+
if click.confirm("\nWould you like to delete credentials for this database?", default=False):
|
|
59
|
+
try:
|
|
60
|
+
# Use the db parameter from the main function
|
|
61
|
+
if url.startswith(BASE_API['pubmlst']):
|
|
62
|
+
db = 'pubmlst'
|
|
63
|
+
elif url.startswith(BASE_API['pasteur']):
|
|
64
|
+
db = 'pasteur'
|
|
65
|
+
remove_db_credentials(config_dir, db)
|
|
66
|
+
info("\nCredentials deleted successfully.")
|
|
67
|
+
info("Please run the script again to generate new credentials.")
|
|
68
|
+
sys.exit(1)
|
|
69
|
+
except Exception as del_error:
|
|
70
|
+
error(f"Failed to delete credentials: {del_error}")
|
|
71
|
+
sys.exit(1)
|
|
72
|
+
|
|
73
|
+
error("Exiting. Please fix credentials and try again")
|
|
74
|
+
sys.exit(1)
|
|
75
|
+
raise
|
|
76
|
+
|
|
77
|
+
def get_mlst_files(url: str, directory: str, client_key: str, client_secret: str,
|
|
78
|
+
session_token: str, session_secret: str, scheme_name: str,
|
|
79
|
+
verbose: bool = False) -> None:
|
|
80
|
+
"""Download MLST data and save them in the given directory."""
|
|
81
|
+
session = OAuth1Session(
|
|
82
|
+
consumer_key=client_key,
|
|
83
|
+
consumer_secret=client_secret,
|
|
84
|
+
access_token=session_token,
|
|
85
|
+
access_token_secret=session_secret,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
session.headers.update({"User-Agent": "BIGSdb downloader"})
|
|
89
|
+
|
|
90
|
+
if verbose:
|
|
91
|
+
info(f"Fetching MLST scheme from {url}...")
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
response = session.get(url)
|
|
95
|
+
response.raise_for_status()
|
|
96
|
+
mlst_scheme = response.json()
|
|
97
|
+
|
|
98
|
+
if verbose:
|
|
99
|
+
info(f"Retrieved MLST scheme: {mlst_scheme}")
|
|
100
|
+
|
|
101
|
+
# Modified version handling for null values
|
|
102
|
+
db_version = mlst_scheme.get('last_added', 'Not found')
|
|
103
|
+
if db_version is None:
|
|
104
|
+
db_version = 'No version information available'
|
|
105
|
+
info(f"Database version: {db_version}")
|
|
106
|
+
|
|
107
|
+
# Save database version to a file
|
|
108
|
+
db_version_path = os.path.join(directory, 'database_version.txt')
|
|
109
|
+
with open(db_version_path, 'w') as version_file:
|
|
110
|
+
version_file.write(db_version)
|
|
111
|
+
|
|
112
|
+
# Download loci with progress bar
|
|
113
|
+
for loci in tqdm(mlst_scheme['loci'], desc="Downloading loci", unit="locus"):
|
|
114
|
+
name = loci.split('/')[-1]
|
|
115
|
+
loci_fasta = session.get(loci + '/alleles_fasta')
|
|
116
|
+
loci_fasta.raise_for_status()
|
|
117
|
+
loci_file_name = os.path.join(directory, name + '.tfa')
|
|
118
|
+
with open(loci_file_name, 'wb') as f:
|
|
119
|
+
f.write(loci_fasta.content)
|
|
120
|
+
|
|
121
|
+
# Download profiles CSV
|
|
122
|
+
profiles_url = url + '/profiles_csv'
|
|
123
|
+
profiles = session.get(profiles_url)
|
|
124
|
+
profiles.raise_for_status()
|
|
125
|
+
profiles_file_path = os.path.join(directory, f"{scheme_name}.txt")
|
|
126
|
+
with open(profiles_file_path, 'w') as f:
|
|
127
|
+
f.write(profiles.text)
|
|
128
|
+
|
|
129
|
+
except requests.exceptions.HTTPError as e:
|
|
130
|
+
if e.response.status_code in [401, 403]:
|
|
131
|
+
error("\nAuthentication failed!")
|
|
132
|
+
info("\nTo fix authentication issues:")
|
|
133
|
+
info("1. Run 'fetch.py' to refresh your credentials")
|
|
134
|
+
info("2. Try running this script again")
|
|
135
|
+
sys.exit(1)
|
|
136
|
+
elif e.response.status_code == 404:
|
|
137
|
+
error(f"Resource not found at URL: {url}")
|
|
138
|
+
raise
|
|
139
|
+
|
|
140
|
+
def fetch_resources(base_uri, client_key, client_secret, session_token, session_secret, verbose=False):
|
|
141
|
+
if verbose:
|
|
142
|
+
print(f"Fetching resources from {base_uri}")
|
|
143
|
+
return fetch_json(base_uri, client_key, client_secret, session_token, session_secret, verbose)
|
|
144
|
+
|
|
145
|
+
def clear_file(file_path):
|
|
146
|
+
"""Clear the contents of a file or create it if it doesn't exist."""
|
|
147
|
+
with open(file_path, 'w') as f:
|
|
148
|
+
# Add headers only for mlst_schemes files
|
|
149
|
+
if file_path.startswith('mlst_schemes_'):
|
|
150
|
+
f.write("database\tspecies\tscheme_description\tURI\n")
|
|
151
|
+
|
|
152
|
+
def load_processed_databases(file_path):
|
|
153
|
+
if not os.path.exists(file_path):
|
|
154
|
+
return set()
|
|
155
|
+
with open(file_path, 'r') as f:
|
|
156
|
+
return set(line.strip() for line in f)
|
|
157
|
+
|
|
158
|
+
def save_processed_database(file_path, db_description):
|
|
159
|
+
with open(file_path, 'a') as f:
|
|
160
|
+
f.write(f"{db_description}\n")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def sanitise_species(species_column: str) -> str:
|
|
164
|
+
"""Clean up species names."""
|
|
165
|
+
return species_column.replace("sequence/profile definitions", "").strip()
|
|
166
|
+
|
|
167
|
+
def extract_scheme_from_url(url: str) -> str:
|
|
168
|
+
"""Extract scheme name from URL pattern."""
|
|
169
|
+
# Handle Pasteur URLs
|
|
170
|
+
if 'pasteur.fr' in url:
|
|
171
|
+
match = re.search(r'pubmlst_([^_]+)_seqdef/schemes/(\d+)', url)
|
|
172
|
+
if match:
|
|
173
|
+
scheme = match.group(1)
|
|
174
|
+
scheme_id = match.group(2)
|
|
175
|
+
return f"{scheme}_{scheme_id}" if scheme_id != "1" else scheme
|
|
176
|
+
|
|
177
|
+
# Handle PubMLST URLs
|
|
178
|
+
else:
|
|
179
|
+
match = re.search(r'pubmlst_([^_]+)_seqdef/schemes/(\d+)', url)
|
|
180
|
+
if match:
|
|
181
|
+
scheme = match.group(1)
|
|
182
|
+
scheme_id = match.group(2)
|
|
183
|
+
return f"{scheme}_{scheme_id}" if scheme_id != "1" else scheme
|
|
184
|
+
|
|
185
|
+
return "missing"
|
|
186
|
+
|
|
187
|
+
def load_scheme_uris(file_path: str) -> dict:
|
|
188
|
+
"""Load scheme URIs from tab-delimited file."""
|
|
189
|
+
schemes = {}
|
|
190
|
+
with open(file_path, 'r') as f:
|
|
191
|
+
next(f) # Skip header
|
|
192
|
+
for line in f:
|
|
193
|
+
scheme, uri = line.strip().split('\t')
|
|
194
|
+
schemes[uri] = scheme
|
|
195
|
+
return schemes
|
|
196
|
+
|
|
197
|
+
def sanitise_output(output_file: str, scheme_uris_file: str, filter_pattern: str, verbose: bool) -> None:
|
|
198
|
+
"""Sanitise the output file using the scheme URIs mapping."""
|
|
199
|
+
if not Path(output_file).exists():
|
|
200
|
+
error(f"Output file not found: {output_file}")
|
|
201
|
+
return
|
|
202
|
+
|
|
203
|
+
scheme_uris = load_scheme_uris(scheme_uris_file)
|
|
204
|
+
sanitised_data = []
|
|
205
|
+
existing_schemes = set()
|
|
206
|
+
|
|
207
|
+
info(f"Sanitising output file: {output_file}")
|
|
208
|
+
|
|
209
|
+
# Read and process the file
|
|
210
|
+
with open(output_file, 'r') as infile:
|
|
211
|
+
header = next(infile) # Skip header
|
|
212
|
+
for line in infile:
|
|
213
|
+
columns = line.strip().split('\t')
|
|
214
|
+
if len(columns) != 4: # Now expecting 4 columns
|
|
215
|
+
error(f"Skipping malformed line: {line}")
|
|
216
|
+
continue
|
|
217
|
+
|
|
218
|
+
database = columns[0] # database type (pubmlst/pasteur)
|
|
219
|
+
species = sanitise_species(columns[1])
|
|
220
|
+
scheme_desc = columns[2]
|
|
221
|
+
uri = columns[3]
|
|
222
|
+
|
|
223
|
+
if filter_pattern and not (
|
|
224
|
+
re.search(filter_pattern, species, re.IGNORECASE) or
|
|
225
|
+
re.search(filter_pattern, uri, re.IGNORECASE)
|
|
226
|
+
):
|
|
227
|
+
if verbose:
|
|
228
|
+
info(f"Skipping entry due to filter mismatch: {line.strip()}")
|
|
229
|
+
continue
|
|
230
|
+
|
|
231
|
+
# First try to get scheme from mapping file
|
|
232
|
+
scheme = scheme_uris.get(uri)
|
|
233
|
+
existing_schemes.add(scheme if scheme else "missing")
|
|
234
|
+
sanitised_data.append((database, species, scheme_desc, scheme, uri))
|
|
235
|
+
|
|
236
|
+
# Handle missing schemes
|
|
237
|
+
if any(entry[3] is None for entry in sanitised_data):
|
|
238
|
+
error("\nThe following URIs have missing schemes:")
|
|
239
|
+
for entry in sanitised_data:
|
|
240
|
+
if entry[3] is None:
|
|
241
|
+
click.echo(entry[4])
|
|
242
|
+
|
|
243
|
+
user_choice = click.prompt(
|
|
244
|
+
"\nDo you want to set missing schemes as 'missing' or auto-generate them?",
|
|
245
|
+
type=click.Choice(['missing', 'auto'], case_sensitive=False)
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
if user_choice == "auto":
|
|
249
|
+
for idx, (database, species, scheme_desc, scheme, uri) in enumerate(sanitised_data):
|
|
250
|
+
if scheme is None:
|
|
251
|
+
auto_scheme = extract_scheme_from_url(uri)
|
|
252
|
+
if verbose:
|
|
253
|
+
info(f"Auto-generated scheme: {auto_scheme} for URI: {uri}")
|
|
254
|
+
sanitised_data[idx] = (database, species, scheme_desc, auto_scheme, uri)
|
|
255
|
+
else: # missing
|
|
256
|
+
sanitised_data = [
|
|
257
|
+
(database, species, scheme_desc, scheme if scheme else "missing", uri)
|
|
258
|
+
for database, species, scheme_desc, scheme, uri in sanitised_data
|
|
259
|
+
]
|
|
260
|
+
|
|
261
|
+
# Write sanitised output back to the same file
|
|
262
|
+
with open(output_file, 'w') as outfile:
|
|
263
|
+
outfile.write("database\tspecies\tscheme_description\tscheme\tURI\n")
|
|
264
|
+
for entry in sanitised_data:
|
|
265
|
+
outfile.write('\t'.join(str(x) for x in entry) + '\n')
|
|
266
|
+
|
|
267
|
+
success(f"Sanitisation complete! Results updated in {output_file}")
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def get_matching_schemes(db, match, exclude, client_key, client_secret,
|
|
271
|
+
session_token, session_secret, output_file, processed_file, verbose=False):
|
|
272
|
+
"""Get matching schemes from the database."""
|
|
273
|
+
# Check if this is a sequence definition database
|
|
274
|
+
is_seqdef = ('seqdef' in db['name'].lower() or
|
|
275
|
+
'definitions' in db.get('description', '').lower())
|
|
276
|
+
|
|
277
|
+
if is_seqdef:
|
|
278
|
+
try:
|
|
279
|
+
db_attributes = fetch_json(db['href'], client_key, client_secret,
|
|
280
|
+
session_token, session_secret, verbose=verbose)
|
|
281
|
+
except requests.exceptions.HTTPError as e:
|
|
282
|
+
if e.response.status_code == 401:
|
|
283
|
+
print(f"The token does not allow access to the `{db['description']}` database. "
|
|
284
|
+
f"So, the `{db['description']}` database will be skipped.\n"
|
|
285
|
+
"To download the data, please ensure your account has access to this database.")
|
|
286
|
+
save_processed_database(processed_file, db['description'])
|
|
287
|
+
return
|
|
288
|
+
elif e.response.status_code == 404:
|
|
289
|
+
print(f"The resource `{db['href']}` for the `{db['description']}` database was not found (404). "
|
|
290
|
+
"Skipping this database.")
|
|
291
|
+
save_processed_database(processed_file, db['description'])
|
|
292
|
+
return
|
|
293
|
+
else:
|
|
294
|
+
raise
|
|
295
|
+
|
|
296
|
+
if not db_attributes or 'schemes' not in db_attributes:
|
|
297
|
+
save_processed_database(processed_file, db['description'])
|
|
298
|
+
return
|
|
299
|
+
|
|
300
|
+
schemes = fetch_json(db_attributes['schemes'], client_key, client_secret,
|
|
301
|
+
session_token, session_secret, verbose=verbose)
|
|
302
|
+
|
|
303
|
+
# Get database type from output filename
|
|
304
|
+
db_type = output_file.split('_')[-1].replace('.txt', '')
|
|
305
|
+
|
|
306
|
+
if schemes and 'schemes' in schemes:
|
|
307
|
+
matching_schemes = []
|
|
308
|
+
for scheme in schemes['schemes']:
|
|
309
|
+
if match and not re.search(match, scheme['description'], flags=0):
|
|
310
|
+
continue
|
|
311
|
+
if exclude and re.search(exclude, scheme['description'], flags=0):
|
|
312
|
+
continue
|
|
313
|
+
# Add database type as first column
|
|
314
|
+
matching_schemes.append(f"{db_type}\t{db['description']}\t{scheme['description']}\t{scheme['scheme']}\n")
|
|
315
|
+
|
|
316
|
+
if matching_schemes: # Only write to file if we found matching schemes
|
|
317
|
+
with open(output_file, 'a') as f:
|
|
318
|
+
f.writelines(matching_schemes)
|
|
319
|
+
|
|
320
|
+
save_processed_database(processed_file, db['description'])
|
|
321
|
+
|
|
322
|
+
def create_blast_db(input_dir: str, blast_directory: str, verbose: bool = False) -> None:
|
|
323
|
+
"""Create BLAST database from MLST schemes."""
|
|
324
|
+
input_path = Path(input_dir)
|
|
325
|
+
if not input_path.is_dir():
|
|
326
|
+
error(f"Input directory {input_dir} does not exist.")
|
|
327
|
+
return
|
|
328
|
+
|
|
329
|
+
# Set default output directory relative to input
|
|
330
|
+
blast_path = Path(blast_directory) if blast_directory else input_path.parent / "blast"
|
|
331
|
+
blast_path.mkdir(parents=True, exist_ok=True)
|
|
332
|
+
|
|
333
|
+
blast_file = blast_path / "mlst.fa"
|
|
334
|
+
if blast_file.exists():
|
|
335
|
+
blast_file.unlink()
|
|
336
|
+
|
|
337
|
+
info(f"Creating BLAST database from {input_dir}")
|
|
338
|
+
info(f"Output directory: {blast_path}")
|
|
339
|
+
|
|
340
|
+
# Get all scheme directories
|
|
341
|
+
scheme_dirs = [d for d in input_path.iterdir() if d.is_dir()]
|
|
342
|
+
total_schemes = len(scheme_dirs)
|
|
343
|
+
|
|
344
|
+
if total_schemes == 0:
|
|
345
|
+
error("No scheme directories found.")
|
|
346
|
+
return
|
|
347
|
+
|
|
348
|
+
with open(blast_file, 'w') as outfile:
|
|
349
|
+
for scheme_dir in tqdm(scheme_dirs, desc="Processing schemes", unit="scheme"):
|
|
350
|
+
scheme_name = scheme_dir.name
|
|
351
|
+
if verbose:
|
|
352
|
+
info(f"\nProcessing scheme: {scheme_name}")
|
|
353
|
+
|
|
354
|
+
# Find all sequence files
|
|
355
|
+
sequence_files = []
|
|
356
|
+
for ext in ['.tfa', '.fasta', '.fa', '.fas']:
|
|
357
|
+
sequence_files.extend(scheme_dir.glob(f"*{ext}"))
|
|
358
|
+
|
|
359
|
+
if not sequence_files:
|
|
360
|
+
if verbose:
|
|
361
|
+
info(f"No sequence files found in {scheme_dir}")
|
|
362
|
+
continue
|
|
363
|
+
|
|
364
|
+
# Process each sequence file
|
|
365
|
+
for seq_file in sequence_files:
|
|
366
|
+
with open(seq_file) as f:
|
|
367
|
+
for line in f:
|
|
368
|
+
if line.startswith('>'):
|
|
369
|
+
# Modify header to include scheme name
|
|
370
|
+
outfile.write(f">{scheme_name}.{line[1:]}")
|
|
371
|
+
else:
|
|
372
|
+
outfile.write(line)
|
|
373
|
+
|
|
374
|
+
if blast_file.stat().st_size == 0:
|
|
375
|
+
error("No sequences found to create BLAST database.")
|
|
376
|
+
return
|
|
377
|
+
|
|
378
|
+
# Create BLAST database
|
|
379
|
+
info("\nCreating BLAST database...")
|
|
380
|
+
try:
|
|
381
|
+
subprocess.run([
|
|
382
|
+
'makeblastdb',
|
|
383
|
+
'-hash_index',
|
|
384
|
+
'-in', str(blast_file),
|
|
385
|
+
'-dbtype', 'nucl',
|
|
386
|
+
'-title', 'MLST',
|
|
387
|
+
'-parse_seqids'
|
|
388
|
+
], check=True, capture_output=True, text=True)
|
|
389
|
+
success(f"BLAST database created successfully: {blast_file}")
|
|
390
|
+
except subprocess.CalledProcessError as e:
|
|
391
|
+
error(f"Failed to create BLAST database: {e.stderr}")
|
|
392
|
+
except FileNotFoundError:
|
|
393
|
+
error("makeblastdb command not found. Please ensure BLAST+ is installed.")
|
mlstdb/data/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
scheme URI
|
|
2
|
+
aactinomycetemcomitans https://rest.pubmlst.org/db/pubmlst_aactinomycetemcomitans_seqdef/schemes/1
|
|
3
|
+
abaumannii https://rest.pubmlst.org/db/pubmlst_abaumannii_seqdef/schemes/1
|
|
4
|
+
abaumannii_2 https://rest.pubmlst.org/db/pubmlst_abaumannii_seqdef/schemes/2
|
|
5
|
+
achromobacter https://rest.pubmlst.org/db/pubmlst_achromobacter_seqdef/schemes/1
|
|
6
|
+
aeromonas https://rest.pubmlst.org/db/pubmlst_aeromonas_seqdef/schemes/1
|
|
7
|
+
aphagocytophilum https://rest.pubmlst.org/db/pubmlst_aphagocytophilum_seqdef/schemes/1
|
|
8
|
+
arcobacter https://rest.pubmlst.org/db/pubmlst_arcobacter_seqdef/schemes/1
|
|
9
|
+
bbacilliformis https://rest.pubmlst.org/db/pubmlst_bbacilliformis_seqdef/schemes/1
|
|
10
|
+
bcc https://rest.pubmlst.org/db/pubmlst_bcc_seqdef/schemes/1
|
|
11
|
+
bcereus https://rest.pubmlst.org/db/pubmlst_bcereus_seqdef/schemes/1
|
|
12
|
+
bfragilis https://rest.pubmlst.org/db/pubmlst_bfragilis_seqdef/schemes/1
|
|
13
|
+
bhenselae https://rest.pubmlst.org/db/pubmlst_bhenselae_seqdef/schemes/1
|
|
14
|
+
blicheniformis_14 https://rest.pubmlst.org/db/pubmlst_blicheniformis_seqdef/schemes/14
|
|
15
|
+
bordetella_3 https://bigsdb.pasteur.fr/api/db/pubmlst_bordetella_seqdef/schemes/3
|
|
16
|
+
borrelia https://rest.pubmlst.org/db/pubmlst_borrelia_seqdef/schemes/1
|
|
17
|
+
bpseudomallei https://rest.pubmlst.org/db/pubmlst_bpseudomallei_seqdef/schemes/1
|
|
18
|
+
brachyspira https://rest.pubmlst.org/db/pubmlst_brachyspira_seqdef/schemes/1
|
|
19
|
+
brachyspira_2 https://rest.pubmlst.org/db/pubmlst_brachyspira_seqdef/schemes/2
|
|
20
|
+
brachyspira_3 https://rest.pubmlst.org/db/pubmlst_brachyspira_seqdef/schemes/3
|
|
21
|
+
brachyspira_4 https://rest.pubmlst.org/db/pubmlst_brachyspira_seqdef/schemes/4
|
|
22
|
+
brachyspira_5 https://rest.pubmlst.org/db/pubmlst_brachyspira_seqdef/schemes/5
|
|
23
|
+
brucella https://rest.pubmlst.org/db/pubmlst_brucella_seqdef/schemes/1
|
|
24
|
+
bsubtilis https://rest.pubmlst.org/db/pubmlst_bsubtilis_seqdef/schemes/1
|
|
25
|
+
bwashoensis https://rest.pubmlst.org/db/pubmlst_bwashoensis_seqdef/schemes/1
|
|
26
|
+
campylobacter https://rest.pubmlst.org/db/pubmlst_campylobacter_seqdef/schemes/1
|
|
27
|
+
campylobacter_nonjejuni https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/1
|
|
28
|
+
campylobacter_nonjejuni_2 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/2
|
|
29
|
+
campylobacter_nonjejuni_3 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/3
|
|
30
|
+
campylobacter_nonjejuni_4 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/4
|
|
31
|
+
campylobacter_nonjejuni_5 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/5
|
|
32
|
+
campylobacter_nonjejuni_6 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/6
|
|
33
|
+
campylobacter_nonjejuni_7 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/7
|
|
34
|
+
campylobacter_nonjejuni_8 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/8
|
|
35
|
+
campylobacter_nonjejuni_9 https://rest.pubmlst.org/db/pubmlst_campylobacter_nonjejuni_seqdef/schemes/9
|
|
36
|
+
cbotulinum https://rest.pubmlst.org/db/pubmlst_cbotulinum_seqdef/schemes/1
|
|
37
|
+
cdifficile https://rest.pubmlst.org/db/pubmlst_cdifficile_seqdef/schemes/1
|
|
38
|
+
cfreundii https://rest.pubmlst.org/db/pubmlst_cfreundii_seqdef/schemes/1
|
|
39
|
+
chlamydiales https://rest.pubmlst.org/db/pubmlst_chlamydiales_seqdef/schemes/1
|
|
40
|
+
cmaltaromaticum https://rest.pubmlst.org/db/pubmlst_cmaltaromaticum_seqdef/schemes/1
|
|
41
|
+
cperfringens https://rest.pubmlst.org/db/pubmlst_cperfringens_seqdef/schemes/1
|
|
42
|
+
cronobacter https://rest.pubmlst.org/db/pubmlst_cronobacter_seqdef/schemes/1
|
|
43
|
+
csepticum https://rest.pubmlst.org/db/pubmlst_csepticum_seqdef/schemes/1
|
|
44
|
+
diphtheria_3 https://bigsdb.pasteur.fr/api/db/pubmlst_diphtheria_seqdef/schemes/3
|
|
45
|
+
dnodosus https://rest.pubmlst.org/db/pubmlst_dnodosus_seqdef/schemes/1
|
|
46
|
+
ecloacae https://rest.pubmlst.org/db/pubmlst_ecloacae_seqdef/schemes/1
|
|
47
|
+
ecoli https://bigsdb.pasteur.fr/api/db/pubmlst_ecoli_seqdef/schemes/1
|
|
48
|
+
ecoli_achtman_4 https://rest.pubmlst.org/db/pubmlst_ecoli_achtman_seqdef/schemes/4
|
|
49
|
+
edwardsiella https://rest.pubmlst.org/db/pubmlst_edwardsiella_seqdef/schemes/1
|
|
50
|
+
efaecalis https://rest.pubmlst.org/db/pubmlst_efaecalis_seqdef/schemes/1
|
|
51
|
+
efaecium https://rest.pubmlst.org/db/pubmlst_efaecium_seqdef/schemes/1
|
|
52
|
+
fpsychrophilum https://rest.pubmlst.org/db/pubmlst_fpsychrophilum_seqdef/schemes/1
|
|
53
|
+
gallibacterium https://rest.pubmlst.org/db/pubmlst_gallibacterium_seqdef/schemes/1
|
|
54
|
+
geotrichum https://rest.pubmlst.org/db/pubmlst_geotrichum_seqdef/schemes/1
|
|
55
|
+
hcinaedi https://rest.pubmlst.org/db/pubmlst_hcinaedi_seqdef/schemes/1
|
|
56
|
+
helicobacter https://rest.pubmlst.org/db/pubmlst_helicobacter_seqdef/schemes/1
|
|
57
|
+
hinfluenzae https://rest.pubmlst.org/db/pubmlst_hinfluenzae_seqdef/schemes/1
|
|
58
|
+
hparasuis https://rest.pubmlst.org/db/pubmlst_hparasuis_seqdef/schemes/1
|
|
59
|
+
hsuis https://rest.pubmlst.org/db/pubmlst_hsuis_seqdef/schemes/1
|
|
60
|
+
kaerogenes https://rest.pubmlst.org/db/pubmlst_kaerogenes_seqdef/schemes/1
|
|
61
|
+
kingella https://bigsdb.pasteur.fr/api/db/pubmlst_kingella_seqdef/schemes/1
|
|
62
|
+
klebsiella https://bigsdb.pasteur.fr/api/db/pubmlst_klebsiella_seqdef/schemes/1
|
|
63
|
+
koxytoca https://rest.pubmlst.org/db/pubmlst_koxytoca_seqdef/schemes/1
|
|
64
|
+
leptospira https://rest.pubmlst.org/db/pubmlst_leptospira_seqdef/schemes/1
|
|
65
|
+
leptospira_2 https://rest.pubmlst.org/db/pubmlst_leptospira_seqdef/schemes/2
|
|
66
|
+
leptospira_3 https://rest.pubmlst.org/db/pubmlst_leptospira_seqdef/schemes/3
|
|
67
|
+
liberibacter https://rest.pubmlst.org/db/pubmlst_liberibacter_seqdef/schemes/1
|
|
68
|
+
listeria_2 https://bigsdb.pasteur.fr/api/db/pubmlst_listeria_seqdef/schemes/2
|
|
69
|
+
llactis_phage https://rest.pubmlst.org/db/pubmlst_llactis_phage_seqdef/schemes/1
|
|
70
|
+
lsalivarius https://rest.pubmlst.org/db/pubmlst_lsalivarius_seqdef/schemes/1
|
|
71
|
+
mabscessus https://rest.pubmlst.org/db/pubmlst_mabscessus_seqdef/schemes/1
|
|
72
|
+
magalactiae https://rest.pubmlst.org/db/pubmlst_magalactiae_seqdef/schemes/1
|
|
73
|
+
manserisalpingitidis https://rest.pubmlst.org/db/pubmlst_manserisalpingitidis_seqdef/schemes/1
|
|
74
|
+
mbovis_2 https://rest.pubmlst.org/db/pubmlst_mbovis_seqdef/schemes/2
|
|
75
|
+
mcanis https://rest.pubmlst.org/db/pubmlst_mcanis_seqdef/schemes/1
|
|
76
|
+
mcaseolyticus https://rest.pubmlst.org/db/pubmlst_mcaseolyticus_seqdef/schemes/1
|
|
77
|
+
mcatarrhalis_achtman_6 https://rest.pubmlst.org/db/pubmlst_mcatarrhalis_achtman_seqdef/schemes/6
|
|
78
|
+
mflocculare https://rest.pubmlst.org/db/pubmlst_mflocculare_seqdef/schemes/1
|
|
79
|
+
mgallisepticum https://rest.pubmlst.org/db/pubmlst_mgallisepticum_seqdef/schemes/1
|
|
80
|
+
mgallisepticum_2 https://rest.pubmlst.org/db/pubmlst_mgallisepticum_seqdef/schemes/2
|
|
81
|
+
mhaemolytica https://rest.pubmlst.org/db/pubmlst_mhaemolytica_seqdef/schemes/1
|
|
82
|
+
mhominis_3 https://rest.pubmlst.org/db/pubmlst_mhominis_seqdef/schemes/3
|
|
83
|
+
mhyopneumoniae https://rest.pubmlst.org/db/pubmlst_mhyopneumoniae_seqdef/schemes/1
|
|
84
|
+
mhyorhinis https://rest.pubmlst.org/db/pubmlst_mhyorhinis_seqdef/schemes/1
|
|
85
|
+
miowae https://rest.pubmlst.org/db/pubmlst_miowae_seqdef/schemes/1
|
|
86
|
+
mplutonius https://rest.pubmlst.org/db/pubmlst_mplutonius_seqdef/schemes/1
|
|
87
|
+
mpneumoniae https://rest.pubmlst.org/db/pubmlst_mpneumoniae_seqdef/schemes/1
|
|
88
|
+
msciuri https://rest.pubmlst.org/db/pubmlst_msciuri_seqdef/schemes/1
|
|
89
|
+
msynoviae https://rest.pubmlst.org/db/pubmlst_msynoviae_seqdef/schemes/1
|
|
90
|
+
mycobacteria_2 https://rest.pubmlst.org/db/pubmlst_mycobacteria_seqdef/schemes/2
|
|
91
|
+
neisseria https://rest.pubmlst.org/db/pubmlst_neisseria_seqdef/schemes/1
|
|
92
|
+
oralstrep https://rest.pubmlst.org/db/pubmlst_oralstrep_seqdef/schemes/1
|
|
93
|
+
orhinotracheale https://rest.pubmlst.org/db/pubmlst_orhinotracheale_seqdef/schemes/1
|
|
94
|
+
otsutsugamushi https://rest.pubmlst.org/db/pubmlst_otsutsugamushi_seqdef/schemes/1
|
|
95
|
+
pacnes_3 https://rest.pubmlst.org/db/pubmlst_pacnes_seqdef/schemes/3
|
|
96
|
+
paeruginosa https://rest.pubmlst.org/db/pubmlst_paeruginosa_seqdef/schemes/1
|
|
97
|
+
pdamselae https://rest.pubmlst.org/db/pubmlst_pdamselae_seqdef/schemes/1
|
|
98
|
+
pfluorescens https://rest.pubmlst.org/db/pubmlst_pfluorescens_seqdef/schemes/1
|
|
99
|
+
pgingivalis https://rest.pubmlst.org/db/pubmlst_pgingivalis_seqdef/schemes/1
|
|
100
|
+
plarvae https://rest.pubmlst.org/db/pubmlst_plarvae_seqdef/schemes/1
|
|
101
|
+
pmultocida https://rest.pubmlst.org/db/pubmlst_pmultocida_seqdef/schemes/1
|
|
102
|
+
pmultocida_2 https://rest.pubmlst.org/db/pubmlst_pmultocida_seqdef/schemes/2
|
|
103
|
+
ppentosaceus https://rest.pubmlst.org/db/pubmlst_ppentosaceus_seqdef/schemes/1
|
|
104
|
+
pputida https://rest.pubmlst.org/db/pubmlst_pputida_seqdef/schemes/1
|
|
105
|
+
psalmonis https://rest.pubmlst.org/db/pubmlst_psalmonis_seqdef/schemes/1
|
|
106
|
+
ranatipestifer https://rest.pubmlst.org/db/pubmlst_ranatipestifer_seqdef/schemes/1
|
|
107
|
+
rhodococcus https://rest.pubmlst.org/db/pubmlst_rhodococcus_seqdef/schemes/1
|
|
108
|
+
sagalactiae https://rest.pubmlst.org/db/pubmlst_sagalactiae_seqdef/schemes/1
|
|
109
|
+
saureus https://rest.pubmlst.org/db/pubmlst_saureus_seqdef/schemes/1
|
|
110
|
+
sbsec https://rest.pubmlst.org/db/pubmlst_sbsec_seqdef/schemes/1
|
|
111
|
+
scanis https://rest.pubmlst.org/db/pubmlst_scanis_seqdef/schemes/1
|
|
112
|
+
schromogenes https://rest.pubmlst.org/db/pubmlst_schromogenes_seqdef/schemes/1
|
|
113
|
+
sdysgalactiae https://rest.pubmlst.org/db/pubmlst_sdysgalactiae_seqdef/schemes/1
|
|
114
|
+
senterica_achtman_2 https://rest.pubmlst.org/db/pubmlst_senterica_achtman_seqdef/schemes/2
|
|
115
|
+
sepidermidis https://rest.pubmlst.org/db/pubmlst_sepidermidis_seqdef/schemes/1
|
|
116
|
+
sgallolyticus https://rest.pubmlst.org/db/pubmlst_sgallolyticus_seqdef/schemes/1
|
|
117
|
+
shaemolyticus https://rest.pubmlst.org/db/pubmlst_shaemolyticus_seqdef/schemes/1
|
|
118
|
+
shewanella https://rest.pubmlst.org/db/pubmlst_shewanella_seqdef/schemes/1
|
|
119
|
+
shominis https://rest.pubmlst.org/db/pubmlst_shominis_seqdef/schemes/1
|
|
120
|
+
sinorhizobium https://rest.pubmlst.org/db/pubmlst_sinorhizobium_seqdef/schemes/1
|
|
121
|
+
smaltophilia https://rest.pubmlst.org/db/pubmlst_smaltophilia_seqdef/schemes/1
|
|
122
|
+
spneumoniae https://rest.pubmlst.org/db/pubmlst_spneumoniae_seqdef/schemes/1
|
|
123
|
+
spseudintermedius https://rest.pubmlst.org/db/pubmlst_spseudintermedius_seqdef/schemes/1
|
|
124
|
+
spyogenes https://rest.pubmlst.org/db/pubmlst_spyogenes_seqdef/schemes/1
|
|
125
|
+
ssuis https://rest.pubmlst.org/db/pubmlst_ssuis_seqdef/schemes/1
|
|
126
|
+
staphlugdunensis https://bigsdb.pasteur.fr/api/db/pubmlst_staphlugdunensis_seqdef/schemes/1
|
|
127
|
+
sthermophilus https://rest.pubmlst.org/db/pubmlst_sthermophilus_seqdef/schemes/1
|
|
128
|
+
streptomyces https://rest.pubmlst.org/db/pubmlst_streptomyces_seqdef/schemes/1
|
|
129
|
+
streptothermophilus https://bigsdb.pasteur.fr/api/db/pubmlst_streptothermophilus_seqdef/schemes/1
|
|
130
|
+
suberis https://rest.pubmlst.org/db/pubmlst_suberis_seqdef/schemes/1
|
|
131
|
+
szooepidemicus https://rest.pubmlst.org/db/pubmlst_szooepidemicus_seqdef/schemes/1
|
|
132
|
+
taylorella https://rest.pubmlst.org/db/pubmlst_taylorella_seqdef/schemes/1
|
|
133
|
+
tenacibaculum https://rest.pubmlst.org/db/pubmlst_tenacibaculum_seqdef/schemes/1
|
|
134
|
+
tpallidum https://rest.pubmlst.org/db/pubmlst_tpallidum_seqdef/schemes/1
|
|
135
|
+
ureaplasma https://rest.pubmlst.org/db/pubmlst_ureaplasma_seqdef/schemes/1
|
|
136
|
+
vcholerae https://rest.pubmlst.org/db/pubmlst_vcholerae_seqdef/schemes/1
|
|
137
|
+
vcholerae_2 https://rest.pubmlst.org/db/pubmlst_vcholerae_seqdef/schemes/2
|
|
138
|
+
vibrio https://rest.pubmlst.org/db/pubmlst_vibrio_seqdef/schemes/1
|
|
139
|
+
vparahaemolyticus https://rest.pubmlst.org/db/pubmlst_vparahaemolyticus_seqdef/schemes/1
|
|
140
|
+
vtapetis https://rest.pubmlst.org/db/pubmlst_vtapetis_seqdef/schemes/1
|
|
141
|
+
vvulnificus https://rest.pubmlst.org/db/pubmlst_vvulnificus_seqdef/schemes/1
|
|
142
|
+
wolbachia https://rest.pubmlst.org/db/pubmlst_wolbachia_seqdef/schemes/1
|
|
143
|
+
xfastidiosa https://rest.pubmlst.org/db/pubmlst_xfastidiosa_seqdef/schemes/1
|
|
144
|
+
ypseudotuberculosis_achtman_3 https://rest.pubmlst.org/db/pubmlst_ypseudotuberculosis_achtman_seqdef/schemes/3
|
|
145
|
+
yruckeri https://rest.pubmlst.org/db/pubmlst_yruckeri_seqdef/schemes/1
|
mlstdb/utils.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
# Color formatting using click
|
|
4
|
+
def error(msg: str) -> None:
|
|
5
|
+
click.secho(f"Error: {msg}", fg="red", err=True)
|
|
6
|
+
|
|
7
|
+
def success(msg: str) -> None:
|
|
8
|
+
click.secho(msg, fg="green")
|
|
9
|
+
|
|
10
|
+
def info(msg: str) -> None:
|
|
11
|
+
click.secho(msg, fg="blue")
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlstdb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package to update and manage the MLST database for the MLST tool.
|
|
5
|
+
Project-URL: Documentation, https://github.com/himal2007/mlstdb#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/himal2007/mlstdb/issues
|
|
7
|
+
Project-URL: Source, https://github.com/himal2007/mlstdb
|
|
8
|
+
Author-email: Himal Shrestha <stha.himal2007@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
+
Requires-Python: >=3
|
|
21
|
+
Requires-Dist: click>=8.0.0
|
|
22
|
+
Requires-Dist: configparser>=5.0.0
|
|
23
|
+
Requires-Dist: pathlib>=1.0.1
|
|
24
|
+
Requires-Dist: rauth>=0.7.3
|
|
25
|
+
Requires-Dist: requests>=2.25.0
|
|
26
|
+
Requires-Dist: tqdm>=4.65.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: black>=22.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: isort>=5.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'test'
|
|
33
|
+
Requires-Dist: pytest>=6.0; extra == 'test'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# mlstdb
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/mlstdb)
|
|
39
|
+
[](https://pypi.org/project/mlstdb)
|
|
40
|
+
|
|
41
|
+
`mlstdb` is a Python package to update and manage the MLST database for the `mlst` tool using the PubMLST and BIGSdb Pasteur APIs. It is written to handle the OAuth2 authentication process that's required to access up-to-date MLST schemes available on these databases. This tool allows user to fetch MLST schemes, filter the schemes, and update the MLST database for the `mlst` tool.
|
|
42
|
+
|
|
43
|
+
-----
|
|
44
|
+
|
|
45
|
+
## Table of Contents
|
|
46
|
+
|
|
47
|
+
- [mlstdb](#mlstdb)
|
|
48
|
+
- [Table of Contents](#table-of-contents)
|
|
49
|
+
- [Prerequisites](#prerequisites)
|
|
50
|
+
- [Installation](#installation)
|
|
51
|
+
- [Usage](#usage)
|
|
52
|
+
- [Final Steps](#final-steps)
|
|
53
|
+
- [License](#license)
|
|
54
|
+
|
|
55
|
+
## Prerequisites
|
|
56
|
+
|
|
57
|
+
Should install `mlst` for the use of this tool.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
From bioconda: TODO:
|
|
62
|
+
```console
|
|
63
|
+
conda install -c bioconda mlstdb
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
From PyPI:
|
|
67
|
+
```console
|
|
68
|
+
pip install mlstdb
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
`mlstdb` uses a simple two step process to update the MLST database for the `mlst` tool. It has two main subcommands: `fetch` and `update`.
|
|
74
|
+
|
|
75
|
+
1. **Fetch MLST schemes**
|
|
76
|
+
|
|
77
|
+
```console
|
|
78
|
+
mlstdb fetch --help
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
```console
|
|
82
|
+
Usage: mlstdb fetch [OPTIONS]
|
|
83
|
+
|
|
84
|
+
BIGSdb Scheme Fetcher Tool
|
|
85
|
+
|
|
86
|
+
This tool downloads MLST scheme information from BIGSdb databases. It will
|
|
87
|
+
automatically handle authentication and save the results.
|
|
88
|
+
|
|
89
|
+
Options:
|
|
90
|
+
-h, --help Show this message and exit.
|
|
91
|
+
-d, --db [pubmlst|pasteur] Database to use (pubmlst or pasteur)
|
|
92
|
+
-e, --exclude TEXT Scheme name must not include provided term
|
|
93
|
+
(default: cgMLST)
|
|
94
|
+
-m, --match TEXT Scheme name must include provided term (default:
|
|
95
|
+
MLST)
|
|
96
|
+
-s, --scheme-uris TEXT Optional: Path to custom scheme_uris.tab file
|
|
97
|
+
-f, --filter TEXT Filter species or schemes using a wildcard
|
|
98
|
+
pattern
|
|
99
|
+
-r, --resume Resume processing from where it stopped
|
|
100
|
+
-v, --verbose Enable verbose logging for debugging
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Use the `fetch` command to download MLST schemes from the BIGSdb databases. The `--db` argument specifies the database to use, which can be either `pubmlst` or `pasteur`. The `--exclude` and `--match` arguments can be used to filter the schemes based on the scheme name. The `--scheme-uris` argument can be used to provide a custom scheme URIs file. The `--filter` argument can be used to filter species or schemes using a wildcard pattern. The `--resume` flag can be used to resume processing from where it stopped. The `--verbose` flag can be used to enable verbose logging for debugging. This will create a `mlst_schemes_<db>.txt` file with the MLST schemes.
|
|
104
|
+
|
|
105
|
+
We can just use `mlstdb fetch` to download the MLST schemes from the BIGSdb databases. If the registration is not done, it will prompt the user to register the client credentials. This will save the client credentials to the `~/.config/mlstdb` directory.
|
|
106
|
+
|
|
107
|
+
In cases where the tool does not find an appropriate scheme name, it will prompt the user to either set the missing schemes as 'missing' or auto-generate them. The user can choose the appropriate option.
|
|
108
|
+
|
|
109
|
+
<details>
|
|
110
|
+
<summary>Auto extraction of scheme?🤔</summary>
|
|
111
|
+
|
|
112
|
+
First, the script automatically tries to extract the scheme names from the `dbases.sh` file. If the scheme name is not found, it will prompt the user to either print `missing` in the output file or automatically create a scheme name based on the URL. For eg, for URL `https://rest.pubmlst.org/db/pubmlst_borrelia_seqdef/schemes/1`, the scheme name will be `borrelia`. If there are multiple schemes, it will append a number to the scheme name. For eg, for URLs `https://rest.pubmlst.org/db/pubmlst_chlamydiales_seqdef/schemes/38` and `https://rest.pubmlst.org/db/pubmlst_chlamydiales_seqdef/schemes/41`, the scheme names will be `chlamydiales_38` and `chlamydiales_41` respectively.
|
|
113
|
+
|
|
114
|
+
</details>
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
The script offers feature to filter for particular species/schemes. It is recommended to run with filter option and thus, download only the required schemes so as not to tamper with the existing DBs and schemes.
|
|
118
|
+
|
|
119
|
+
**📝Important**: `mlst` tool is designed for typing bacterial species only. Please make sure to filter the non-bacterial schemes from your schemes file.
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
2. **Update MLST database**
|
|
123
|
+
|
|
124
|
+
```console
|
|
125
|
+
mlstdb update --help
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```console
|
|
129
|
+
Usage: mlstdb update [OPTIONS]
|
|
130
|
+
|
|
131
|
+
Update MLST schemes and create BLAST database.
|
|
132
|
+
|
|
133
|
+
Downloads MLST schemes from the specified input file and creates a BLAST
|
|
134
|
+
database from the downloaded sequences. Authentication tokens should be set
|
|
135
|
+
up using fetch.py.
|
|
136
|
+
|
|
137
|
+
Options:
|
|
138
|
+
-h, --help Show this message and exit.
|
|
139
|
+
-i, --input TEXT Path to mlst_schemes_<db>.txt containing MLST
|
|
140
|
+
scheme URLs [required]
|
|
141
|
+
-d, --directory TEXT Directory to save the downloaded MLST schemes
|
|
142
|
+
(default: pubmlst)
|
|
143
|
+
-b, --blast-directory TEXT Directory for BLAST database (default: relative
|
|
144
|
+
to directory as ../blast)
|
|
145
|
+
-v, --verbose Enable verbose logging for debugging
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Use the `update` command to update the MLST database and create a BLAST database. The `--input` argument specifies the path to the `mlst_schemes_<db>.txt` file containing MLST scheme URLs. The `--directory` argument specifies the directory to save the downloaded MLST schemes. The `--blast-directory` argument specifies the directory for the BLAST database. The `--verbose` flag can be used to enable verbose logging for debugging.
|
|
149
|
+
|
|
150
|
+
We can prepare a custom `mlst_schemes_<db>.txt` file and use `mlstdb update` to update the MLST database for select species and schemes. This will automatically create a BLAST database from the downloaded sequences.
|
|
151
|
+
|
|
152
|
+
## Final Steps
|
|
153
|
+
After running all scripts, verify the database setup by running the `mlst` tool with the updated database:
|
|
154
|
+
```bash
|
|
155
|
+
mlst --blastdb <path_to_blast/mlst.fa> --datadir <path_to_pubmlst_dir>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
`mlstdb` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
For additional support, please raise an issue.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
mlstdb/__about__.py,sha256=S2NBpoFdt_UW3FL1iHUO9cY1Nms779HIbcPK6-DSGws,130
|
|
2
|
+
mlstdb/__init__.py,sha256=GZ5hnxVMz_TJfAKjdHDk1JLiFHhOak3p8PwdD6WmqVg,114
|
|
3
|
+
mlstdb/__main__.py,sha256=LN80DXxpECRPsMOoF3fw4-cBcx5gaE8Uxs76IZwrAe8,186
|
|
4
|
+
mlstdb/utils.py,sha256=ESq6bA1LlWoKEj9IBboEmAowsI3r4sps0_e8Wumchhw,255
|
|
5
|
+
mlstdb/.bigsdb_tokens/access_tokens,sha256=9HQqpeccECAUOCvJjo_RsFMplntZUmmE9Z6jlQCX-gc,186
|
|
6
|
+
mlstdb/.bigsdb_tokens/client_credentials,sha256=6Mdgqm5e-HiTs9liKpOlaQiwUCm95-XjbHQMLEcfN_g,213
|
|
7
|
+
mlstdb/.bigsdb_tokens/session_tokens,sha256=6XVC0GUnAqwLtJKLchezF65mOMbkqQ5smDUBzGidXHo,187
|
|
8
|
+
mlstdb/cli/__init__.py,sha256=Gv4MNaNAJiOO432lLsW1ONVyDPZA4E5Wt49AobVcKbU,452
|
|
9
|
+
mlstdb/cli/fetch.py,sha256=8wLn4W5yIv6UFM-Vf4wWkmPWL9Tgnhxo90s1VHGXJTQ,6293
|
|
10
|
+
mlstdb/cli/update.py,sha256=Zk6G_2_U5r-_irxKx6WjxT6w2JLOjLPvjhHQinC_PCc,3298
|
|
11
|
+
mlstdb/core/__init__.py,sha256=OnDNLbzdG6FNc3TScIfGTreGvuokJjHKcNT20adsLoY,54
|
|
12
|
+
mlstdb/core/auth.py,sha256=XSwQe1tCL-33i8sn47UYs_WXr4X0CAeKWZ6w_NXu5HI,6513
|
|
13
|
+
mlstdb/core/config.py,sha256=hLD_toDgrFuw5v5cqdsxFvfZ0zVm6rkRssShSy9LABI,1142
|
|
14
|
+
mlstdb/core/download.py,sha256=OGSS7u9FHNFKS-D_yg9mdyosAAVUVRYicKJP-GBgb5U,16080
|
|
15
|
+
mlstdb/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
mlstdb/data/scheme_uris.tab,sha256=8GM2vltRR6IzlPI7fm7fAe_y291-Pahl0gQJa23Rxbo,11510
|
|
17
|
+
mlstdb-0.1.0.dist-info/METADATA,sha256=tO7r-T0ceG3G0FXZD7NGQqv3xIOLfAIh5YmKFvMj8nM,7722
|
|
18
|
+
mlstdb-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
19
|
+
mlstdb-0.1.0.dist-info/entry_points.txt,sha256=K5QEQyLaFsqZv0Zpzb7R96JbQqSLcgafkrwlDUmEw-0,45
|
|
20
|
+
mlstdb-0.1.0.dist-info/licenses/LICENSE.txt,sha256=0JQADVyovg_H26-abQSLwUi5xH6WjLN_yJ6q3WjeR50,1106
|
|
21
|
+
mlstdb-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Himal Shrestha <stha.himal2007@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|