Skip to content

Commit

Permalink
feat(runner.py): new function added: implemented a function to downlo…
Browse files Browse the repository at this point in the history
…ad and extract the exomiser runner

this function will handle the preinstallation processes for exomiser runner, and must exist for every different pheval runner ensuring a streamlined setup.
  • Loading branch information
souzadevinicius committed Dec 11, 2024
1 parent 7df5587 commit 6eea26d
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions src/pheval_exomiser/runner.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""Exomiser Runner"""

import os
import zipfile
from dataclasses import dataclass
from pathlib import Path

import requests
from pheval.runners.runner import PhEvalRunner

from pheval_exomiser.post_process.post_process import post_process_result_format
from pheval_exomiser.prepare.tool_specific_configuration_options import ExomiserConfigurations
from pheval_exomiser.prepare.write_application_properties import ExomiserConfigurationFileWriter
from pheval_exomiser.prepare.tool_specific_configuration_options import (
ExomiserConfigurations,
)
from pheval_exomiser.prepare.write_application_properties import (
ExomiserConfigurationFileWriter,
)
from pheval_exomiser.run.run import prepare_batch_files, run_exomiser


Expand All @@ -22,6 +29,67 @@ class ExomiserPhEvalRunner(PhEvalRunner):
config_file: Path
version: str

def install(self, overwrite_existing: bool = False):
# Parse configuration options
configuration = ExomiserConfigurations.parse_obj(
self.input_dir_config.tool_specific_configuration_options
)
phenotype_version = configuration.application_properties.phenotype_data_version

# Define filenames and URLs
base_url = "https://data.monarchinitiative.org/exomiser"
filenames = [
f"{phenotype_version}_hg19.zip",
f"{phenotype_version}_hg38.zip",
f"{phenotype_version}_phenotype.zip",
]
urls = [
f"{base_url}/{self.version}/exomiser-cli-{self.version}-distribution.zip",
*[f"{base_url}/data/{filename}" for filename in filenames],
]

# Download files
os.makedirs("./data/tmp/", exist_ok=True)
for url in urls:
filename = url.split("/")[-1]
full_filename = f"./data/tmp/{filename}"

if os.path.exists(full_filename) and not overwrite_existing:
continue

response = requests.get(url)
response.raise_for_status() # Raise an error for bad responses
with open(full_filename, "wb") as f:
f.write(response.content)

# Check if data directory exists
data_dir = f"exomiser-cli-{self.version}/data"
if os.path.exists(data_dir) and not overwrite_existing:
return

# Unzip distribution file
with zipfile.ZipFile(
f"exomiser-cli-{self.version}-distribution.zip", "r"
) as zip_ref:
zip_ref.extractall(".")

# Unzip data files into the appropriate directory
os.makedirs(data_dir, exist_ok=True)
for filename in filenames:
with zipfile.ZipFile(filename, "r") as zip_ref:
zip_ref.extractall(data_dir)

# Update application.properties
properties_path = os.path.join(data_dir, "application.properties")
with open(properties_path, "a") as prop_file:
prop_file.writelines(
[
f"exomiser.hg19.data-version={phenotype_version}\n",
f"exomiser.hg38.data-version={phenotype_version}\n",
f"exomiser.phenotype.data-version={phenotype_version}\n",
]
)

def prepare(self):
"""prepare"""
print("preparing")
Expand Down

0 comments on commit 6eea26d

Please sign in to comment.