-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCVDSBG_complex.Rmd
158 lines (136 loc) · 5.17 KB
/
CVDSBG_complex.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
title: "Untitled"
output: html_document
---
```{r complex urine}
rm(list=ls())
library(dplyr)
promart <- read.csv("urine_protein_matrix_20200506.csv", stringsAsFactors = F)
protein_n <- read.csv("urine_protein_matrix_protein_name.csv", stringsAsFactors = F)
complex_table <- read.csv("allComplexes_human.csv", stringsAsFactors = F)
####### find complex #############
df_complex <- vector()
for(i in 1:nrow(protein_n)){
protSel <- protein_n$Uniport_ID[i]
selInd <- vector()
for(j in 1:length(complex_table)){
# protMat_deSel<-protMat_de[ which(grepl(protSel[i],row.names(protMat_de))),]
selInd<-c(selInd,which(grepl(protSel[j],complex_table$subunits.UniProt.IDs.)))
}
if (length(selInd) > 0){
complex_table_deSel <- complex_table[selInd,]
df_complex <- rbind(df_complex, complex_table_deSel)
print(i)
}
}
df_complex <- distinct(df_complex)
######## calculate ratio ########
protRatioNames<-vector();m=1
for(i in 1:nrow(df_complex)){
prot_sp <- unlist(strsplit(df_complex$subunits.UniProt.IDs.[i],";"))
if (length(prot_sp) > 1) {
comb<-combn(1:length(prot_sp),2)
for(j in 1:ncol(comb)) {
protRatioNames[m]<-paste(prot_sp[comb[,j]],collapse = "/")
m<-m+1
}
}
print(i)
}
protRatioNames <- unique(protRatioNames)
row.names(promart) <- promart$ID
promart_ma <- promart[,-1:-8]
promart_ma_t <- data.frame(t(promart_ma))
promart_ma_tNoNA<-promart_ma_t
promart_ma_tNoNA[promart_ma_tNoNA==0]<-NA
promart_ma_tNoNA[is.na(promart_ma_tNoNA)]<-min(promart_ma_tNoNA, na.rm=T)
protRatioMat<-data.frame(matrix(0,nrow=length(protRatioNames),ncol=ncol(promart_ma_tNoNA)))
row.names(protRatioMat)<-protRatioNames
colnames(protRatioMat)<-colnames(promart_ma_tNoNA)
protRatioMat_1 <- vector()
for(i in 1:nrow(protRatioMat)){
selProt<-unlist(strsplit(row.names(protRatioMat)[i],"/"))
selInd<-vector()
for(m in 1:length(selProt)){
# protMat_deSel<-protMat_de[ which(grepl(protSel[i],row.names(protMat_de))),]
selInd<-c(selInd,which(grepl(selProt[m],row.names(promart_ma_tNoNA))))
}
protRatioMat_deSel <- promart_ma_tNoNA[selInd,]
protMat_deSel_2_fi <- log2(protRatioMat_deSel[1,])-log2(protRatioMat_deSel[2,])
protRatioMat_1[i]<-paste(protMat_deSel_2_fi,collapse = ";") #sum by row
print(i)
}
for(i in 11779:nrow(protRatioMat)){
protRatioMat[i,]<-unlist(strsplit(protRatioMat_1[i],";"))
print(i)
}
write.csv(protRatioMat,"protRatioMat.csv",row.names = T)
protRatioMatSel<-protRatioMat[apply((protRatioMat)=="NA",1,sum)!=ncol(protRatioMat),]
write.csv(protRatioMatSel,"protRatioMatSel.csv",row.names = T)
```
```{r complex serum}
rm(list=ls())
library(dplyr)
promart <- read.csv("serum_protein_matrix_20200518.csv", stringsAsFactors = F)
protein_n <- read.csv("serum_protein_matrix_protein_name.csv", stringsAsFactors = F)
complex_table <- read.csv("allComplexes_human.csv", stringsAsFactors = F)
####### find complex #############
df_complex <- vector()
for(i in 1:nrow(protein_n)){
protSel <- protein_n$Uniport_ID[i]
selInd <- vector()
for(j in 1:length(complex_table)){
# protMat_deSel<-protMat_de[ which(grepl(protSel[i],row.names(protMat_de))),]
selInd<-c(selInd,which(grepl(protSel[j],complex_table$subunits.UniProt.IDs.)))
}
if (length(selInd) > 0){
complex_table_deSel <- complex_table[selInd,]
df_complex <- rbind(df_complex, complex_table_deSel)
print(i)
}
}
df_complex <- distinct(df_complex)
######## calculate ratio ########
protRatioNames<-vector();m=1
for(i in 1:nrow(df_complex)){
prot_sp <- unlist(strsplit(df_complex$subunits.UniProt.IDs.[i],";"))
if (length(prot_sp) > 1) {
comb<-combn(1:length(prot_sp),2)
for(j in 1:ncol(comb)) {
protRatioNames[m]<-paste(prot_sp[comb[,j]],collapse = "/")
m<-m+1
}
}
print(i)
}
protRatioNames <- unique(protRatioNames)
row.names(promart) <- promart$ID
promart_ma <- promart[,-1:-8]
promart_ma_t <- data.frame(t(promart_ma))
promart_ma_tNoNA<-promart_ma_t
promart_ma_tNoNA[promart_ma_tNoNA==0]<-NA
promart_ma_tNoNA[is.na(promart_ma_tNoNA)]<-min(promart_ma_tNoNA, na.rm=T)
protRatioMat<-data.frame(matrix(0,nrow=length(protRatioNames),ncol=ncol(promart_ma_tNoNA)))
row.names(protRatioMat)<-protRatioNames
colnames(protRatioMat)<-colnames(promart_ma_tNoNA)
protRatioMat_1 <- vector()
for(i in 1:nrow(protRatioMat)){
selProt<-unlist(strsplit(row.names(protRatioMat)[i],"/"))
selInd<-vector()
for(m in 1:length(selProt)){
# protMat_deSel<-protMat_de[ which(grepl(protSel[i],row.names(protMat_de))),]
selInd<-c(selInd,which(grepl(selProt[m],row.names(promart_ma_tNoNA))))
}
protRatioMat_deSel <- promart_ma_tNoNA[selInd,]
protMat_deSel_2_fi <- log2(protRatioMat_deSel[1,])-log2(protRatioMat_deSel[2,])
protRatioMat_1[i]<-paste(protMat_deSel_2_fi,collapse = ";") #sum by row
print(i)
}
for(i in 1:nrow(protRatioMat)){
protRatioMat[i,]<-unlist(strsplit(protRatioMat_1[i],";"))
print(i)
}
write.csv(protRatioMat,"serum_protRatioMat.csv",row.names = T)
protRatioMatSel<-protRatioMat[apply((protRatioMat)=="NA",1,sum)!=ncol(protRatioMat),]
write.csv(protRatioMatSel,"serum_protRatioMatSel.csv",row.names = T)
```