2
|
1 FirstSubstrateSet<- read.csv("input1.csv", stringsAsFactors=FALSE, header = FALSE)
|
|
2 Firstsubbackfreq<- read.csv("input2.csv", header=FALSE, stringsAsFactors=FALSE)
|
|
3 SubstrateHeader<-FirstSubstrateSet[1,]
|
|
4 FirstSubstrateSet<- FirstSubstrateSet[2:nrow(FirstSubstrateSet),]
|
|
5
|
|
6 SecondSubstrateSet<- read.csv("input3.csv", stringsAsFactors=FALSE, header = FALSE)
|
|
7 Secondsubbackfreq<- read.csv("input4.csv", header=FALSE, stringsAsFactors=FALSE)
|
|
8 SecondSubstrateSet<- SecondSubstrateSet[2:nrow(SecondSubstrateSet),]
|
|
9
|
|
10
|
|
11 ThirdSubstrateSet<- read.csv("input5.csv", stringsAsFactors=FALSE, header = FALSE)
|
|
12 Thirdsubbackfreq<- read.csv("input6.csv", header=FALSE, stringsAsFactors=FALSE)
|
|
13 ThirdSubstrateSet<- ThirdSubstrateSet[2:nrow(ThirdSubstrateSet),]
|
|
14
|
|
15
|
|
16 #ff you want ONLY FULL MOTIFS, put "YES" here, please use all caps
|
|
17 FullMotifsOnly_questionmark<-"NO"
|
|
18 #If you want ONLY TRUNCATED MOTIFS, put "YES" here, please use all caps
|
|
19 TruncatedMotifsOnly_questionmark<-"NO"
|
|
20 #if you want to find the overlap, put a "YES" here (all caps), if you want to find the non-overlap, put "NO" (all caps)
|
|
21 Are_You_Looking_For_Commonality<-"YES"
|
|
22
|
|
23
|
|
24 #then put the names of your output files here
|
|
25 Shared_motifs_table<-"sharedmotifs.csv"
|
|
26 Shared_subbackfreq_table<-"sharedSBF.csv"
|
|
27
|
|
28 # Shared_motifs_table<-"Shared motifs 7-27-17.csv"
|
|
29 # Shared_subbackfreq_table<-"SubstrateBackgrounFrequency-for-shared-motifs 4 7-27-17.csv"
|
|
30
|
|
31 First_unshared_motifs_table<-"R1 substrates.csv"
|
|
32 First_unshared_subbackfreq<-"R1 SBF.csv"
|
|
33
|
|
34 Second_unshared_motifs_table<-"R2 subs.csv"
|
|
35 Second_unshared_subbackfreq<-"R2 SBf.csv"
|
|
36
|
|
37 Third_unshared_motifs_table<-"R3 subs.csv"
|
|
38 Third_unshared_subbackfreq<-"R3 SBF.csv"
|
|
39
|
|
40 #final note, this code is going to be unworkable if you want to make a Venn diagram of more than 3 circles. I think I'll poke around
|
|
41 #other languages to see if any of them can do it.
|
|
42 ####################################################################################################################################
|
|
43
|
|
44
|
|
45
|
|
46
|
|
47
|
|
48 FirstxY<-rep("xY",times=nrow(FirstSubstrateSet))
|
|
49 FirstSubstrateSet[,11]<-FirstxY
|
|
50
|
|
51 SecondxY<-rep("xY",times=nrow(SecondSubstrateSet))
|
|
52 SecondSubstrateSet[,11]<-SecondxY
|
|
53
|
|
54 ThirdxY<-rep("xY",times=nrow(ThirdSubstrateSet))
|
|
55 ThirdSubstrateSet[,11]<-ThirdxY
|
|
56
|
|
57
|
|
58
|
|
59
|
|
60
|
|
61
|
|
62
|
|
63
|
|
64
|
|
65
|
|
66
|
|
67 ####################################################################################################################################
|
|
68 ####################################################################################################################################
|
|
69 # better version of this code written in C: what happens when two kinases share a motif, but they found that motif in two
|
|
70 # separate proteins thus two separate accession numbers?
|
|
71 # It should actually output the shared motif and BOTH accession numbers. Right now it does not, it only maps out the second
|
|
72 # accession number. So that needs to be fixed BUT you need to keep the commonality between a motif and its accession number
|
|
73 ####################################################################################################################################
|
|
74 ####################################################################################################################################
|
|
75 ####################################################################################################################################
|
|
76 ####################################################################################################################################
|
|
77
|
|
78 #Create the motif sets, deciding wether or not you're looking for truncated or full here
|
|
79 #full only
|
|
80 if (Are_You_Looking_For_Commonality=="YES"){
|
|
81
|
|
82
|
|
83 ###############################################
|
|
84 #ALL motifs, full and truncated
|
|
85
|
|
86 FTLwtmotifs=matrix(,nrow = nrow(FirstSubstrateSet),ncol=1)
|
|
87 FTLwtAccessionNumbers=matrix(data = Firstsubbackfreq[1,],ncol=1)
|
|
88
|
|
89 for (i in 1:nrow(FirstSubstrateSet)){
|
|
90 FTLwtletters<-FirstSubstrateSet[i,4:18]
|
|
91 FTLwtletters<-FTLwtletters[FTLwtletters !="XXXXX"]
|
|
92 FTLwtletters<-paste(FTLwtletters, sep="", collapse="")
|
|
93 leftspaces<-c()
|
|
94 rightspaces<-c()
|
|
95
|
|
96 YYYmotif <- unlist(strsplit(FTLwtletters, split = ""))
|
|
97 YYYposition <- match(x = "x", table = YYYmotif)
|
|
98 #position itself tells me how much is to the left of that X by what it's number is. x at position 4 tells me that there are
|
|
99 #just 3 letters to the left of x
|
|
100
|
|
101 YYYLettersToTheLeft <- YYYposition - 1
|
|
102 #how many letters to the right SHOULD just be length(motif)-position-1 if it's 5 long and x is at 3 then Y is at 4 and there is
|
|
103 #just 1 spot to the right of Y so LettersToTheRight<-1 because 5-3-1=1
|
|
104 YYYLettersToTheRight <- length(YYYmotif) - YYYposition - 1
|
|
105 #then sanity check, we're currently looking only at +/-4, but this spot allows for up to +/- 7 as well, just depends on what the
|
|
106 #variable the user puts in is
|
|
107
|
|
108
|
|
109 if (YYYLettersToTheLeft < 7 | YYYLettersToTheRight < 7) {
|
|
110 leftspaces<-rep(" ",times=(7-YYYLettersToTheLeft))
|
|
111 rightspaces<-rep(" ",times=7-(YYYLettersToTheRight))
|
|
112 #add blank spaces if the motif has less than 4 letters to the left/right
|
|
113 motif<-c(leftspaces,YYYmotif,rightspaces)
|
|
114 #save that motif, which is the Y and +/- 4 amino acids, including truncation
|
|
115 motif<-motif[!motif %in% "x"]
|
|
116 motif<-paste(motif, sep="", collapse="")
|
|
117 FTLwtletters<-motif
|
|
118 FTLwtmotifs[i,1]<-FTLwtletters
|
|
119 # FTLwtAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
|
|
120 }
|
|
121
|
|
122 if(YYYLettersToTheLeft>6 && YYYLettersToTheRight>6){
|
|
123 motif<-YYYmotif
|
|
124 #add blank spaces if the motif has less than 4 letters to the left/right
|
|
125 motif<-c(leftspaces,YYYmotif,rightspaces)
|
|
126 #save that motif, which is the Y and +/- 4 amino acids, including truncation
|
|
127 motif<-motif[!motif %in% "x"]
|
|
128 motif<-paste(motif, sep="", collapse="")
|
|
129 FTLwtletters<-motif
|
|
130 FTLwtmotifs[i,1]<-FTLwtletters
|
|
131 # FTLwtAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
|
|
132
|
|
133
|
|
134 }
|
|
135
|
|
136 }
|
|
137
|
|
138 D835Ymotifs=matrix(,nrow = nrow(SecondSubstrateSet),ncol=1)
|
|
139 D835YAccessionNumbers<-matrix(data = Secondsubbackfreq[1,],ncol = 1)
|
|
140
|
|
141 for (i in 1:nrow(SecondSubstrateSet)){
|
|
142 D835letters<-SecondSubstrateSet[i,4:18]
|
|
143 D835letters<-D835letters[D835letters !="XXXXX"]
|
|
144 D835letters<-paste(D835letters, sep="", collapse="")
|
|
145 leftspaces<-c()
|
|
146 rightspaces<-c()
|
|
147
|
|
148 YYYmotif <- unlist(strsplit(D835letters, split = ""))
|
|
149 YYYposition <- match(x = "x", table = YYYmotif)
|
|
150 #position itself tells me how much is to the left of that X by what it's number is. x at position 4 tells me that there are
|
|
151 #just 3 letters to the left of x
|
|
152
|
|
153 YYYLettersToTheLeft <- YYYposition - 1
|
|
154 #how many letters to the right SHOULD just be length(motif)-position-1 if it's 5 long and x is at 3 then Y is at 4 and there is
|
|
155 #just 1 spot to the right of Y so LettersToTheRight<-1 because 5-3-1=1
|
|
156 YYYLettersToTheRight <- length(YYYmotif) - YYYposition - 1
|
|
157 #then sanity check, we're currently looking only at +/-4, but this spot allows for up to +/- 7 as well, just depends on what the
|
|
158 #variable the user puts in is
|
|
159 if (YYYLettersToTheLeft < 7 | YYYLettersToTheRight < 7) {
|
|
160 leftspaces<-rep(" ",times=(7-YYYLettersToTheLeft))
|
|
161 rightspaces<-rep(" ",times=7-(YYYLettersToTheRight))
|
|
162 #add blank spaces if the motif has less than 4 letters to the left/right
|
|
163 motif<-c(leftspaces,YYYmotif,rightspaces)
|
|
164 #save that motif, which is the Y and +/- 4 amino acids, including truncation
|
|
165 motif<-motif[!motif %in% "x"]
|
|
166 motif<-paste(motif, sep="", collapse="")
|
|
167 D835letters<-motif
|
|
168 D835Ymotifs[i,1]<-D835letters
|
|
169 D835YAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
|
|
170 }
|
|
171
|
|
172 if(YYYLettersToTheLeft>6 && YYYLettersToTheRight>6){
|
|
173 motif<-YYYmotif
|
|
174 #add blank spaces if the motif has less than 4 letters to the left/right
|
|
175 motif<-c(leftspaces,YYYmotif,rightspaces)
|
|
176 #save that motif, which is the Y and +/- 4 amino acids, including truncation
|
|
177 motif<-motif[!motif %in% "x"]
|
|
178 motif<-paste(motif, sep="", collapse="")
|
|
179 D835letters<-motif
|
|
180 D835Ymotifs[i,1]<-D835letters
|
|
181 D835YAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
|
|
182 }
|
|
183 }
|
|
184
|
|
185
|
|
186 ITDmotifs=matrix(,nrow = nrow(ThirdSubstrateSet),ncol=1)
|
|
187 ITDAccessionNumbers<-matrix(data = Thirdsubbackfreq[1,],ncol = 1)
|
|
188
|
|
189 for (i in 1:nrow(ThirdSubstrateSet)){
|
|
190 ITDletters<-ThirdSubstrateSet[i,4:18]
|
|
191 ITDletters<-ITDletters[ITDletters !="XXXXX"]
|
|
192 ITDletters<-paste(ITDletters, sep="", collapse="")
|
|
193 YYYmotif <- unlist(strsplit(ITDletters, split = ""))
|
|
194 leftspaces<-c()
|
|
195 rightspaces<-c()
|
|
196 YYYposition <- match(x = "x", table = YYYmotif)
|
|
197 #position itself tells me how much is to the left of that X by what it's number is. x at position 4 tells me that there are
|
|
198 #just 3 letters to the left of x
|
|
199
|
|
200 YYYLettersToTheLeft <- YYYposition - 1
|
|
201 #how many letters to the right SHOULD just be length(motif)-position-1 if it's 5 long and x is at 3 then Y is at 4 and there is
|
|
202 #just 1 spot to the right of Y so LettersToTheRight<-1 because 5-3-1=1
|
|
203 YYYLettersToTheRight <- length(YYYmotif) - YYYposition - 1
|
|
204 #then sanity check, we're currently looking only at +/-4, but this spot allows for up to +/- 7 as well, just depends on what the
|
|
205 #variable the user puts in is
|
|
206 if (YYYLettersToTheLeft < 7 | YYYLettersToTheRight < 7) {
|
|
207 leftspaces<-rep(" ",times=(7-YYYLettersToTheLeft))
|
|
208 rightspaces<-rep(" ",times=7-(YYYLettersToTheRight))
|
|
209 #add blank spaces if the motif has less than 4 letters to the left/right
|
|
210 motif<-c(leftspaces,YYYmotif,rightspaces)
|
|
211 #save that motif, which is the Y and +/- 4 amino acids, including truncation
|
|
212 motif<-motif[!motif %in% "x"]
|
|
213 motif<-paste(motif, sep="", collapse="")
|
|
214 ITDletters<-motif
|
|
215 ITDmotifs[i,1]<-ITDletters
|
|
216 ITDAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
|
|
217 }
|
|
218
|
|
219 if(YYYLettersToTheLeft>6 && YYYLettersToTheRight>6){
|
|
220 motif<-YYYmotif
|
|
221 #add blank spaces if the motif has less than 4 letters to the left/right
|
|
222 motif<-c(leftspaces,YYYmotif,rightspaces)
|
|
223 #save that motif, which is the Y and +/- 4 amino acids, including truncation
|
|
224 motif<-motif[!motif %in% "x"]
|
|
225 motif<-paste(motif, sep="", collapse="")
|
|
226 ITDletters<-motif
|
|
227 ITDmotifs[i,1]<-ITDletters
|
|
228 ITDAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
|
|
229 }
|
|
230 }
|
|
231
|
|
232 #############################################################################################################################
|
|
233 #############################################################################################################################
|
|
234 #############################################################################################################################
|
|
235 #############################################################################################################################
|
|
236 #############################################################################################################################
|
|
237
|
|
238 #now look for either commonality or difference. Actually could you look for both...
|
|
239
|
|
240 if (Are_You_Looking_For_Commonality=="YES"){
|
|
241
|
|
242 columnalheader<-c(as.character(Thirdsubbackfreq[1:36,1]))
|
|
243 columnalheader<-matrix(columnalheader,nrow = 1)
|
|
244
|
|
245 SubstrateOverlap1<-intersect(D835Ymotifs,ITDmotifs)
|
|
246 SubstrateOverlap1<-as.matrix(SubstrateOverlap1)
|
|
247
|
|
248
|
|
249 columnalheader<-c(rep(NA,36))
|
|
250 FinalMatrix<-matrix(data =columnalheader,ncol = 1)
|
|
251
|
|
252 SubstrateOverlapFINAL<-intersect(FTLwtmotifs,SubstrateOverlap1)
|
|
253 AccessionOverlap1<-intersect(D835YAccessionNumbers,ITDAccessionNumbers)
|
|
254 AccessionOverlapFinal<-intersect(AccessionOverlap1,FTLwtAccessionNumbers)
|
|
255 AccessionOverlapFinal<-unlist(AccessionOverlapFinal)
|
|
256
|
|
257 for (x in 1:length(AccessionOverlapFinal)) {
|
|
258 for (y in 1:ncol(Firstsubbackfreq)) {
|
|
259 Acc<-AccessionOverlapFinal[x]
|
|
260 SBF<-Firstsubbackfreq[1,y]
|
|
261 if(Acc==SBF){
|
|
262 FinalMatrix<-cbind(FinalMatrix,Firstsubbackfreq[,y])
|
|
263 }
|
|
264 }
|
|
265 }
|
|
266 FinalMatrix<-FinalMatrix[,2:ncol(FinalMatrix)]
|
|
267 Outputmatrix<-cbind(Firstsubbackfreq[,1],FinalMatrix)
|
|
268 write.table(x=Outputmatrix,file = Shared_subbackfreq_table,quote = FALSE,sep = ",",row.names = FALSE,col.names = FALSE,na="")
|
|
269
|
|
270 SubstrateMatrix<-SubstrateHeader
|
|
271 if(ncol(SubstrateMatrix)>18){
|
|
272 SubstrateMatrix<-SubstrateMatrix[,1:18]
|
|
273 }
|
|
274
|
|
275 for (z in 1:length(SubstrateOverlapFINAL)) {
|
|
276 motif<-SubstrateOverlapFINAL[z]
|
|
277 newmotif<-unlist(strsplit(motif,split = ""))
|
|
278
|
|
279 Addition<-""
|
|
280 outputmotif<-c(Addition,Addition,Addition,newmotif)
|
|
281 SubstrateMatrix<-rbind(SubstrateMatrix,outputmotif)
|
|
282 }
|
|
283 write.table(x=SubstrateMatrix,file = Shared_motifs_table,quote = FALSE,sep = ",",row.names = FALSE,col.names = FALSE,na="")
|
|
284 }
|
|
285 } |