annotate Dotplot_Release/Normalization_sigpreys.R @ 5:dc2aed283637 draft

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