-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_outlayer_contributors.R
More file actions
54 lines (37 loc) · 1.65 KB
/
add_outlayer_contributors.R
File metadata and controls
54 lines (37 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
add_outlayer_contributors=function(samples,
signatures,
set_of_signature,
cutoff_exposure=0.05)
{
"
As a final step, the function remove all the signatures that contribute less than a certain percentage of the total contribution
Args:
- samples: matrix of samples you want to fit [nrow=96,ncol=num_of_samples]
- signatures: matrix of all the signatures [nrow=96,ncol=num_of_signatures]
- set_of_signature: vector with the indices of the current signatures
- cutoff_exposure: cutoff to choose whether a signature is removed from the set of signatures (RSS criterion)
Returns:
- set_of_signature: the updated set of signatures
"
#Total number of mutations in the sample
total_num_mut=mean(colSums(samples))
# loop_bool is a boolean that checks if we have to continue removing signatures
loop_bool=T
while(loop_bool){
loop_bool=F
if(length(set_of_signature)>1){
# We fit or samples
fit=fit_to_signatures(samples,signatures[,set_of_signature])
#Compute the mean exposure by signature
meanExpo=rowMeans(fit$contribution)
# We remove the small activities one by one starting with the signature with the smallest activity
min=min(meanExpo)
# if the smallest activity accounts for less than cutoff_exposure*the total number of mutations in the sample, we remove it
if(min<total_num_mut*cutoff_exposure){
set_of_signature=set_of_signature[-which.min(meanExpo)]
loop_bool=T
}
}
}
return(set_of_signature)
}