Skip to content

Commit

Permalink
Merge pull request #173 from AlexandrovLab/docker
Browse files Browse the repository at this point in the history
Upgrade to v1.2.23
  • Loading branch information
mdbarnesUCSD authored Jan 31, 2024
2 parents 411e2e8 + daa5b28 commit 9b12f7d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use an official Python runtime as a parent image
FROM python:3.8-slim

# Set the working directory in the container
WORKDIR /usr/src/app

# Install SigProfilerMatrixGenerator from PyPI
RUN pip install SigProfilerMatrixGenerator==1.2.23

# Create a non-root user named 'spm_user'
RUN useradd -m -s /bin/bash spm_user

# Change the ownership of the /usr/src/app directory and its contents to the new non-root user
RUN chown -R spm_user:spm_user /usr/src/app

# Switch to the non-root user for subsequent commands and when running the container
USER spm_user
67 changes: 67 additions & 0 deletions SigProfilerMatrixGenerator/controllers/cli_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from SigProfilerMatrixGenerator import test_helpers
from SigProfilerMatrixGenerator.scripts import (
SigProfilerMatrixGeneratorFunc as mg,
SVMatrixGenerator as sv_mg,
CNVMatrixGenerator as cnv_mg,
reference_genome_manager,
)

Expand Down Expand Up @@ -129,6 +131,54 @@ def parse_arguments_matrix_generator(args: List[str]) -> argparse.Namespace:
return result


def parse_arguments_sv_matrix_generator(args: List[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Generate a structural variant (SV) matrix from input data."
)

# Mandatory arguments
parser.add_argument("input_dir", help="The directory containing the input files.")
parser.add_argument("project", help="The name of the project.")
parser.add_argument(
"output_dir", help="The directory where the output matrix will be stored."
)

result = parser.parse_args(args)
return result


def parse_arguments_cnv_matrix_generator(args: List[str]) -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Generate a Copy Number Variation (CNV) matrix."
)

# Mandatory arguments
parser.add_argument(
"file_type",
choices=[
"ASCAT",
"ASCAT_NGS",
"SEQUENZA",
"ABSOLUTE",
"BATTENBERG",
"FACETS",
"PURPLE",
"TCGA",
],
help="The type of the input file based on the CNV calling tool used (e.g., 'ASCAT').",
)
parser.add_argument(
"input_file", help="The absolute path to the multi-sample segmentation file."
)
parser.add_argument("project", help="The name of the project.")
parser.add_argument(
"output_path", help="The path where the output CNV matrix will be stored."
)

result = parser.parse_args(args)
return result


class CliController:
def dispatch_install(self, user_args: List[str]) -> None:
parsed_args = parse_arguments_install(user_args)
Expand Down Expand Up @@ -161,3 +211,20 @@ def dispatch_matrix_generator(self, user_args: List[str]) -> None:
cushion=parsed_args.cushion,
volume=parsed_args.volume,
)

def dispatch_sv_matrix_generator(self, user_args: List[str]) -> None:
parsed_args = parse_arguments_sv_matrix_generator(user_args)
sv_mg.generateSVMatrix(
input_dir=parsed_args.input_dir,
project=parsed_args.project,
output_dir=parsed_args.output_dir,
)

def dispatch_cnv_matrix_generator(self, user_args: List[str]) -> None:
parsed_args = parse_arguments_cnv_matrix_generator(user_args)
cnv_mg.generateCNVMatrix(
file_type=parsed_args.file_type,
input_file=parsed_args.input_file,
project=parsed_args.project,
output_path=parsed_args.output_path,
)
4 changes: 2 additions & 2 deletions SigProfilerMatrixGenerator/scripts/MutationMatrixGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def perm(n, seq):
return permus


def reference_paths(genome):
def reference_paths(genome, volume=None):
"""
Returns the path to the reference genomes installed with SigProfilerMatrixGenerator
Expand All @@ -95,7 +95,7 @@ def reference_paths(genome):
Returns:
chrom_path -> path to the reference genome's chromosome files
"""
reference_dir = ref_install.reference_dir()
reference_dir = ref_install.reference_dir(secondary_chromosome_install_dir=volume)
ref_dir = str(reference_dir.path)
chrom_path = str(reference_dir.get_tsb_dir() / genome) + "/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
def main_function():
commands = {
"install": "Install reference genome files (required to generate matrices).",
"matrix_generator": "Create mutational matrices for all types of somatic mutations.",
"matrix_generator": "Create mutational matrices for SBSs, DBSs, and INDELs.",
"sv_matrix_generator": "Create mutational matrices for SVs.",
"cnv_matrix_generator": "Create mutational matrices for CNVs.",
}

if len(sys.argv) < 2 or sys.argv[1].lower() not in commands:
Expand All @@ -28,6 +30,10 @@ def main_function():
controller.dispatch_install(args)
elif command == "matrix_generator":
controller.dispatch_matrix_generator(args)
elif command == "sv_matrix_generator":
controller.dispatch_sv_matrix_generator(args)
elif command == "cnv_matrix_generator":
controller.dispatch_cnv_matrix_generator(args)


def print_usage(commands):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import setup

VERSION = "1.2.22"
VERSION = "1.2.23"

# remove the dist folder first if exists
if os.path.exists("dist"):
Expand All @@ -23,7 +23,7 @@ def write_version_py(filename="SigProfilerMatrixGenerator/version.py"):
# THIS FILE IS GENERATED FROM SIGPROFILEMATRIXGENERATOR SETUP.PY
short_version = '%(version)s'
version = '%(version)s'
Update = 'v1.2.22: CLI calls ReferenceGenomeManager to download reference genomes and not install.py'
Update = 'v1.2.23: Add SV and CNV matrix generation to CLI. Add Dockerfile.'
"""
fh = open(filename, "w")
Expand Down

0 comments on commit 9b12f7d

Please sign in to comment.