annotate Dotplot_Release/Normalization_sigpreys.R @ 13:e74888e94f96 draft

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