annotate all stuff/Difference finder for GalaxyP working.R @ 10:78f16bc92ba6 draft

Uploaded
author jfb
date Fri, 21 Feb 2020 16:37:08 -0500
parents 033dd86d3e0c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
1 #ff you want ONLY FULL MOTIFS, put "YES" here, please use all caps
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
2 FullMotifsOnly_questionmark<-"NO"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
3 #If you want ONLY TRUNCATED MOTIFS, put "YES" here, please use all caps
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
4 TruncatedMotifsOnly_questionmark<-"NO"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
5 #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)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
6 Are_You_Looking_For_Commonality<-"NO"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
7
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
8
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
9 #put the names of your input files here
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
10 FirstSubstrateSet<- read.csv("S1.csv", stringsAsFactors=FALSE,colClasses = "character")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
11 Firstsubbackfreq<- read.csv("SBF1.csv", header=FALSE, stringsAsFactors=FALSE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
12
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
13 SecondSubstrateSet<- read.csv("S2.csv", stringsAsFactors=FALSE,colClasses = "character")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
14 Secondsubbackfreq<- read.csv("SBF2.csv", header=FALSE, stringsAsFactors=FALSE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
15
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
16
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
17 First_unshared_motifs_table<-"1RS.csv"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
18 First_unshared_subbackfreq<-"1RSBF.csv"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
19
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
20 Second_unshared_motifs_table<-"2RS.csv"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
21 Second_unshared_subbackfreq<-"2RSBF.csv"
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
22
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
23 EmptySubHeader<-colnames(FirstSubstrateSet)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
24 EmptySubHeader<-matrix(EmptySubHeader, nrow=1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
25 EmptySBFHeader<-Firstsubbackfreq[,1]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
26
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
27 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
28 #other languages to see if any of them can do it.
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
29 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
30
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
31
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
32 FirstCentralLetters<-FirstSubstrateSet[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
33 SecondCentralLetters<-SecondSubstrateSet[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
34
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
35 FirstEsses<-sapply(FirstCentralLetters, grepl, pattern="S", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
36 FirstTees<-sapply(FirstCentralLetters, grepl, pattern="T", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
37 FirstWys<-sapply(FirstCentralLetters, grepl, pattern="Y", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
38
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
39 SecondEsses<-sapply(SecondCentralLetters, grepl, pattern="S", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
40 SecondTees<-sapply(SecondCentralLetters, grepl, pattern="T", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
41 SecondWys<-sapply(SecondCentralLetters, grepl, pattern="Y", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
42
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
43 FirstCentralLetters<-replace(FirstCentralLetters,FirstEsses,"xS")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
44 FirstCentralLetters<-replace(FirstCentralLetters,FirstTees,"xT")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
45 FirstCentralLetters<-replace(FirstCentralLetters,FirstWys,"xY")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
46
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
47 SecondCentralLetters<-replace(SecondCentralLetters,SecondEsses,"xS")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
48 SecondCentralLetters<-replace(SecondCentralLetters,SecondTees,"xT")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
49 SecondCentralLetters<-replace(SecondCentralLetters,SecondWys,"xY")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
50
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
51 FirstCentralLetters->FirstSubstrateSet[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
52 SecondCentralLetters->SecondSubstrateSet[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
53
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
54 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
55 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
56 # better version of this code written in C: what happens when two kinases share a motif, but they found that motif in two
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
57 # separate proteins thus two separate accession numbers?
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
58 # It should actually output the shared motif and BOTH accession numbers. Right now it does not, it only maps out the second
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
59 # accession number. So that needs to be fixed BUT you need to keep the commonality between a motif and its accession number
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
60 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
61 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
62 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
63 ####################################################################################################################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
64
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
65 #Create the motif sets, deciding wether or not you're looking for truncated or full here
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
66 #full only
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
67
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
68
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
69 ###############################################
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
70 #ALL motifs, full and truncated
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
71
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
72 if (FullMotifsOnly_questionmark!="YES"&&TruncatedMotifsOnly_questionmark!="YES"){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
73 FTLwtmotifs=matrix(,nrow = nrow(FirstSubstrateSet),ncol=1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
74 FTLwtAccessionNumbers=matrix(,nrow = nrow(FirstSubstrateSet),ncol=1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
75
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
76 for (i in 1:nrow(FirstSubstrateSet)){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
77 FTLwtletters<-FirstSubstrateSet[i,4:18]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
78 FTLwtletters<-FTLwtletters[FTLwtletters !="XXXXX"]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
79 FTLwtletters<-paste(FTLwtletters, sep="", collapse="")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
80 leftspaces<-c()
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
81 rightspaces<-c()
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
82
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
83 YYYmotif <- unlist(strsplit(FTLwtletters, split = ""))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
84 YYYposition <- match(x = "x", table = YYYmotif)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
85 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
86 #just 3 letters to the left of x
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
87
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
88 YYYLettersToTheLeft <- YYYposition - 1
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
89 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
90 #just 1 spot to the right of Y so LettersToTheRight<-1 because 5-3-1=1
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
91 YYYLettersToTheRight <- length(YYYmotif) - YYYposition - 1
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
92 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
93 #variable the user puts in is
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
94
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
95
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
96 if (YYYLettersToTheLeft < 7 | YYYLettersToTheRight < 7) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
97 leftspaces<-rep(" ",times=(7-YYYLettersToTheLeft))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
98 rightspaces<-rep(" ",times=7-(YYYLettersToTheRight))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
99 #add blank spaces if the motif has less than 4 letters to the left/right
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
100 motif<-c(leftspaces,YYYmotif,rightspaces)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
101 #save that motif, which is the Y and +/- 4 amino acids, including truncation
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
102 motif<-motif[!motif %in% "x"]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
103 motif<-paste(motif, sep="", collapse="")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
104 FTLwtletters<-motif
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
105 FTLwtmotifs[i,1]<-FTLwtletters
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
106 FTLwtAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
107 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
108
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
109 if(YYYLettersToTheLeft>6 && YYYLettersToTheRight>6){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
110 motif<-YYYmotif
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
111 #add blank spaces if the motif has less than 4 letters to the left/right
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
112 motif<-c(leftspaces,YYYmotif,rightspaces)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
113 #save that motif, which is the Y and +/- 4 amino acids, including truncation
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
114 motif<-motif[!motif %in% "x"]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
115 motif<-paste(motif, sep="", collapse="")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
116 FTLwtletters<-motif
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
117 FTLwtmotifs[i,1]<-FTLwtletters
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
118 FTLwtAccessionNumbers[i,1]<-FirstSubstrateSet[i,3]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
119
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
120
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
121 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
122
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
123 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
124
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
125 D835Ymotifs=matrix(,nrow = nrow(SecondSubstrateSet),ncol=1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
126 D835YAccessionNumbers<-matrix(,nrow = nrow(SecondSubstrateSet),ncol = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
127
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
128 for (i in 1:nrow(SecondSubstrateSet)){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
129 D835letters<-SecondSubstrateSet[i,4:18]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
130 D835letters<-D835letters[D835letters !="XXXXX"]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
131 D835letters<-paste(D835letters, sep="", collapse="")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
132 leftspaces<-c()
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
133 rightspaces<-c()
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
134
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
135 YYYmotif <- unlist(strsplit(D835letters, split = ""))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
136 YYYposition <- match(x = "x", table = YYYmotif)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
137 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
138 #just 3 letters to the left of x
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
139
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
140 YYYLettersToTheLeft <- YYYposition - 1
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
141 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
142 #just 1 spot to the right of Y so LettersToTheRight<-1 because 5-3-1=1
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
143 YYYLettersToTheRight <- length(YYYmotif) - YYYposition - 1
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
144 #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
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
145 #variable the user puts in is
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
146 if (YYYLettersToTheLeft < 7 | YYYLettersToTheRight < 7) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
147 leftspaces<-rep(" ",times=(7-YYYLettersToTheLeft))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
148 rightspaces<-rep(" ",times=7-(YYYLettersToTheRight))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
149 #add blank spaces if the motif has less than 4 letters to the left/right
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
150 motif<-c(leftspaces,YYYmotif,rightspaces)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
151 #save that motif, which is the Y and +/- 4 amino acids, including truncation
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
152 motif<-motif[!motif %in% "x"]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
153 motif<-paste(motif, sep="", collapse="")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
154 D835letters<-motif
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
155 D835Ymotifs[i,1]<-D835letters
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
156 D835YAccessionNumbers[i,1]<-SecondSubstrateSet[i,3]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
157 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
158
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
159 if(YYYLettersToTheLeft>6 && YYYLettersToTheRight>6){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
160 motif<-YYYmotif
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
161 #add blank spaces if the motif has less than 4 letters to the left/right
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
162 motif<-c(leftspaces,YYYmotif,rightspaces)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
163 #save that motif, which is the Y and +/- 4 amino acids, including truncation
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
164 motif<-motif[!motif %in% "x"]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
165 motif<-paste(motif, sep="", collapse="")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
166 D835letters<-motif
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
167 D835Ymotifs[i,1]<-D835letters
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
168 D835YAccessionNumbers[i,1]<-SecondSubstrateSet[i,3]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
169 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
170 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
171
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
172 names(FTLwtmotifs)<-FTLwtAccessionNumbers
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
173 names(D835Ymotifs)<-D835YAccessionNumbers
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
174
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
175 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
176
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
177
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
178 FTLwtmotifsFINAL<-FTLwtmotifs[!FTLwtmotifs %in% D835Ymotifs]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
179 FTLwtmotifsFINAL<-FTLwtmotifsFINAL[!duplicated(FTLwtmotifsFINAL)]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
180
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
181 D835YmotifsFINAL<-D835Ymotifs[!D835Ymotifs %in% FTLwtmotifs]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
182 D835YmotifsFINAL<-D835YmotifsFINAL[!duplicated(D835YmotifsFINAL)]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
183
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
184
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
185 columnalheader<-c(rep(NA,36))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
186 FTLFinalMatrix<-matrix(data =columnalheader,nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
187
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
188 FLTheader<-c("Substrate","Species","Reference","-7","-6","-5","-4","-3","-2","-1","0","1","2","3","4","5","6","7","Phosphite")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
189
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
190 if (length(FTLwtmotifsFINAL)>0){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
191 for (k in 1:length(FTLwtmotifsFINAL)) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
192 AN<-00000
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
193 #I don't remember why, but I felt it necessary to destroy the accession number multiple times to ensure it is
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
194 #destroyed immediately after use
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
195 for (m in 1:ncol(Firstsubbackfreq)) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
196 AN <- as.character(Firstsubbackfreq[1, m])
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
197 if (grepl(pattern = AN,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
198 x = names(FTLwtmotifsFINAL[k]),
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
199 fixed = TRUE) == TRUE) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
200 outputmatrix <- as.character(Firstsubbackfreq[, m])
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
201 outputmatrix <- matrix(outputmatrix, nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
202 #with that accession number, find a match in the subbackfreq file and save it here
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
203 FTLFinalMatrix<-rbind(FTLFinalMatrix,outputmatrix)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
204 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
205 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
206 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
207 FTLFinalMatrix<-FTLFinalMatrix[!duplicated(FTLFinalMatrix),]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
208 FTLFinalMatrix<-FTLFinalMatrix[2:nrow(FTLFinalMatrix),]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
209
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
210
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
211 FTLoutputmatrix<-matrix(data=c(FTLwtmotifsFINAL,names(FTLwtmotifsFINAL)),ncol = 2)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
212 # FLTheader<-unlist(FLTheader)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
213 lefthandFLT<-matrix(data = rep(NA,times=2*nrow(FTLoutputmatrix)),nrow=nrow(FTLoutputmatrix))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
214 righthandFLT<-matrix(data = rep(NA,times=1*nrow(FTLoutputmatrix)),nrow=nrow(FTLoutputmatrix))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
215 FLTaccessionset<-FTLoutputmatrix[,2]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
216 FTLmeat<-sapply(FTLoutputmatrix[,1], strsplit, "")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
217 FTLmeat<-sapply(FTLmeat, unlist)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
218 colnames(FTLmeat)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
219 FTLmeat<-t(FTLmeat)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
220
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
221 FTLoutputmatrix2<-cbind(lefthandFLT,FLTaccessionset,FTLmeat,righthandFLT)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
222 colnames(FTLoutputmatrix2)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
223 rownames(FTLoutputmatrix2)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
224 colnames(FLTheader)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
225 rownames(FLTheader)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
226
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
227
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
228 FirstCentralLettersAGAIN<-FTLoutputmatrix2[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
229
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
230 FirstEsses<-sapply(FirstCentralLettersAGAIN, grepl, pattern="S", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
231 FirstTees<-sapply(FirstCentralLettersAGAIN, grepl, pattern="T", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
232 FirstWys<-sapply(FirstCentralLettersAGAIN, grepl, pattern="Y", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
233
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
234 FirstCentralLettersAGAIN<-replace(FirstCentralLettersAGAIN,FirstEsses,"xS")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
235 FirstCentralLettersAGAIN<-replace(FirstCentralLettersAGAIN,FirstTees,"xT")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
236 FirstCentralLettersAGAIN<-replace(FirstCentralLettersAGAIN,FirstWys,"xY")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
237
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
238 FirstCentralLettersAGAIN->FTLoutputmatrix2[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
239
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
240 FTLoutputmatrix2<-rbind(FLTheader,FTLoutputmatrix2)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
241
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
242 write.table(x=FTLoutputmatrix2,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
243 file=First_unshared_motifs_table,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
244 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
245 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
246
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
247 columnalheader<-c("Accession Numbers",as.character(Firstsubbackfreq[1:35,1]))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
248 columnalheader<-matrix(columnalheader,nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
249 write.table(x=columnalheader,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
250 file=First_unshared_subbackfreq,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
251 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
252 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
253
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
254 write.table(x=FTLFinalMatrix,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
255 file=First_unshared_subbackfreq,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
256 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
257 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
258 } else{
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
259 FTLFinalMatrix<-columnalheader
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
260 write.table(x=EmptySubHeader,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
261 file=First_unshared_motifs_table,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
262 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
263 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
264
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
265 columnalheader<-c("Accession Numbers",as.character(Firstsubbackfreq[1:35,1]))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
266 columnalheader<-matrix(columnalheader,nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
267 write.table(x=columnalheader,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
268 file=First_unshared_subbackfreq,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
269 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
270 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
271 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
272
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
273
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
274 columnalheader<-c(rep(NA,36))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
275 D835YFinalMatrix<-matrix(data =columnalheader,nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
276
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
277 if (length(D835YmotifsFINAL)>0){
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
278 for (k in 1:length(D835YmotifsFINAL)) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
279 #I don't remember why, but I felt it necessary to destroy the accession number multiple times to ensure it is
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
280 #destroyed immediately after use
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
281 for (m in 1:ncol(Secondsubbackfreq)) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
282 AN <- as.character(Secondsubbackfreq[1, m])
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
283 if (grepl(pattern = AN,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
284 x = names(D835YmotifsFINAL[k]),
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
285 fixed = TRUE) == TRUE) {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
286 outputmatrix <- as.character(Secondsubbackfreq[, m])
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
287 outputmatrix <- matrix(outputmatrix, nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
288 #with that accession number, find a match in the subbackfreq file and save it here
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
289 D835YFinalMatrix<-rbind(D835YFinalMatrix,outputmatrix)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
290 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
291 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
292 }
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
293 D835YFinalMatrix<-D835YFinalMatrix[!duplicated(D835YFinalMatrix),]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
294 D835YFinalMatrix<-D835YFinalMatrix[2:nrow(D835YFinalMatrix),]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
295
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
296 D835Youtputmatrix<-matrix(data=c(D835YmotifsFINAL,names(D835YmotifsFINAL)),ncol = 2)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
297
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
298 D835Yheader<-c("Substrate","Species","Reference","-7","-6","-5","-4","-3","-2","-1","0","1","2","3","4","5","6","7","Phosphite")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
299 # D835Yheader<-unlist(D835Yheader)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
300 lefthandD835<-matrix(data = rep(NA,times=2*nrow(D835Youtputmatrix)),nrow=nrow(D835Youtputmatrix))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
301 righthandD835<-matrix(data = rep(NA,times=1*nrow(D835Youtputmatrix)),nrow=nrow(D835Youtputmatrix))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
302 D835Yaset<-D835Youtputmatrix[,2]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
303 D835meat<-sapply(D835Youtputmatrix[,1], strsplit, "")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
304 D835meat<-sapply(D835meat, unlist)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
305 colnames(D835meat)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
306 D835meat<-t(D835meat)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
307
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
308 D835Youtputmatrix2<-cbind(lefthandD835,D835Yaset,D835meat,righthandD835)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
309 colnames(D835Youtputmatrix2)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
310 rownames(D835Youtputmatrix2)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
311 colnames(D835Yheader)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
312 rownames(D835Yheader)<-NULL
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
313
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
314
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
315 SecondCentralLettersAGAIN<-D835Youtputmatrix2[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
316
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
317 SecondEsses<-sapply(SecondCentralLettersAGAIN, grepl, pattern="S", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
318 SecondTees<-sapply(SecondCentralLettersAGAIN, grepl, pattern="T", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
319 SecondWys<-sapply(SecondCentralLettersAGAIN, grepl, pattern="Y", ignore.case=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
320
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
321 SecondCentralLettersAGAIN<-replace(SecondCentralLettersAGAIN,SecondEsses,"xS")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
322 SecondCentralLettersAGAIN<-replace(SecondCentralLettersAGAIN,SecondTees,"xT")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
323 SecondCentralLettersAGAIN<-replace(SecondCentralLettersAGAIN,SecondWys,"xY")
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
324
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
325 SecondCentralLettersAGAIN->D835Youtputmatrix2[,11]
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
326
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
327 D835Youtputmatrix2<-rbind(D835Yheader,D835Youtputmatrix2)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
328
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
329 write.table(x=D835Youtputmatrix2,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
330 file=Second_unshared_motifs_table,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
331 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
332 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
333
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
334 columnalheader<-c("Accession Numbers",as.character(Firstsubbackfreq[1:35,1]))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
335 columnalheader<-matrix(columnalheader,nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
336 write.table(x=columnalheader,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
337 file=Second_unshared_subbackfreq,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
338 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
339 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
340
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
341 write.table(x=D835YFinalMatrix,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
342 file=Second_unshared_subbackfreq,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
343 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
344 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
345 } else {
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
346 D835YFinalMatrix<- columnalheader
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
347 write.table(x=EmptySubHeader,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
348 file=Second_unshared_motifs_table,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
349 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
350 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
351
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
352 columnalheader<-c("Accession Numbers",as.character(Firstsubbackfreq[1:35,1]))
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
353 columnalheader<-matrix(columnalheader,nrow = 1)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
354 write.table(x=columnalheader,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
355 file=Second_unshared_subbackfreq,
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
356 quote=FALSE, sep=",",
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
357 row.names=FALSE,col.names = FALSE, na="", append=TRUE)
033dd86d3e0c Uploaded
jfb
parents:
diff changeset
358 }