annotate Dotplot_Release/Normalization.R @ 29:16df07f285c0 draft default tip

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