-
Notifications
You must be signed in to change notification settings - Fork 0
/
gisaid_formatter.R
283 lines (244 loc) · 9 KB
/
gisaid_formatter.R
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
library(readxl)
library(readr)
library(dplyr)
library(data.table)
library(lubridate)
#ILLUMINA PORTION
#Filter for samples not yet submitted to GISAID
Terra <-
read_tsv("sample - 2023-07-18T191753.177.tsv", col_names = T)
Terra_filtered = Terra %>% filter(
seq_platform == "ILLUMINA" &
!is.na(assembly_fasta) &
is.na(Submitted_to_Gisaid) &
!is.na(read1_dehosted) &
!grepl('skipped', vadr_num_alerts)
)
barcodes_filtered = data.frame(Terra_filtered$`entity:sample_id`,
Terra_filtered$purpose_of_sequencing)
colnames(barcodes_filtered) = c("entity:sample_id", "purpose_of_sequencing")
#LIMS_script
lims_metadata <- fread("lims_metadata.ALL.csv")
lims_metadata$`Sample Number` = NULL
lims_metadata$Patient = NULL
lims_metadata$`Last Name` = NULL
lims_metadata$`First Name` = NULL
lims_metadata$`Date Completed` = NULL
lims_metadata$`Birth Date` = NULL
lims_metadata$`Address1 Line 1` = NULL
lims_metadata$`Address1 Zip` = NULL
lims_metadata$`Address1 City` = NULL
lims_metadata.2 = unique(lims_metadata)
colnames(lims_metadata.2) = c(
"entity:sample_id",
"collection_date",
"customer",
"iso_gender",
"iso_age",
"iso_county",
"iso_state",
"depscription"
)
#Age of 5 year range
age=as.data.frame(str_split_fixed(lims_metadata.2$iso_age, ' ', 2))
lims_metadata.2$iso_age=paste(age$V1, "-", as.numeric(age$V1)+5, "years")
age=as.data.table(age)
age[V2 %in% "months", V1 := "0"]
age[V2 %in% "days", V1 := "0"]
age[V2 %in% "weeks", V1 := "0"]
lims_metadata.2 = as.data.table(lims_metadata.2)
lims_metadata.2[iso_state %in% c("nil", ""), iso_state := "Un"]
submission_id = paste(lims_metadata.2$iso_state,
"DHSS",
lims_metadata.2$`entity:sample_id`,
sep = "-")
bioproject_accession = "PRJNA673096"
gisaid_submitter = "mbajwa"
Authors = "Holly Miller, Moneeb Bajwa"
isolation_source = "Clinical"
library_selection = "cDNA"
library_source = "Genomic"
library_strategy = "Amplicon"
iso_continent = "North America"
iso_country = "USA"
originating_lab = "N/A"
submitting_lab = "Delaware Public Health Lab"
origLab_address = "N/A"
subLab_address = "30 Sunnyside Road, Smyrna, Delaware 19977"
host_disease = "COVID-19"
library_id = submission_id
organism = "SARS-CoV-2"
prep_upload_date = paste(Sys.Date(), "mercury_prep", sep = "_")
lims_metadata.2.1 = cbind(
lims_metadata.2,
submission_id,
bioproject_accession,
gisaid_submitter,
Authors,
isolation_source,
library_selection,
library_source,
library_strategy,
iso_continent,
iso_country,
originating_lab,
submitting_lab,
subLab_address,
origLab_address,
host_disease,
library_id,
organism,
prep_upload_date
)
`%!in%` <- Negate(`%in%`)
lims_metadata.2.1 = as.data.table(lims_metadata.2.1)
lims_metadata.2.1[customer %in% "CCMC", originating_lab := "CCMC"]
lims_metadata.2.1[customer %!in% "CCMC", originating_lab := "N/A"]
lims_metadata.2.1[customer %in% "CCMC", origLab_address := "4755 Ogletown Stanton Rd, Newark, DE 19718"]
for (i in 1:nrow(lims_metadata.2.1)) {
if (grepl('Nemours', lims_metadata.2.1$depscription[i], ignore.case = T) ==
T) {
lims_metadata.2.1$customer[i] = "Nemours"
}
}
lims_metadata.2.1[customer %in% "Nemours", origLab_address := "1600 Rockland Road, Wilmington, DE 19803"]
lims_metadata.2.1[customer %in% "Nemours", originating_lab := "Nemours"]
#Merge LIMS data with filtered samples from Terra
metadata = merge(lims_metadata.2.1, barcodes_filtered, by = "entity:sample_id")
not_found = anti_join(barcodes_filtered, lims_metadata.2.1, by = "entity:sample_id")
print("# of barcodes found: ", quote = F)
print(length(unique(metadata$`entity:sample_id`)))
write(unique(not_found$`entity:sample_id`),
"barcodes_notfound.txt")
xy = metadata$Label.Id
print("# of barcodes NOT found: ", quote = F)
print(length(unique(not_found$Label.Id)))
print("Duplicates: ", quote = F)
print(xy[duplicated(xy)], quote = F)
metadata[purpose_of_sequencing %in% NA, purpose_of_sequencing := "Baseline surveillance"]
metadata[customer %in% "Nemours", purpose_of_sequencing := "Targeted surveillance"]
#Reformat column values
metadata$collection_date <-
strftime(mdy_hms(metadata$collection_date), "%Y-%m-%d")
metadata = as.data.table(metadata)
metadata[iso_gender %!in% c("M", "F"), iso_gender := "unknown"]
#County name
metadata[iso_county %!in% c("001", "003", "005"), iso_county := "Unknown"]
metadata[iso_county %in% c("001"), iso_county := "Kent"]
metadata[iso_county %in% c("003"), iso_county := "New Castle"]
metadata[iso_county %in% c("005"), iso_county := "Sussex"]
metadata$depscription = NULL
metadata$customer = NULL
metadata.illumina = metadata
###############################################################################
#Clearlabs Portion
Terra_filtered = Terra %>% filter(
seq_platform == "OXFORD_NANOPORE" &
!is.na(clearlabs_fasta) &
is.na(Submitted_to_Gisaid) &
!grepl('skipped', vadr_num_alerts)
)
barcodes_filtered = data.frame(Terra_filtered$`entity:sample_id`,
Terra_filtered$purpose_of_sequencing)
colnames(barcodes_filtered) = c("entity:sample_id", "purpose_of_sequencing")
#LIMS_script
lims_metadata <- fread("lims_metadata.ALL.csv")
lims_metadata$`Sample Number` = NULL
lims_metadata$Patient = NULL
lims_metadata$`Last Name` = NULL
lims_metadata$`First Name` = NULL
lims_metadata$`Date Completed` = NULL
lims_metadata$`Birth Date` = NULL
lims_metadata$`Address1 Line 1` = NULL
lims_metadata$`Address1 Zip` = NULL
lims_metadata$`Address1 City` = NULL
lims_metadata.2 = unique(lims_metadata)
colnames(lims_metadata.2) = c(
"entity:sample_id",
"collection_date",
"customer",
"iso_gender",
"iso_age",
"iso_county",
"iso_state",
"depscription"
)
#Age of 5 year range
age=as.data.frame(str_split_fixed(lims_metadata.2$iso_age, ' ', 2))
lims_metadata.2$iso_age=paste(age$V1, "-", as.numeric(age$V1)+5, "years")
age=as.data.table(age)
age[V2 %in% "months", V1 := "0"]
age[V2 %in% "days", V1 := "0"]
age[V2 %in% "weeks", V1 := "0"]
lims_metadata.2 = as.data.table(lims_metadata.2)
lims_metadata.2[iso_state %in% c("nil", ""), iso_state := "Un"]
submission_id = paste(lims_metadata.2$iso_state,
"DHSS",
lims_metadata.2$`entity:sample_id`,
sep = "-")
library_id = submission_id
prep_upload_date = paste(Sys.Date(), "mercury_cl_prep", sep = "_")
lims_metadata.2.1 = cbind(
lims_metadata.2,
submission_id,
bioproject_accession,
gisaid_submitter,
Authors,
isolation_source,
library_selection,
library_source,
library_strategy,
iso_continent,
iso_country,
originating_lab,
submitting_lab,
subLab_address,
origLab_address,
host_disease,
library_id,
organism,
prep_upload_date
)
`%!in%` <- Negate(`%in%`)
lims_metadata.2.1 = as.data.table(lims_metadata.2.1)
lims_metadata.2.1[customer %in% "CCMC", originating_lab := "CCMC"]
lims_metadata.2.1[customer %!in% "CCMC", originating_lab := "N/A"]
lims_metadata.2.1[customer %in% "CCMC", origLab_address := "4755 Ogletown Stanton Rd, Newark, DE 19718"]
for (i in 1:nrow(lims_metadata.2.1)) {
if (grepl('Nemours', lims_metadata.2.1$depscription[i], ignore.case = T) ==
T) {
lims_metadata.2.1$customer[i] = "Nemours"
}
}
lims_metadata.2.1[customer %in% "Nemours", origLab_address := "1600 Rockland Road, Wilmington, DE 19803"]
lims_metadata.2.1[customer %in% "Nemours", originating_lab := "Nemours"]
#Merge LIMS data with filtered samples from Terra
metadata = merge(lims_metadata.2.1, barcodes_filtered, by = "entity:sample_id")
not_found = anti_join(barcodes_filtered, lims_metadata.2.1, by = "entity:sample_id")
print("# of barcodes found: ", quote = F)
print(length(unique(metadata$`entity:sample_id`)))
write(unique(not_found$`entity:sample_id`),
"barcodes_notfound.txt")
xy = metadata$Label.Id
print("# of barcodes NOT found: ", quote = F)
print(length(unique(not_found$Label.Id)))
print("Duplicates: ", quote = F)
print(xy[duplicated(xy)], quote = F)
metadata[purpose_of_sequencing %in% NA, purpose_of_sequencing := "Baseline surveillance"]
metadata[customer %in% "Nemours", purpose_of_sequencing := "Targeted surveillance"]
#Reformat column values
metadata$collection_date <-
strftime(mdy_hms(metadata$collection_date), "%Y-%m-%d")
metadata = as.data.table(metadata)
metadata[iso_gender %!in% c("M", "F"), iso_gender := "unknown"]
#County name
metadata[iso_county %!in% c("001", "003", "005"), iso_county := "Unknown"]
metadata[iso_county %in% c("001"), iso_county := "Kent"]
metadata[iso_county %in% c("003"), iso_county := "New Castle"]
metadata[iso_county %in% c("005"), iso_county := "Sussex"]
metadata$depscription = NULL
metadata$customer = NULL
metadata_cl = metadata
combined_metadata = rbind(metadata.illumina, metadata_cl)
View(combined_metadata)
write_tsv(combined_metadata, "public_subm_metadata.tsv")