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 2bcb7c7..45a0687 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) @@ -1017,18 +1017,26 @@ def generateSVMatrix(input_dir, project, output_dir, skip=False): all_samples.append(result["sv_bedpe"]) + 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) 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