Skip to main content
[Preprint]. 2023 Jul 11:2023.07.10.548264. [Version 1] doi: 10.1101/2023.07.10.548264

Algorithm 1:

Assigning mutational signatures to samples with SigProfilerAssignment

Input: vN+ξ×1 (a vector corresponding to a set of mutations in a sample) and SR+ξ×1 (a matrix corresponding to a set of n known mutational signatures)
Output: aN+n×1 (the vector reflecting the activities of the n known signatures in sample v)
1: ϵmin, a=calcNNLS(v,S)
Sall=S
2: While FLAG = True:
3: ϵmin, S=removeSignatures(v,S,ϵmin)
4: ϵmin, S=addSignatures(v,Sall,S,ϵmin)
5: Set FLAG = False if S remains constant and there is no addition or removal of signatures
END While
6: ϵmin, a=calcNNLS(v,S)
7: Return a
8: FUNCTION removeSignatures (v,S,ϵmin)
9: While FLAG = True:
10:   For j in 1 to size(S, 2) do // loop from 1 to the total number of signatures in S
11:    Sˆ=S[:,j] // remove the jth signature from S
12:    [j], aj=calcNNLS(v,S^)
  END For
13:   minIndex, minValue=min(ϵ) // find the signature set with least relative error
14:   If (minValueϵmin0.01)
15:    S=S[:,minIndex]
  else
16:    Return minValue, S
  END If
END While
END removeSignatures
17: FUNCTION addSignatures (v,Sall,S,ϵmin)
18: While FLAG = True:
19:   For p in 1 to size(Sall, 2) do // loop from 1 to the total number of signatures in Sall
20:    S^=[S;Sall[:,p]] // add the pth signature from Sall
21:    ϵ[j], aj=calcNNLS(v,S^)
  END For
22:   minIndex, minValue=min(ϵ) // find the signature set with least relative error
23:   If ϵminminValue0.05
24:    S=[S;Sall[:,minValue]]
  else
25:    Return minValue, S
  END If
END While
END addSignatures
26: FUNCTION calcNNLS (v,S)
27: a=nnls(S,v) // Calculating NNLS with the Lawson-Hanson method
28: ϵ=vSa22/v22 // Computing relative error
29: Return ϵ, a
END calcNNLS