-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummaryScript.r
More file actions
executable file
·70 lines (55 loc) · 1.97 KB
/
summaryScript.r
File metadata and controls
executable file
·70 lines (55 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/Rscript
suppressMessages(library(optparse))
# get the summarie values of each variable
getSums <- function(y){
temp <- c(bait_name=unique(y$bait_name), bait_uniprot_id=unique(y$bait_uniprot_id), ID=unique(y$ID), num_unique_prey=length(unique(y[,4])))
temp <- c(temp, num_unique_peptides=sum(na.omit(y$Uniq.Pep)))
idx <- which(y$Acc..==temp[2]) #location of bait in the prey list
if(length(idx)>0){
temp <- c(temp, bait_detected="Y", bait_rank=y[idx,]$Rank)
}else{
temp <- c(temp, bait_detected="N", bait_rank="0")
}
temp <- c(temp, top_rank=y[which(y$Rank=="[1]"),]$Acc)
return(temp)
}
# wrapper to summarize each bait ID
summarize <- function(x){
tmp <- c()
for(i in unique(x$ID)){
idx <- which(x$ID == i)
tmp <- rbind(tmp,getSums(x[idx,]))
}
tmp <- as.data.frame(tmp)
tmp <- tmp[order(tmp$bait_rank),]
return(tmp)
}
# get bait names and merge them with the Prospector data file
mergeWkeys <- function(datafile, keysfile){
dat <- read.delim(datafile, header=TRUE, stringsAsFactors=FALSE, sep="\t")
keys <- read.delim(keysfile, header=TRUE, stringsAsFactors=FALSE, sep="\t")
names(dat)[1] <- names(keys)[2] <- "ID"
dat <- merge(dat, keys[,c(2,5,7)], by="ID", all.x=TRUE)
n <- dim(dat)[2]
x1 <- dat[,c(n,n-1)]
x2 <- dat[,-c(n,n-1)]
dat <- cbind(x1, x2)
return(dat)
}
# begin summarizing
main <- function(datafile, keysfile){
dat <- mergeWkeys(datafile, keysfile)
x <- summarize(dat)
return(x)
}
option_list <- list(
make_option(c("-d", "--data_file"),
help="data file containing Prospector output"),
make_option(c("-o", "--output_file"),
help="output file for summary matrix"),
make_option(c("-k", "--keys_file"),
help="keys file for summary matrix")
)
parsedArgs = parse_args(OptionParser(option_list = option_list), args = commandArgs(trailingOnly=T))
summarizedData <- main(parsedArgs$data_file, parsedArgs$keys_file)
write.table(summarizedData, parsedArgs$output_file, sep="\t", quote=FALSE, row.names=FALSE, col.names=TRUE)