annotate bubbles_v9_NSAF_natural_log.R @ 6:a5f4ec159731 draft

Uploaded
author bornea
date Thu, 19 Nov 2015 10:36:27 -0500
parents 8eb1dd926f6e
children 79285a7acfbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
1 rm(list=ls())
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
2 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
3 # R-code: Multi-bubble graph generation from SAINTexpress output
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
4 # Author: Brent Kuenzi
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
5 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
6 library(dplyr); library(tidyr); library(ggplot2)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
7 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
8 ### Run program ###
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
9
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
10 ## REQUIRED INPUT ##
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
11 # 1) listfile: SAINTexpress generated "list.txt" file
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
12 # 2) preyfile: SAINT pre-processing generated "prey.txt" file used to run SAINTexpress
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
13 ## OPTIONAL INPUT ##
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
14 # 3) crapome: raw output from crapome Workflow 1 query (http://www.crapome.org)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
15 # 4) color: bubble color (default = "red")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
16 # - color= "crapome": color bubbles based on Crapome(%)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
17 # - Also recognizes any color within R's built-in colors() vector
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
18 # 5) label: Adds gene name labels to bubbles within the "zoomed in" graphs (default = FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
19 # 6) cutoff: Saintscore cutoff to be assigned for filtering the "zoomed in" graphs (default = 0.8)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
20 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
21 main <- function(listfile, preyfile , crapome=FALSE, color="red", label=FALSE, cutoff=0.8, type="SC", inc_file = "None", exc_file = "None" ) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
22 cutoff_check(cutoff)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
23 listfile <- list_type(listfile, inc_file, exc_file)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
24 if(type == "SC") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
25 df <- merge_files_sc(listfile, preyfile, crapome)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
26 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
27 if(type == "MQ") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
28 df <- merge_files_mq(listfile, preyfile, crapome)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
29 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
30 bubble_NSAF(df,color)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
31 bubble_SAINT(df,color)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
32 bubble_zoom_SAINT(df, color, label, cutoff)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
33 bubble_zoom_NSAF(df, color, label, cutoff)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
34 write.table(df,"output.txt",sep="\t",quote=FALSE, row.names=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
35 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
36
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
37 list_type <- function(df, inc_file, exc_file) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
38 Saint <- read.delim(df, stringsAsFactors=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
39 if (inc_file != "None") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
40 if (exc_file == "None"){
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
41 inc_prots <- read.delim(inc_file, sep='\t', header=FALSE, stringsAsFactors=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
42 print(inc_prots[,1])
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
43 print(Saint$Prey)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
44 filtered_df = subset(Saint, Saint$Prey == inc_prots[,1])
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
45 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
46 else {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
47 inc_prots <- read.delim(inc_file, sep='\t', header=FALSE, stringsAsFactors=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
48 exc_prots <- read.delim(exc_file, sep='\t', header=FALSE, stringsAsFactors=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
49 filtered_df = subset(Saint, Saint$Prey == inc_prots[,1])
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
50 filtered_df = subset(filtered_df, filtered_df$Prey != exc_prots[,1])
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
51 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
52 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
53 else if (exc_file != "None") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
54 exc_prots <- read.delim(exc_file, sep='\t', header=FALSE, stringsAsFactors=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
55 filtered_df = subset(Saint, Saint$Prey != exc_prots[,1])
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
56 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
57 else {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
58 filtered_df = Saint
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
59 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
60 return(filtered_df)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
61
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
62 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
63 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
64 # Merge input files and caculate Crapome(%) and NSAF for each protein for each bait
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
65 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
66 merge_files_mq <- function(SAINT, prey_DF, crapome=FALSE) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
67 #SAINT <- read.table(SAINT_DF, sep='\t', header=TRUE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
68 prey <- read.table(prey_DF, sep='\t', header=FALSE); colnames(prey) <- c("Prey", "Length", "PreyGene")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
69 DF <- merge(SAINT,prey)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
70 DF$SpecSum <- log2(DF$SpecSum)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
71
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
72 if(crapome!=FALSE) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
73 crapome <- read.table(crapome, sep='\t', header=TRUE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
74 colnames(crapome) <- c("Prey", "Symbol", "Num.of.Exp", "Ave.SC", "Max.SC")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
75 DF1 <- merge(DF, crapome); as.character(DF1$Num.of.Exp); DF1$Symbol <- NULL;
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
76 DF1$Ave.SC <- NULL; DF1$Max.SC <- NULL #remove unnecessary columns
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
77 DF1$Num.of.Exp <- sub("^$", "0 / 1", DF1$Num.of.Exp ) #replace blank values with 0 / 1
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
78 DF <- DF1 %>% separate(Num.of.Exp, c("NumExp", "TotalExp"), " / ") #split into 2 columns
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
79 DF$CrapomePCT <- 100 - (as.integer(DF$NumExp) / as.integer(DF$TotalExp) * 100) #calculate crapome %
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
80 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
81 DF$SAF <- DF$AvgSpec / DF$Length
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
82 DF2 = DF %>% group_by(Bait) %>% mutate(NSAF = SAF/sum(SAF))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
83 DF$NSAF = DF2$NSAF
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
84 return(DF)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
85 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
86
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
87 merge_files_sc <- function(SAINT, prey_DF, crapome=FALSE) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
88 #SAINT <- read.table(SAINT_DF, sep='\t', header=TRUE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
89 prey <- read.table(prey_DF, sep='\t', header=FALSE); colnames(prey) <- c("Prey", "Length", "PreyGene")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
90 DF <- merge(SAINT,prey)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
91
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
92 if(crapome!=FALSE) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
93 crapome <- read.table(crapome, sep='\t', header=TRUE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
94 colnames(crapome) <- c("Prey", "Symbol", "Num.of.Exp", "Ave.SC", "Max.SC")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
95 DF1 <- merge(DF, crapome); as.character(DF1$Num.of.Exp); DF1$Symbol <- NULL;
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
96 DF1$Ave.SC <- NULL; DF1$Max.SC <- NULL #remove unnecessary columns
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
97 DF1$Num.of.Exp <- sub("^$", "0 / 1", DF1$Num.of.Exp ) #replace blank values with 0 / 1
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
98 DF <- DF1 %>% separate(Num.of.Exp, c("NumExp", "TotalExp"), " / ") #split into 2 columns
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
99 DF$CrapomePCT <- 100 - (as.integer(DF$NumExp) / as.integer(DF$TotalExp) * 100) #calculate crapome %
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
100 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
101 DF$SAF <- DF$AvgSpec / DF$Length
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
102 DF2 = DF %>% group_by(Bait) %>% mutate(NSAF = SAF/sum(SAF))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
103 DF$NSAF = DF2$NSAF
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
104 return(DF)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
105 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
106 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
107 # Plot all proteins for each bait by x=ln(NSAF), y=Log2(FoldChange)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
108 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
109 bubble_NSAF <- function(data, color) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
110 if(color=="crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
111 a <- subset(data, CrapomePCT <80, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
112 b <- subset(data, CrapomePCT>=80, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
113 p <- qplot(x=log(NSAF), y=log2(FoldChange), data=a, colour=I("tan"),size=SpecSum) + scale_size(range=c(1,10)) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
114 geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=a)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
115 if(length(levels(a$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")} # multiple graphs if multiple baits
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
116 p <- p + geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum, color=CrapomePCT), data=b) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
117 scale_colour_gradient(limits=c(80, 100), low="tan", high="red") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
118 labs(colour="CRAPome Probability \nof Specific Interaction (%)", x="ln(NSAF)") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
119 geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=b)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
120 return(ggsave(p, width=8,height=4,filename = "bubble_NSAF.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
121 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
122 if(color != "crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
123 p <- qplot(x=log(NSAF), y=log2(FoldChange), data=data, colour=I(color),size=SpecSum) + scale_size(range=c(1,10)) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
124 geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=data) + # add bubble outlines
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
125 labs(x="ln(NSAF)")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
126 if(length(levels(data$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
127 return(ggsave(p, width=8,height=4,filename = "bubble_NSAF.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
128 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
129 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
130 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
131 # Plot all proteins for each bait by x=Saintscore, y=Log2(FoldChange)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
132 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
133 bubble_SAINT <- function(data, color) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
134 if(color=="crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
135 a <- subset(data, CrapomePCT <80, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait)) #filter on CRAPome
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
136 b <- subset(data, CrapomePCT >=80, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
137 p <- qplot(x=SaintScore, y=log2(FoldChange), data=a, colour=I("tan"),size=SpecSum) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
138 scale_size(range=c(1,10)) + geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=a)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
139 if(length(levels(a$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
140 p <- p + geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum, color=CrapomePCT), data=b) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
141 scale_colour_gradient(limits=c(80, 100), low="tan", high="red") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
142 labs(colour="CRAPome Probability \nof Specific Interaction (%)") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
143 geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=b)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
144 return(ggsave(p, width=8,height=4,filename = "bubble_SAINT.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
145 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
146 if(color != "crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
147 p <- qplot(x=SaintScore, y=log2(FoldChange), data=data, colour=I(color),size=SpecSum) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
148 scale_size(range=c(1,10)) + geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=data)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
149 if(length(levels(data$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
150 return(ggsave(p, width=8,height=4,filename = "bubble_SAINT.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
151 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
152 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
153 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
154 # Filter proteins on Saintscore cutoff and plot for each bait x=Saintscore, y=Log2(FoldChange)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
155 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
156 bubble_zoom_SAINT <- function(data, color, label=FALSE, cutoff=0.8) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
157 if(color=="crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
158 a <- subset(data, CrapomePCT <80 & SaintScore>=cutoff, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait, PreyGene))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
159 b <- subset(data, CrapomePCT >=80 & SaintScore >=cutoff, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait, PreyGene))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
160 p <- qplot(x=SaintScore, y=log2(FoldChange), data=a, colour=I("tan"),size=SpecSum) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
161 scale_size(range=c(1,10)) + ggtitle("Filtered on SAINT score")+geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=a)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
162 if(label==TRUE & length(a$NSAF!=0)) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
163 p <- p + geom_text(data=a, aes(label=PreyGene, size=10, vjust=0, hjust=0),colour="black")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
164 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
165 if(length(levels(a$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
166 p <- p + geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum, color=CrapomePCT), data=b) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
167 scale_colour_gradient(limits=c(80, 100), low="tan", high="red") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
168 labs(colour="CRAPome Probability \nof Specific Interaction (%)") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
169 geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=b)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
170 if(label==TRUE & length(b$NSAF!=0)) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
171 p <- p + geom_text(data=b, aes(label=PreyGene, size=10, vjust=0, hjust=0),colour="black", show_guide=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
172 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
173 return(ggsave(p, width=8,height=4,filename = "bubble_zoom_SAINT.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
174 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
175 if(color != "crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
176 a <- subset(data, SaintScore>=cutoff, select = c(NSAF,SpecSum, FoldChange, SaintScore, Bait, PreyGene))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
177 p <- qplot(x=SaintScore, y=log2(FoldChange), data=a, colour=I(color),size=SpecSum) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
178 scale_size(range=c(1,10)) + ggtitle("Filtered on SAINT score") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
179 geom_point(aes(x=SaintScore,y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=a)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
180 if(label==TRUE & length(a$NSAF!=0)) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
181 p <- p + geom_text(data=a, aes(label=PreyGene, size=10, vjust=0, hjust=0),colour="black", show_guide=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
182 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
183 if(length(levels(data$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
184 return(ggsave(p, width=8,height=4,filename = "bubble_zoom_SAINT.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
185 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
186 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
187 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
188 # Filter proteins on Saintscore cutoff and plot for each bait x=log(NSAF), y=Log2(FoldChange)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
189 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
190 bubble_zoom_NSAF <- function(data, color, label=FALSE, cutoff=0.8) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
191 if(color=="crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
192 a <- subset(data, CrapomePCT <80 & SaintScore>=cutoff, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait, PreyGene))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
193 b <- subset(data, CrapomePCT >=80 & SaintScore >=cutoff, select = c(NSAF,SpecSum, CrapomePCT, FoldChange, SaintScore, Bait, PreyGene))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
194 p <- qplot(x=log(NSAF), y=log2(FoldChange), data=a, colour=I("tan"),size=SpecSum) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
195 scale_size(range=c(1,10)) + ggtitle("Filtered on SAINT score") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
196 geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=a)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
197 if(label==TRUE & length(a$NSAF!=0)) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
198 p <- p + geom_text(data=a, aes(label=PreyGene, size=10, vjust=0, hjust=0),colour="black")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
199 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
200 if(length(levels(a$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
201 p <- p + geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum, color=CrapomePCT), data=b) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
202 scale_colour_gradient(limits=c(80, 100), low="tan", high="red") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
203 labs(colour="CRAPome Probability \nof Specific Interaction (%)", x="ln(NSAF)") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
204 geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=b)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
205 if(label==TRUE & length(b$NSAF!=0)) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
206 p <- p + geom_text(data=b, aes(label=PreyGene, size=10, vjust=0, hjust=0),colour="black", show_guide=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
207 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
208 return(ggsave(p, width=8,height=4,filename = "bubble_zoom_NSAF.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
209 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
210 if(color != "crapome") {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
211 a <- subset(data, SaintScore>=cutoff, select = c(NSAF,SpecSum, FoldChange, SaintScore, Bait, PreyGene))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
212 p <- qplot(x=log(NSAF), y=log2(FoldChange), data=a, colour=I(color), size=SpecSum) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
213 scale_size(range=c(1,10)) + ggtitle("Filtered on SAINT score") +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
214 geom_point(aes(x=log(NSAF),y=log2(FoldChange), size=SpecSum), colour="black", shape=21, data=a) +
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
215 labs(x="ln(NSAF)")
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
216 if(label==TRUE & length(a$NSAF!=0)) {
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
217 p <- p + geom_text(data=a, aes(label=PreyGene, size=10, vjust=0, hjust=0),colour="black", show_guide=FALSE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
218 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
219 if(length(levels(data$Bait) > 1)) {p <- p + facet_wrap(~Bait, scales="free_y")}
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
220 return(ggsave(p, width=8,height=4,filename = "bubble_zoom_NSAF.png"))
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
221 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
222 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
223 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
224 # Check Saintscore cutoff and stop program if not between 0 and 1
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
225 ###################################################################################################
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
226 cutoff_check <- function(cutoff){
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
227 if( any(cutoff < 0 | cutoff > 1) ) stop('SAINT score cutoff not between 0 and 1. Please correct and try again')
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
228 }
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
229
4
8eb1dd926f6e Uploaded
bornea
parents: 3
diff changeset
230 args <- commandArgs(trailingOnly = TRUE)
8eb1dd926f6e Uploaded
bornea
parents: 3
diff changeset
231 main(args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9])
3
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
232
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
233 #main("test_list.txt", "preytest.txt", crapome="craptest.txt", color="crapome", label=TRUE)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
234 #main("Crizo_list.txt", "prey_cr.txt", crapome = "crizo_crap.txt", color="crapome", label=TRUE, cutoff=0.7)
463a0ca33d7f Uploaded
bornea
parents:
diff changeset
235 #main("test_list.txt", "preytest.txt", crapome=FALSE, color="magenta", label=FALSE, cutoff=1.1)