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

2.1.5p5 #63

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6e7faee
fix mypy error
rannick Mar 14, 2022
d553d38
Merge branch 'matq007:master' into master
rannick Aug 19, 2022
0e70efe
fix mitelman + fusiongdb2 enabled
rannick Aug 19, 2022
76cff27
add workflow to build docker image
rannick Aug 30, 2022
cde799a
edit workflow to build docker image
rannick Aug 30, 2022
67f272f
edit workflow to build docker image
rannick Aug 30, 2022
e3aadc6
edit workflow to build docker image
rannick Aug 30, 2022
9186ca7
rename fusions table of fusiongdb2
rannick Sep 12, 2022
cfa8dda
add qiagen option for downloading cosmic db
rannick Feb 22, 2023
4cac902
Merge branch 'mittelman_fix' into add_qiagen_for_cosmic
rannick Feb 22, 2023
acd7c46
Delete fusion_report.log.2023-02-21
rannick Feb 22, 2023
3358956
Merge pull request #1 from Clinical-Genomics/add_qiagen_for_cosmic
rannick Feb 22, 2023
c782130
Small fix for setuppy
apeltzer Feb 28, 2023
642a109
Attempt at fixing missing definition
apeltzer Feb 28, 2023
88b069c
Modified net classs
apeltzer Feb 28, 2023
e8289ff
Added small change
apeltzer Feb 28, 2023
0dc10a5
Fix token handling
apeltzer Feb 28, 2023
7b764ed
Small further bugfix
apeltzer Feb 28, 2023
456e685
Looks faster now
apeltzer Feb 28, 2023
dd1cf01
Download should go to output
apeltzer Feb 28, 2023
f897116
Add function to extract only fusion file ids
apeltzer Feb 28, 2023
f491901
Access file
apeltzer Feb 28, 2023
05ee8b8
This should do
apeltzer Feb 28, 2023
79af059
This works reliably
apeltzer Feb 28, 2023
2f099d6
Merge pull request #2 from apeltzer/mittelman_fix
rannick Feb 28, 2023
cf0abab
change tag of docker image
rannick Feb 28, 2023
d692b48
Silencio
apeltzer Feb 28, 2023
585edc9
Merge pull request #3 from apeltzer/mittelman_fix
rannick Feb 28, 2023
988bc4d
remove staticmethod for include_raw
rannick Mar 12, 2023
80d3725
change docker version
rannick Mar 12, 2023
9449956
remove MACOSX files from being taken into account
rannick Aug 28, 2023
e5379f8
update docker image
rannick Aug 28, 2023
2d98644
update docker for master
rannick Aug 28, 2023
e21f5f7
Merge pull request #4 from Clinical-Genomics/2.1.5p3.0
rannick Aug 28, 2023
76cf9d0
fix 403 error for fusiongdb
rannick Sep 15, 2023
c1bf562
update docker image
rannick Sep 18, 2023
ce78485
Merge pull request #5 from Clinical-Genomics/update_docker_image
rannick Sep 18, 2023
fa633da
add manual docker workflow
rannick Sep 18, 2023
6b55dcc
Merge pull request #6 from Clinical-Genomics/2.1.5p3.0
rannick Sep 18, 2023
fbcec1a
update cosmic to v98
rannick Oct 18, 2023
e75dd7f
update docker image version
rannick Oct 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/docker-image-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Docker Image CI [ master ]

on:
workflow_dispatch:
jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Login to DockerHub
id: docker_login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build only
id: docker_build_only
uses: docker/build-push-action@v2
with:
file: Dockerfile
push: true
tags: clinicalgenomics/fusion-report:2.1.5p5
25 changes: 25 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker Image CI [ master ]

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Login to DockerHub
id: docker_login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build only
id: docker_build_only
uses: docker/build-push-action@v2
with:
file: Dockerfile
push: true
tags: clinicalgenomics/fusion-report:2.1.5p4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ tests/sss
*.log
.tox/
.DS_Store
testfusionreport.sh
thisismydb/
11 changes: 11 additions & 0 deletions docs/download.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ fusion_report download
/path/to/db
```

With a non-academic/research login -> using QIAGEN with a commercial license:

```bash
fusion_report download
--cosmic_usr '<QIAGEN username>'
--cosmic_passwd 'QIAGEN <password>'
--qiagen
/path/to/db
```


## Manual download

### FusionGDB
Expand Down
2 changes: 1 addition & 1 deletion fusion_report/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def export_results(self, path: str, extension: str) -> None:
def generate_fusion_list(self, path: str, cutoff: int):
"""
Helper function that generates file containing list of found fusions and filtered list of
fusions. One of these files ise used by FusionInspector to visualize the fusions.
fusions. One of these files is used by FusionInspector to visualize the fusions.
Input for FusionInspector expects list of fusions in format `geneA--geneB\n`.

Returns:
Expand Down
7 changes: 5 additions & 2 deletions fusion_report/args_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_args(self, args, weight) -> None:
help=optional.get('help'),
action=optional.get('action')
)
else:
else:
run_optional.add_argument(
optional['key'][0], optional['key'][1],
default=optional.get('default'), help=optional.get('help'),
Expand Down Expand Up @@ -117,7 +117,10 @@ def _cosmic(self, args: Dict[str, Any], parser) -> None:
which will be used to generate base64 token or the token itself.'''
)
for cosmic in args['cosmic']:
download_cosmic.add_argument(cosmic['key'], help=cosmic['help'], type=str)
if not cosmic.get('action'):
download_cosmic.add_argument(cosmic['key'], help=cosmic.get('help'), type=str)
else:
download_cosmic.add_argument(cosmic['key'], help=cosmic.get('help'), action=cosmic.get('action'))

def parse(self) -> Namespace:
"""Parse arguments."""
Expand Down
5 changes: 5 additions & 0 deletions fusion_report/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
{
"key": "--cosmic_token",
"help": "COSMIC token"
},
{
"key": "--qiagen",
"help": "Use QIAGEN to download COSMIC db (commercial usage)",
"action": "store_true"
}
]
}
Expand Down
103 changes: 87 additions & 16 deletions fusion_report/common/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import time
import pandas as pd
from zipfile import ZipFile

import subprocess
import json

from argparse import Namespace
from typing import List
Expand All @@ -32,16 +33,59 @@ def get_cosmic_token(params: Namespace):
if params.cosmic_token is not None:
return params.cosmic_token

if (
params.cosmic_token is None
and (params.cosmic_usr is not None or params.cosmic_passwd is not None)
):
if params.cosmic_usr is not None and params.cosmic_passwd is not None:
return base64.b64encode(
f'{params.cosmic_usr}:{params.cosmic_passwd}'.encode()
).decode('utf-8')
else:
raise DownloadException('COSMIC credentials have not been provided correctly')

@staticmethod
def run_qiagen_cmd(cmd, return_output=False, silent=False):
if not silent:
print(cmd)
if return_output:
output = subprocess.check_output(cmd, shell=True, executable='/bin/bash').strip()
return output
else:
subprocess.check_call(cmd, shell=True, executable='/bin/bash')

@staticmethod
def get_qiagen_files(token: str, output_path: str):
files_request = 'curl --stderr -s -X GET ' \
'-H "Content-Type: application/octet-stream" ' \
'-H "Authorization: Bearer {token}" ' \
'"https://my.qiagendigitalinsights.com/bbp/data/files/cosmic"' \
' -o {output_path}qiagen_files.tsv'
cmd = files_request.format(token=token, output_path = output_path)
return Net.run_qiagen_cmd(cmd, True, True)

@staticmethod
def download_qiagen_file(token: str, file_id: str, output_path: str):
file_request = 'curl -s -X GET ' \
'-H "Content-Type: application/octet-stream" ' \
'-H "Authorization: Bearer {token}" ' \
'"https://my.qiagendigitalinsights.com/bbp/data/download/cosmic-download?name={file_id}"' \
' -o {output_path}CosmicFusionExport.tsv.gz'
cmd = file_request.format(token=token, file_id=file_id, output_path=output_path)
Net.run_qiagen_cmd(cmd, True, True)

@staticmethod
def fetch_fusion_file_id(output_path: str):
df = pd.read_csv(output_path+"/qiagen_files.tsv", names=['file_id','file_name','genome_draft'], sep='\t')
file_id = df.loc[(df['file_name'] == Settings.COSMIC["FILE"]) & (df['genome_draft'] == 'cosmic/GRCh38'), 'file_id'].values[0]
return file_id

@staticmethod
def get_cosmic_qiagen_token(params: Namespace):
token_request = 'curl -s -X POST ' \
'-H "Content-Type: application/x-www-form-urlencoded" ' \
'-d "grant_type=password&client_id=603912630-14192122372034111918-SmRwso&username={uid}&password={pwd}" ' \
'"https://apps.ingenuity.com/qiaoauth/oauth/token"'
cmd = token_request.format(uid=params.cosmic_usr, pwd=params.cosmic_passwd)
token_response = Net.run_qiagen_cmd(cmd, True, True).decode('UTF-8')
return json.loads(token_response)['access_token']

@staticmethod
def get_large_file(url: str, ignore_ssl: bool = False) -> None:
"""Method for downloading a large file."""
Expand All @@ -54,7 +98,9 @@ def get_large_file(url: str, ignore_ssl: bool = False) -> None:

if url.startswith('https') or url.startswith('ftp'):
try:
with urllib.request.urlopen(url, context=ctx) as response:
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0')
with urllib.request.urlopen(req, context=ctx) as response:
file = url.split('/')[-1].split('?')[0]
Logger(__name__).info('Downloading %s', file)
# only download if file size doesn't match
Expand All @@ -68,8 +114,8 @@ def get_large_file(url: str, ignore_ssl: bool = False) -> None:
Logger(__name__).error('Downloading resources supports only HTTPS or FTP')

@staticmethod
def get_cosmic(token: str, return_err: List[str]) -> None:
"""Method for download COSMIC database."""
def get_cosmic_from_sanger(token: str, return_err: List[str]) -> None:
"""Method for download COSMIC database from sanger website."""

# get auth url to download file
files = []
Expand All @@ -96,17 +142,42 @@ def get_cosmic(token: str, return_err: List[str]) -> None:
except urllib.error.HTTPError as ex:
return_err.append(f'{Settings.COSMIC["NAME"]}: {ex}')

@staticmethod
def get_cosmic_from_qiagen(token: str, return_err: List[str], outputpath: str) -> None:
"""Method for download COSMIC database from QIAGEN."""
try:
result = Net.get_qiagen_files(token, outputpath)
except Exception as ex:
print(ex)
#Then continue parsing out the fusion_file_id
file_id = Net.fetch_fusion_file_id(outputpath)
Net.download_qiagen_file(token, file_id, outputpath)
file: str = Settings.COSMIC["FILE"]
files = []

try:
files.append('.'.join(file.split('.')[:-1]))

with gzip.open(file, 'rb') as archive, open(files[0], 'wb') as out_file:
shutil.copyfileobj(archive, out_file)

db = CosmicDB('.')
db.setup(files, delimiter='\t', skip_header=True)
except urllib.error.HTTPError as ex:
return_err.append(f'{Settings.COSMIC["NAME"]}: {ex}')


@staticmethod
def get_fusiongdb(self, return_err: List[str]) -> None:
"""Method for download FusionGDB database."""

pool_params = [
(f'{Settings.FUSIONGDB["HOSTNAME"]}/{x}', True) for x in Settings.FUSIONGDB["FILES"]
]
pool = Pool(Settings.THREAD_NUM)
pool.starmap(Net.get_large_file, pool_params)
pool.close()
pool.join()
for file in Settings.FUSIONGDB["FILES"]:
try:
url: str = (f'{Settings.FUSIONGDB["HOSTNAME"]}/{file}')
Net.get_large_file(url)
except DownloadException as ex:
return_err.append(f'FusionGDB: {ex}')

db = FusionGDB('.')
db.setup(Settings.FUSIONGDB['FILES'], delimiter='\t', skip_header=False)

Expand Down Expand Up @@ -135,7 +206,7 @@ def get_mitelman(self, return_err: List[str]) -> None:
url: str = f'{Settings.MITELMAN["HOSTNAME"]}/{Settings.MITELMAN["FILE"]}'
Net.get_large_file(url)
with ZipFile(Settings.MITELMAN['FILE'], 'r') as archive:
files = [x for x in archive.namelist() if "mitelman_db/MBCA.TXT.DATA" in x]
files = [x for x in archive.namelist() if "MBCA.TXT.DATA" in x and not "MACOSX" in x]
archive.extractall()

db = MitelmanDB('.')
Expand Down
4 changes: 2 additions & 2 deletions fusion_report/common/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pathlib import Path
from typing import Any, Dict

from jinja2 import Environment, FileSystemLoader, Markup

from jinja2 import Environment, FileSystemLoader
from markupsafe import Markup
from fusion_report.common.page import Page
from fusion_report.config import Config
from fusion_report.settings import Settings
Expand Down
4 changes: 2 additions & 2 deletions fusion_report/data/schema/FusionGDB2.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CREATE TABLE "fusionGDB2" (
"Fusions" varchar(50) NOT NULL DEFAULT ''
CREATE TABLE "fusiongdb2" (
"fusions" varchar(50) NOT NULL DEFAULT ''
);
14 changes: 11 additions & 3 deletions fusion_report/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def __init__(self, params: Namespace):
self.download_all(params)

def validate(self, params: Namespace) -> None:
"""Method validating required input. In this case COSMIC credentials."""
self.cosmic_token = Net.get_cosmic_token(params)
"""Method validating required input. In this case COSMIC credentials."""
if(params.qiagen):
self.cosmic_token = Net.get_cosmic_qiagen_token(params)
else:
self.cosmic_token = Net.get_cosmic_token(params)

# making sure output directory exists
if not os.path.exists(params.output):
Expand All @@ -44,7 +47,12 @@ def download_all(self, params: Namespace) -> None:
Net.get_fusiongdb2(self, return_err)

# COSMIC
Net.get_cosmic(self.cosmic_token, return_err)
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
2 changes: 2 additions & 0 deletions fusion_report/modules/index_summary/index_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def tool_detection(self) -> List[List[Any]]:
counts['together'] = 0
running_tools_count: int = len(running_tools)
for fusion in self.manager.fusions:
print(fusion.name)
fusion_tools = fusion.tools.keys()
for tool in fusion_tools:
print(tool)
counts[tool] += 1
# intersection
if len(fusion_tools) == running_tools_count:
Expand Down
2 changes: 1 addition & 1 deletion fusion_report/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Settings:

COSMIC: Dict[str, str] = {
"NAME": "COSMIC",
"HOSTNAME": "https://cancer.sanger.ac.uk/cosmic/file_download/GRCh38/cosmic/v95",
"HOSTNAME": "https://cancer.sanger.ac.uk/cosmic/file_download/GRCh38/cosmic/v98",
"SCHEMA": "Cosmic.sql",
"FILE": "CosmicFusionExport.tsv.gz",
}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ colorlog
python-rapidjson
pyyaml>=4.2b1
Jinja2>=2.10
MarkupSafe
MarkupSafe>=2.1.1
pandas
openpyxl
xlrd >= 1.0.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
setup(
name='fusion_report',
version=Settings.VERSION,
python_requires='>=3.6.*',
python_requires='>=3.6',
description='Tool for parsing outputs from fusion detection tools.',
long_description=README,
author='Martin Proks',
Expand Down
Loading