Skip to content

Commit b61d426

Browse files
committed
Add parameter to disable automatic background signature addition
Add add_background_signatures parameter (default: True) to allow users to disable the automatic inclusion of background signatures SBS1 and SBS5 during signature assignment. - Added parameter to spa_analyze(), signature_decomposition(), and all Analyzer functions - Added CLI flag --disable_background_signatures - Updated logic to conditionally add SBS1/SBS5 only when enabled - Maintains backward compatibility (defaults to True)
1 parent a3d1d13 commit b61d426

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

SigProfilerAssignment/Analyzer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def decompose_fit(
2525
export_probabilities_per_mutation=False,
2626
volume=None,
2727
cpu=-1,
28+
add_background_signatures=True,
2829
):
2930
decomp.spa_analyze(
3031
samples=samples,
@@ -53,6 +54,7 @@ def decompose_fit(
5354
export_probabilities_per_mutation=export_probabilities_per_mutation,
5455
volume=volume,
5556
cpu=cpu,
57+
add_background_signatures=add_background_signatures,
5658
)
5759

5860

@@ -79,6 +81,7 @@ def denovo_fit(
7981
export_probabilities_per_mutation=False,
8082
volume=None,
8183
cpu=-1,
84+
add_background_signatures=True,
8285
):
8386
decomp.spa_analyze(
8487
samples=samples,
@@ -106,6 +109,7 @@ def denovo_fit(
106109
export_probabilities_per_mutation=export_probabilities_per_mutation,
107110
volume=volume,
108111
cpu=cpu,
112+
add_background_signatures=add_background_signatures,
109113
)
110114

111115

@@ -133,6 +137,7 @@ def cosmic_fit(
133137
sample_reconstruction_plots=False,
134138
volume=None,
135139
cpu=-1,
140+
add_background_signatures=True,
136141
):
137142
decomp.spa_analyze(
138143
samples=samples,
@@ -161,4 +166,5 @@ def cosmic_fit(
161166
sample_reconstruction_plots=sample_reconstruction_plots,
162167
volume=volume,
163168
cpu=cpu,
169+
add_background_signatures=add_background_signatures,
164170
)

SigProfilerAssignment/controllers/cli_controller.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ def parse_arguments_common(args: List[str], description: str) -> argparse.Namesp
154154
"'png' (PNG only, PDF removed)."
155155
),
156156
)
157+
parser.add_argument(
158+
"--add_background_signatures",
159+
type=str2bool,
160+
nargs="?",
161+
const=True,
162+
default=True,
163+
help="Automatically add background signatures SBS1 and SBS5 (default: True).",
164+
)
157165

158166

159167
return parser.parse_args(args)
@@ -189,6 +197,7 @@ def dispatch_decompose_fit(self, user_args: List[str]) -> None:
189197
context_type=parsed_args.context_type,
190198
export_probabilities=parsed_args.export_probabilities,
191199
export_probabilities_per_mutation=parsed_args.export_probabilities_per_mutation,
200+
add_background_signatures=parsed_args.add_background_signatures,
192201
)
193202

194203
def dispatch_denovo_fit(self, user_args: List[str]) -> None:
@@ -219,6 +228,7 @@ def dispatch_denovo_fit(self, user_args: List[str]) -> None:
219228
context_type=parsed_args.context_type,
220229
export_probabilities=parsed_args.export_probabilities,
221230
export_probabilities_per_mutation=parsed_args.export_probabilities_per_mutation,
231+
add_background_signatures=parsed_args.add_background_signatures,
222232
)
223233

224234
def dispatch_cosmic_fit(self, user_args: List[str]) -> None:
@@ -250,4 +260,5 @@ def dispatch_cosmic_fit(self, user_args: List[str]) -> None:
250260
export_probabilities=parsed_args.export_probabilities,
251261
export_probabilities_per_mutation=parsed_args.export_probabilities_per_mutation,
252262
sample_reconstruction_plots=parsed_args.sample_reconstruction_plots,
263+
add_background_signatures=parsed_args.add_background_signatures,
253264
)

SigProfilerAssignment/decompose_subroutines.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def signature_decomposition(
300300
exome=False,
301301
m_for_subgroups="SBS",
302302
volume=None,
303+
add_background_signatures=True,
303304
):
304305
originalProcessAvg = originalProcessAvg.reset_index()
305306
if not os.path.exists(directory + "/Solution_Stats"):
@@ -395,7 +396,10 @@ def signature_decomposition(
395396

396397
# only for SBS96
397398
if mtype == "96" or mtype == "288" or mtype == "1536":
398-
bgsigs = get_indeces(list(signames), ["SBS1", "SBS5"])
399+
if add_background_signatures:
400+
bgsigs = get_indeces(list(signames), ["SBS1", "SBS5"])
401+
else:
402+
bgsigs = []
399403
else:
400404
bgsigs = []
401405

@@ -691,7 +695,10 @@ def signature_decomposition(
691695

692696
# only for SBS96
693697
if mtype == "96" or mtype == "288" or mtype == "1536":
694-
background_sigs = get_indeces(list(detected_signatures), ["SBS1", "SBS5"])
698+
if add_background_signatures:
699+
background_sigs = get_indeces(list(detected_signatures), ["SBS1", "SBS5"])
700+
else:
701+
background_sigs = []
695702
# add connected signatures
696703
different_signatures = ss.add_connected_sigs(
697704
different_signatures, list(signames)
@@ -874,8 +881,10 @@ def process_sample(args):
874881
set().union(list(np.nonzero(exposureAvg[:, r])[0]), background_sigs)
875882
)
876883

877-
if background_sigs != 0:
884+
if background_sigs and len(background_sigs) > 0:
878885
background_sig_idx = get_indeces(allsigids, ["SBS1", "SBS5"])
886+
else:
887+
background_sig_idx = []
879888

880889
try:
881890
(

SigProfilerAssignment/decomposition.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def spa_analyze(
264264
make_metadata=True,
265265
volume=None,
266266
cpu=-1,
267+
add_background_signatures=True,
267268
):
268269
"""
269270
Decomposes the De Novo Signatures into COSMIC Signatures and assigns COSMIC signatures into samples.
@@ -644,7 +645,10 @@ def spa_analyze(
644645
attribution[i] = [i]
645646
# only for SBS96
646647
if mutation_type == "96" or mutation_type == "288" or mutation_type == "1536":
647-
background_sigs = sub.get_indeces(list(allsigids), ["SBS1", "SBS5"])
648+
if add_background_signatures:
649+
background_sigs = sub.get_indeces(list(allsigids), ["SBS1", "SBS5"])
650+
else:
651+
background_sigs = []
648652
# add connected signatures
649653
# different_signatures = ss.add_connected_sigs(different_signatures, list(signames))
650654
# for other contexts
@@ -855,6 +859,7 @@ def spa_analyze(
855859
exome=exome,
856860
m_for_subgroups=m_for_subgroups,
857861
volume=volume,
862+
add_background_signatures=add_background_signatures,
858863
)
859864
# final_signatures = sub.signature_decomposition(processAvg, m, layer_directory2, genome_build=genome_build)
860865
# extract the global signatures and new signatures from the final_signatures dictionary
@@ -1016,7 +1021,10 @@ def spa_analyze(
10161021
attribution[i] = [i]
10171022
# only for SBS96
10181023
if mutation_type == "96" or mutation_type == "288" or mutation_type == "1536":
1019-
background_sigs = sub.get_indeces(list(allsigids), ["SBS1", "SBS5"])
1024+
if add_background_signatures:
1025+
background_sigs = sub.get_indeces(list(allsigids), ["SBS1", "SBS5"])
1026+
else:
1027+
background_sigs = []
10201028
# add connected signatures
10211029
# different_signatures = ss.add_connected_sigs(different_signatures, list(signames))
10221030
# for other contexts

0 commit comments

Comments
 (0)