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