From fec46b6ed2c5fd414e18cefa0428a7e469b7ab2d Mon Sep 17 00:00:00 2001 From: Jakob Jersild Nielsen Date: Sat, 11 Oct 2025 13:27:19 +0200 Subject: [PATCH 1/3] Don't generate matrix if 0 classified SVs --- SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py b/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py index 2bcb7c7..f90a179 100644 --- a/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py +++ b/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py @@ -1017,6 +1017,10 @@ def generateSVMatrix(input_dir, project, output_dir, skip=False): all_samples.append(result["sv_bedpe"]) + if len(all_samples) < 1 and skip == True: + print("Warning: all samples have 0 classified SVs") + return None + matrix = tsv2matrix(all_samples, project, output_dir) out_file = os.path.join(output_dir, project + ".SV32.matrix.tsv") matrix.to_csv(out_file, sep="\t") From 60e1a5cb83a8b93a08e74129ebca608b3048e28d Mon Sep 17 00:00:00 2001 From: Jakob Jersild Nielsen Date: Sat, 11 Oct 2025 15:03:51 +0200 Subject: [PATCH 2/3] Optional plotting --- .../controllers/cli_controller.py | 9 +++++++++ .../scripts/SVMatrixGenerator.py | 20 ++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/SigProfilerMatrixGenerator/controllers/cli_controller.py b/SigProfilerMatrixGenerator/controllers/cli_controller.py index 0c43333..6526cbc 100644 --- a/SigProfilerMatrixGenerator/controllers/cli_controller.py +++ b/SigProfilerMatrixGenerator/controllers/cli_controller.py @@ -161,6 +161,14 @@ def parse_arguments_sv_matrix_generator(args: List[str]) -> argparse.Namespace: # 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( + "--plot", + type=str2bool, + nargs="?", + const=True, + default=False, + help="Integrates with SigProfilerPlotting to output matrix visualization. Default is False.", + ) parser.add_argument( "output_dir", help="The directory where the output matrix will be stored." ) @@ -245,6 +253,7 @@ def dispatch_sv_matrix_generator(self, user_args: List[str]) -> None: input_dir=parsed_args.input_dir, project=parsed_args.project, output_dir=parsed_args.output_dir, + plot=parsed_args.plot, ) def dispatch_cnv_matrix_generator(self, user_args: List[str]) -> None: diff --git a/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py b/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py index f90a179..33bffc7 100644 --- a/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py +++ b/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py @@ -930,7 +930,7 @@ def annotateBedpe(sv_bedpe): return result -def generateSVMatrix(input_dir, project, output_dir, skip=False): +def generateSVMatrix(input_dir, project, output_dir, plot=True, skip=False): # create output_dir if it does not yet exist if not os.path.exists(output_dir): os.makedirs(output_dir) @@ -1025,14 +1025,16 @@ def generateSVMatrix(input_dir, project, output_dir, skip=False): out_file = os.path.join(output_dir, project + ".SV32.matrix.tsv") matrix.to_csv(out_file, sep="\t") print("Saved matrix to " + out_file) - sigPlt.plotSV( - matrix, - output_dir, - project, - savefig_format="pdf", - percentage=False, - aggregate=True, - ) + + if plot == True: + sigPlt.plotSV( + matrix, + output_dir, + project, + savefig_format="pdf", + percentage=False, + aggregate=True, + ) return matrix From b83f8c05286d19b1564a5432f569006dadf991e2 Mon Sep 17 00:00:00 2001 From: Jakob Jersild Nielsen Date: Sat, 11 Oct 2025 15:12:47 +0200 Subject: [PATCH 3/3] Always skip matrix generation if 0 classified SVs --- SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py b/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py index 33bffc7..45a0687 100644 --- a/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py +++ b/SigProfilerMatrixGenerator/scripts/SVMatrixGenerator.py @@ -1017,8 +1017,10 @@ def generateSVMatrix(input_dir, project, output_dir, plot=True, skip=False): all_samples.append(result["sv_bedpe"]) - if len(all_samples) < 1 and skip == True: - print("Warning: all samples have 0 classified SVs") + if len(all_samples) < 1: + fout.write( + "Warning: unable to generate SV matrix, as all samples have 0 classified SVs" + ) return None matrix = tsv2matrix(all_samples, project, output_dir)