Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make db optional #77

Merged
merged 16 commits into from
Oct 2, 2024
64 changes: 64 additions & 0 deletions fusion_report.log.2024-06-25
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
2024-06-25 09:55:25,106 - CRITICAL - fusion_report.common.net - table "mbca" already exists
rannick marked this conversation as resolved.
Show resolved Hide resolved
Traceback (most recent call last):
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/db.py", line 61, in setup
self.create_database()
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/db.py", line 84, in create_database
self.connection.executescript(schema.read().lower())
sqlite3.OperationalError: table "mbca" already exists

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/app.py", line 72, in run
Download(params)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/download.py", line 23, in __init__
self.download_all(params)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/download.py", line 42, in download_all
Net.get_mitelman(self, return_err)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/net.py", line 203, in get_mitelman
db.setup(files, delimiter="\t", skip_header=False, encoding="ISO-8859-1")
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/db.py", line 79, in setup
raise DbException(ex)
fusion_report.common.exceptions.db.DbException: table "mbca" already exists

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/EGG-INFO/scripts/fusion_report", line 13, in <module>
app.run()
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/app.py", line 79, in run
raise AppException(ex)
fusion_report.common.exceptions.app.AppException: table "mbca" already exists
2024-06-25 09:56:32,905 - CRITICAL - fusion_report.common.net - unable to open database file
Traceback (most recent call last):
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/db.py", line 37, in connect
connection = sqlite3.connect(os.path.join(path, database))
sqlite3.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/app.py", line 60, in run
self.preprocess(params)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/app.py", line 84, in preprocess
self.enrich(params.db_path)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/app.py", line 124, in enrich
CosmicDB(path).name: CosmicDB(path).get_all_fusions(),
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/singleton.py", line 12, in __call__
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/data/cosmic.py", line 15, in __init__
super().__init__(path, Settings.COSMIC["NAME"], Settings.COSMIC["SCHEMA"])
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/db.py", line 25, in __init__
self.connection = self.connect(path, self.database)
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/common/db.py", line 41, in connect
raise DbException(ex)
fusion_report.common.exceptions.db.DbException: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/EGG-INFO/scripts/fusion_report", line 13, in <module>
app.run()
File "/Users/annick.renevey/anaconda3/envs/fusion-report/lib/python3.9/site-packages/fusion_report-2.1.5-py3.9.egg/fusion_report/app.py", line 79, in run
raise AppException(ex)
fusion_report.common.exceptions.app.AppException: unable to open database file
6 changes: 3 additions & 3 deletions fusion_report/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from typing import Any, Dict, List

import rapidjson
import json

from tqdm import tqdm

Expand Down Expand Up @@ -138,7 +138,7 @@ def export_results(self, path: str, extension: str) -> None:
if extension == "json":
with open(dest, "w", encoding="utf-8") as output:
results = [fusion.json_serialize() for fusion in self.manager.fusions]
output.write(rapidjson.dumps(results))
output.write(json.dumps(results))
elif extension == "csv":
with open(dest, "w", encoding="utf-8") as output:
csv_writer = csv.writer(
Expand Down Expand Up @@ -248,4 +248,4 @@ def generate_multiqc(

dest = f"{os.path.join(path, 'fusion_genes_mqc.json')}"
with open(dest, "w", encoding="utf-8") as output:
output.write(rapidjson.dumps(configuration))
output.write(json.dumps(configuration))
11 changes: 9 additions & 2 deletions fusion_report/args_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from argparse import ArgumentParser, Namespace, _SubParsersAction
from typing import Any, Dict

import rapidjson
import json

from fusion_report.settings import Settings

Expand All @@ -21,7 +21,7 @@ class ArgsBuilder:
def __init__(self):
configuration = os.path.join(Settings.ROOT_DIR, "arguments.json")
with open(configuration, "r") as config_file:
self.arguments: Dict[str, Any] = rapidjson.loads(config_file.read())
self.arguments: Dict[str, Any] = json.load(config_file)
self.arguments["weight"] = float(100 / len(self.supported_tools))
self.parser = ArgumentParser(
description="""Tool for generating friendly UI custom report."""
Expand Down Expand Up @@ -108,6 +108,13 @@ def download_args(self, args: Dict[str, Any]) -> None:
for mandatory in args["mandatory"]:
download_parser.add_argument(mandatory["key"], help=mandatory["help"], type=str)

for optional in args["optionals"]:
download_parser.add_argument(
optional["key"],
help=optional["help"],
action=optional.get("action", "store"),
)

self._cosmic(args, download_parser)

def sync_args(self, args: Dict[str, Any]) -> None:
Expand Down
17 changes: 17 additions & 0 deletions fusion_report/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@
"help": "Output directory"
}
],
"optionals": [
{
"key": "--no-cosmic",
"help": "Do not download cosmic fusion database",
"action": "store_true"
},
{
"key": "--no-fusiongdb2",
"help": "Do not download fusiongdb2 fusion database",
"action": "store_true"
},
{
"key": "--no-mitelman",
"help": "Do not download mitelman fusion database",
"action": "store_true"
}
],
"cosmic": [
{
"key": "--cosmic_usr",
Expand Down
1 change: 1 addition & 0 deletions fusion_report/common/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class Net:
@staticmethod
def get_cosmic_token(params: Namespace):
print(params.no_cosmic)
if params.cosmic_token is not None:
return params.cosmic_token

Expand Down
31 changes: 18 additions & 13 deletions fusion_report/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Download:
"""

def __init__(self, params: Namespace):
self.validate(params)
self.download_all(params)

def validate(self, params: Namespace) -> None:
Expand All @@ -29,28 +28,34 @@ def validate(self, params: Namespace) -> None:
else:
self.cosmic_token = Net.get_cosmic_token(params)


def download_all(self, params: Namespace) -> None:

# making sure output directory exists
if not os.path.exists(params.output):
os.makedirs(params.output, 0o755)

def download_all(self, params: Namespace) -> None:
"""Download all databases."""
return_err: List[str] = []
os.chdir(params.output)

# MITELMAN
Net.get_mitelman(self, return_err)
if not params.no_mitelman:
# MITELMAN
Net.get_mitelman(self, return_err)

# FusionGDB2
Net.get_fusiongdb2(self, return_err)
if not params.no_fusiongdb2:
# FusionGDB2
Net.get_fusiongdb2(self, return_err)

# COSMIC
if params.qiagen:
Logger(__name__).info("Downloading resources from QIAGEN...")
Net.get_cosmic_from_qiagen(self.cosmic_token, return_err, params.output)
else:
Logger(__name__).info("Downloading resources from SANGER...")
Net.get_cosmic_from_sanger(self.cosmic_token, return_err)
if not params.no_cosmic:
# COSMIC
self.validate(params)
if params.qiagen:
Logger(__name__).info("Downloading resources from QIAGEN...")
Net.get_cosmic_from_qiagen(self.cosmic_token, return_err, params.output)
else:
Logger(__name__).info("Downloading resources from SANGER...")
Net.get_cosmic_from_sanger(self.cosmic_token, return_err)

if len(return_err) > 0:
raise DownloadException(return_err)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pyyaml>=4.2b1
Jinja2>=2.10
MarkupSafe>=2.1.1
pandas
python-rapidjson
requests
openpyxl
xlrd >= 2.0.0
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ lines_after_imports=2
lines_between_types=1
multi_line_output=7
use_parentheses=true
known_third_party=colorlog,jinja2,rapidjson,setuptools,tqdm,yaml
known_third_party=colorlog,jinja2,setuptools,tqdm,yaml