-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMismatchAnalysis.R
More file actions
152 lines (128 loc) · 5.9 KB
/
MismatchAnalysis.R
File metadata and controls
152 lines (128 loc) · 5.9 KB
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
#! /usr/bin/env Rscript
rm(list=ls())
setwd("/ufrc/renne/sunantha.s/research/CLASH/Scripts")
library(splitstackshape)
library(dplyr)
library(data.table)
digitsum <- function(x) sum(floor(x / 10^(0:(nchar(x) - 1))) %% 10)
options(scipen = 999)
INDIR = "../HybVienna/"
OUTDIR= "../SeedMatch/"
files <- list.files(path = INDIR ,pattern = "\\.csv$")
for (file in files) {
Type <- list()
temp <- read.csv(paste0(INDIR,file), stringsAsFactors = F)
miR_Diagram <- temp$miR_Diagram
miR_Diagram <- gsub("\\(", "1", miR_Diagram)
miR_Diagram <- gsub("\\)", "1", miR_Diagram)
miR_Diagram <- gsub("\\.", "0", miR_Diagram)
for (i in 1:length(miR_Diagram)){
if (nchar(miR_Diagram[i]) > 7) {
p1 <- as.numeric(substr(miR_Diagram[i],2,2))
p2 <- as.numeric(substr(miR_Diagram[i],3,3))
p3 <- as.numeric(substr(miR_Diagram[i],4,4))
p4 <- as.numeric(substr(miR_Diagram[i],5,5))
p5 <- as.numeric(substr(miR_Diagram[i],6,6))
p6 <- as.numeric(substr(miR_Diagram[i],7,7))
p7 <- as.numeric(substr(miR_Diagram[i],8,8))
if (sum(p1,p2,p3,p4,p5,p6,p7) == 7) {Type[i] <- "seed_7"
} else if (sum(p1,p2,p3,p4,p5,p6) == 6) {Type[i] <- "seed_6"
} else if (sum(p1,p2,p3,p4,p5,p6,p7) == 6) {Type[i] <- "seed_7m1"
} else if (sum(p1,p2,p3,p4,p5,p6,p7) == 5) {Type[i] <- "seed_7m2"
} else {Type[i] <- "other"}
}
else {Type[i] <- "seed_truncated"}
}
temp$Seed_Type <- unlist(Type)
write.csv(temp,paste0(OUTDIR,file), row.names = F)
}
files <- list.files(path = OUTDIR ,pattern = "\\.csv$")
for (file in files) {
Type_3p <- list()
temp <- read.csv(paste0(OUTDIR,file), stringsAsFactors = F)
miR_Diagram <- temp$miR_Diagram
miR_Diagram <- gsub("\\(", "1", miR_Diagram)
miR_Diagram <- gsub("\\)", "1", miR_Diagram)
miR_Diagram <- gsub("\\.", "0", miR_Diagram)
for (i in 1:length(miR_Diagram)){
if (nchar(miR_Diagram[i]) > 11 && ! is.na(nchar(miR_Diagram[i]))) {
Bind_3p <- digitsum(as.numeric(substr(miR_Diagram[i],11,nchar(miR_Diagram[i]))))
if (Bind_3p == 0) {Type_3p[i] <- "Absent"
} else if (Bind_3p < 5) {Type_3p[i] <- "Weak"
} else if (Bind_3p < 8) {Type_3p[i] <- "Moderate"
} else if (Bind_3p > 7) {Type_3p[i] <- "Strong"
}
}
else {Type_3p[i] <- "miR_truncated"}
}
temp$Bind_3p_Type <- unlist(Type_3p)
write.csv(temp,paste0(OUTDIR,file), row.names = F)
}
####################################################################################################################################
files <- list.files(OUTDIR, pattern = "\\.csv$")
counting <- data.frame(matrix(NA, nrow=length(files), ncol=7))
colnames(counting) <- c("Sample","seed_7", "seed_6", "seed_7m1", "seed_7m2", "other", "seed_truncated")
count =1
for(file in files) {
temp <- read.csv(paste0(OUTDIR,file), stringsAsFactors = F)
counting[count,1] <- file
counting[count,2] <- sum(temp$Seed_Type == "seed_7")
counting[count,3] <- sum(temp$Seed_Type == "seed_6")
counting[count,4] <- sum(temp$Seed_Type == "seed_7m1")
counting[count,5] <- sum(temp$Seed_Type == "seed_7m2")
counting[count,6] <- sum(temp$Seed_Type == "other")
counting[count,7] <- sum(temp$Seed_Type == "seed_truncated")
count= count+1
}
write.csv(counting, paste0(OUTDIR,"Counts/","SeedMatches.csv"), row.names=F)
# Running these counts only on complete diagrams
counting <- data.frame(matrix(NA, nrow=length(files), ncol=7))
colnames(counting) <- c("Sample","seed_7", "seed_6", "seed_7m1", "seed_7m2", "other", "seed_truncated")
count =1
for(file in files) {
temp <- read.csv(paste0(OUTDIR,file), stringsAsFactors = F)
temp <- temp[which(nchar(temp$Diagram) == temp$Read_end_3 - temp$Read_start_5 +1),]
counting[count,1] <- file
counting[count,2] <- sum(temp$Seed_Type == "seed_7")
counting[count,3] <- sum(temp$Seed_Type == "seed_6")
counting[count,4] <- sum(temp$Seed_Type == "seed_7m1")
counting[count,5] <- sum(temp$Seed_Type == "seed_7m2")
counting[count,6] <- sum(temp$Seed_Type == "other")
counting[count,7] <- sum(temp$Seed_Type == "seed_truncated")
count= count+1
test <- temp
}
write.csv(counting, paste0(OUTDIR,"Counts/","SeedMatches_CompleteDiags.csv"), row.names=F)
####################################################################################################################################
files <- list.files(OUTDIR, pattern = "\\.csv$")
counting <- data.frame(matrix(NA, nrow=length(files), ncol=6))
colnames(counting) <- c("Sample","Absent", "Weak", "Moderate", "Strong", "miR_truncated")
count =1
for(file in files) {
temp <- read.csv(paste0(OUTDIR,file), stringsAsFactors = F)
counting[count,1] <- file
counting[count,2] <- sum(temp$Bind_3p_Type == "Absent")
counting[count,3] <- sum(temp$Bind_3p_Type == "Weak")
counting[count,4] <- sum(temp$Bind_3p_Type == "Moderate")
counting[count,5] <- sum(temp$Bind_3p_Type == "Strong")
counting[count,6] <- sum(temp$Bind_3p_Type == "miR_truncated")
count= count+1
}
write.csv(counting, paste0(OUTDIR,"Counts/","Binding_3p.csv"), row.names=F)
# Running these counts only on complete diagrams
counting <- data.frame(matrix(NA, nrow=length(files), ncol=6))
colnames(counting) <- c("Sample","Absent", "Weak", "Moderate", "Strong", "miR_truncated")
count =1
for(file in files) {
temp <- read.csv(paste0(OUTDIR,file), stringsAsFactors = F)
temp <- temp[which(nchar(temp$Diagram) == temp$Read_end_3 - temp$Read_start_5 +1),]
counting[count,1] <- file
counting[count,2] <- sum(temp$Bind_3p_Type == "Absent")
counting[count,3] <- sum(temp$Bind_3p_Type == "Weak")
counting[count,4] <- sum(temp$Bind_3p_Type == "Moderate")
counting[count,5] <- sum(temp$Bind_3p_Type == "Strong")
counting[count,6] <- sum(temp$Bind_3p_Type == "miR_truncated")
count= count+1
}
write.csv(counting, paste0(OUTDIR,"Counts/","Binding_3p_CompleteDiags.csv"), row.names=F)
####################################################################################################################################