annotate Dotplot_Release/Normalization.R @ 1:7e98f893e9ae draft

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