This repository was archived by the owner on Oct 8, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathexport_to_sql.R
More file actions
166 lines (136 loc) · 3.5 KB
/
Copy pathexport_to_sql.R
File metadata and controls
166 lines (136 loc) · 3.5 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
if (!require('tcltk')) {
install.packages('tcltk')
library('tcltk')
}
if (!require('foreach')) {
install.packages('foreach')
library('foreach')
}
if (!require('readr')) {
install.packages('readr')
library('readr')
}
if (!require('tidyverse')) {
install.packages('tidyverse')
library('tidyverse')
}
print("Select the NCBI CSV file that you process !!!")
Filters <- matrix(c("CSV File", "*NCBI*.csv",
"All files", "*"),
4, 2, byrow = TRUE)
csv_file <-
tk_choose.files(
default = "",
caption = "Select NCBI CSV File",
multi = FALSE,
filter = Filters
)
ncbi_csv_file <- read_csv(
csv_file,
col_types = cols(
name = col_character(),
specie = col_character(),
annotation = col_character(),
sequence = col_character(),
creation_date = col_character()
)
)
print("Select the Ensembl CSV file that you process !!!")
Filters <- matrix(c("CSV File", "*Ensembl*.csv",
"All files", "*"),
4, 2, byrow = TRUE)
csv_file <-
tk_choose.files(
default = "",
caption = "Select Ensembl CSV File",
multi = FALSE,
filter = Filters
)
ensembl_csv_file <- read_csv(
csv_file,
col_types = cols(
name = col_character(),
transcript = col_character(),
gene = col_character(),
chromosome = col_character(),
`gene symbol` = col_character(),
specie = col_character(),
annotation = col_character(),
sequence = col_character(),
creation_date = col_character()
)
)
merged_data <- ""
# Initializes the progress bar
pb <-
tkProgressBar(
title = "Convart SQL Export",
# Title of bar
label = "Combining CSV files to export for Ensembl and NCBI",
# Information label
min = 0,
# Minimum value of the progress bar
max = nrow(ensembl_csv_file),
# Maximum value of the progress bar
width = 300
)
foreach(i = 1:nrow(ensembl_csv_file)) %do% {
merged_data <- rbind(merged_data, paste0(
"INSERT INTO ensembl_meta_data ",
"( id, ",
paste0(names(ensembl_csv_file)[2:length(ensembl_csv_file)], collapse = ", "),
") ",
sprintf(
"VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s",
i,
ensembl_csv_file[i,]$name,
ensembl_csv_file[i,]$transcript,
ensembl_csv_file[i,]$gene,
ensembl_csv_file[i,]$chromosome,
ensembl_csv_file[i,]$`gene symbol`,
ensembl_csv_file[i,]$specie,
ensembl_csv_file[i,]$annotation,
ensembl_csv_file[i,]$sequence,
ensembl_csv_file[i,]$creation_date
),
")"
))
setTkProgressBar(pb, i)
}
# Initializes the progress bar
pb <-
tkProgressBar(
title = "Convart SQL Export",
# Title of bar
label = "Combining CSV files to export for Ensembl and NCBI",
# Information label
min = 0,
# Minimum value of the progress bar
max = nrow(ncbi_csv_file),
# Maximum value of the progress bar
width = 300
)
foreach(i = 1:nrow(ncbi_csv_file)) %do% {
merged_data <- rbind(merged_data, paste0(
"INSERT INTO ncbi_meta_data ",
"( id, ",
paste0(names(ncbi_csv_file)[2:length(ncbi_csv_file)], collapse = ", "),
") ",
sprintf(
"VALUES ( %d, %s, %s, %s, %s, %s ",
i,
ensembl_csv_file[i,]$name,
ensembl_csv_file[i,]$specie,
ensembl_csv_file[i,]$annotation,
ensembl_csv_file[i,]$sequence,
ensembl_csv_file[i,]$creation_date
),
")"
))
setTkProgressBar(pb, i)
}
fileConn<-file("output.sql")
writeLines(merged_data, fileConn)
close(fileConn)
writeLines()
close(pb)