annotate bubbles_v9_NSAF_natural_log.R @ 16:54102aee991e draft

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