annotate C and D finder/commonality-working feb 21 20.R @ 2:a20e7cc7e0c9 draft

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