annotate bubbles_v9_NSAF_natural_log.R @ 11:80cc85d7d6e3 draft

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