0
|
1 #!/usr/bin/env Rscript
|
|
2
|
|
3 args <- commandArgs(trailingOnly = TRUE)
|
|
4
|
|
5 #this programs normalizes a saint input file based on the spectral counts of all preys
|
|
6
|
|
7 d = read.delim(args[1], header=T, sep="\t", as.is=T)
|
|
8
|
|
9 baitn = 1
|
|
10 curr_bait <- d$Bait[1]
|
|
11 s <- vector()
|
|
12 s[1] = 0
|
|
13 for(i in 1:length(d$Bait)){
|
|
14 if(curr_bait != d$Bait[i]){
|
|
15 baitn <- baitn + 1
|
|
16 curr_bait <- d$Bait[i]
|
|
17 s[baitn] <- d$AvgSpec[i]
|
|
18 }
|
|
19 else{
|
|
20 s[baitn] <- s[baitn] + d$AvgSpec[i]
|
|
21 }
|
|
22 }
|
|
23
|
|
24 med.s = median(s)
|
|
25 s = s / med.s
|
|
26
|
|
27 d_n <- d
|
|
28 baitn = 1
|
|
29 curr_bait <- d_n$Bait[1]
|
|
30 for(i in 1:length(d_n$Bait)){
|
|
31 if(curr_bait != d_n$Bait[i]){
|
|
32 baitn <- baitn + 1
|
|
33 curr_bait <- d_n$Bait[i]
|
|
34 d_n$AvgSpec[i] <- d_n$AvgSpec[i]/s[baitn]
|
|
35 }
|
|
36 else{
|
|
37 d_n$AvgSpec[i] <- d_n$AvgSpec[i]/s[baitn]
|
|
38 }
|
|
39 }
|
|
40
|
|
41 #print normalized data to file
|
|
42
|
|
43 write.table(d_n, file = "norm_saint.txt", sep="\t", quote=F, row.names=F)
|
|
44
|