-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandora2capture_request.R
More file actions
220 lines (197 loc) · 9.04 KB
/
pandora2capture_request.R
File metadata and controls
220 lines (197 loc) · 9.04 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
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
#!/usr/bin/env Rscript
## Need sidora.core to pull library metainfo
if (!require('sidora.core')) {
if(!require('remotes')) install.packages('remotes')
remotes::install_github('sidora-tools/sidora.core', quiet=T)
} else {library(sidora.core)}
require(purrr)
require(tidyverse, warn.conflicts = F)
require(optparse)
require(readr)
require(stringr)
Probe_Sets_Jena_CoreUnit <- read.csv("Probe_Set.csv")
validate_csv <- function(csv) {
labs <- c("CoreUnit","JenaLab")
sequencing_kits <- c("HiSeq4000 75 SR","HiSeq4000 75 PE**","HiSeq4000 150 PE**",
"Flex 75 PE*", "Flex 75 SR*",
"MiSeqNano 150 PE",
"MiSeqMicro 150 PE","MiSeq 75 PE", "MiSeq 150 PE","MiSeq 300 PE",
"NextSeq500MO 75 PE", "NextSeq500MO 75 SR",
"NextSeq500MO 150 SR", "NextSeq500MO 150 PE**",
"NextSeq500HO 75 PE**", "NextSeq500HO 75 SR**",
"NextSeq500HO 150 PE**",
"NovaSeqX 75 PE*",
"NovaSeqX 100PE*")
sequencing_depths <- c("1M","2M","5M","10M","20M", "40M")
incorrect_probe <- csv %>% filter(!Probe_Set %in% Probe_Sets_Jena_CoreUnit$Name) %>% pull(Probe_Set)
incorrect_lab <- csv %>% filter(!Lab %in% labs) %>% pull(Lab)
incorrect_kit <- csv %>% filter(!Sequencing_Kit %in% sequencing_kits) %>% pull(Sequencing_Kit)
incorrect_depth <- csv %>% filter(!Sequencing_Depth %in% sequencing_depths) %>% pull(Sequencing_Depth)
if (length(incorrect_probe) == 0 & length(incorrect_lab) == 0 & length(incorrect_kit) == 0 & length(incorrect_depth) == 0) {
cat("\n[pandora2capture_request.R]: CSV check passed")
} else {
if ( length(incorrect_probe) != 0 ) {
cat(paste("\n[pandora2capture_request.R] error: Invalid probe set: '", incorrect_probe,
"'\nAccepted values: ", paste(probe_set,collapse=", "),"\n\n"))
}
if ( length(incorrect_lab) != 0 ) {
cat(paste("\n[pandora2capture_request.R] error: Invalid lab: '", incorrect_lab,
"'\nAccepted values: ", paste(labs,collapse=", "), "\n\n", sep = ""))
}
if ( length(incorrect_kit) != 0 ) {
cat(paste("\n[pandora2capture_request.R] ERROR - Invalid sequencing kit: '", incorrect_kit,
"'\nAccepted values: ", paste(sequencing_kits,collapse=", "),"\n\n",sep = ""))
}
if ( length(incorrect_depth) != 0 ) {
cat(paste("\n[pandora2capture_request.R] error: Invalid sequencing depth: '", incorrect_depth,
"'\nAccepted values: ", paste(sequencing_depths,collapse=", "),"\n\n"))
}
if ( length(incorrect_probe) != 0 | length(incorrect_lab) != 0 | length(incorrect_kit) != 0 | length(incorrect_depth) != 0 ) {
stop()
}
}
}
validate_libraries <- function(option, opt_str, value, parser) {
ifelse(!is.na(value),
return(value),
stop(call.=F, "\n[pandora2capture_request.R] error: No file with libraries provided!\n Please provide a file with library IDs using the -f option"))
}
## Parse arguments ----------------------------
parser <- OptionParser(usage = "%prog [options] .credentials")
##Make -f mandatory with valid_entries
parser <- add_option(parser, c("-f", "--file_libraries_id"), type = 'character',
action = "callback", dest = "file_libraries_id",
callback = validate_libraries,
help = "CSV file containing all the libraries ID, probe set, sequecing kit, sequencing depth, cost center and lab",
default = NA)
parser <- add_option(parser, c("-r", "--researcher"), type = 'character',
action = "store", dest = "researcher", default=NA,
help = "Name of the contact person for the request"
)
parser <- add_option(parser, c("-e", "--emailresearcher"), type = 'character',
action = "store", dest = "email", default=NA,
help = "Email of the contact person for the request"
)
parser <- add_option(parser, c("-o", "--outDir"), type = 'character',
action = "store", dest = "outdir",
help= "The desired output directory. By default, it is the current directory.",
default = "."
)
parser <- add_option(parser, c("-v", "--version"), action= 'store_true', default=FALSE, help = "Prints version")
arguments <- parse_args(parser, positional_arguments = 1)
opts <- arguments$options
if( opts$version == TRUE ) {
print("[pandora2capture_request.R] version 1.0")
quit()
}
cred_file <- arguments$args
libraries <- read.csv(opts$file_libraries_id, header = T)
#Check all columns contain correct information:
validate_csv(libraries)
contact <- paste(opts$researcher, opts$email, sep = ",")
requestDate <- Sys.Date()
con <- sidora.core::get_pandora_connection(cred_file)
libraryTab <- get_df("TAB_Library", con) %>%
convert_all_ids_to_values(con) %>%
filter(library.Full_Library_Id %in% libraries$Library_ID)
JenaLab <- libraries %>%
filter(Lab == "JenaLab")
CoreUnit <- libraries %>%
filter(Lab == "CoreUnit")
if (nrow(JenaLab) > 0) {
JenaTSV <- libraryTab %>%
filter(library.Full_Library_Id %in% JenaLab$Library_ID) %>%
left_join(JenaLab, by = c("library.Full_Library_Id" = "Library_ID")) %>%
mutate(
Library_ID = library.Full_Library_Id,
Researchers_Name = contact,
Project_Name = ifelse(is.na(Cost_Center), library.Projects, as.character(Cost_Center)),
Batch = library.Batch,
Robot = case_when(
library.Robot == FALSE ~ "n",
library.Robot == TRUE ~ "y",
is.na(library.Robot) ~ "NA"
),
Protocol = library.Protocol,
Probe_Set = Probe_Set,
Position_on_plate = library.Position_on_Plate,
Location = library.Location_Room,
Drawer = paste(" ",library.Location, sep = ""),
P7_Index_Name = library.P7_Index_Id,
P7_Index_Sequence = library.P7_Index_Sequence,
P5_Index_Name = library.P5_Index_Id,
P5_Index_Sequence = library.P5_Index_Sequence,
P5_Barcode = library.P5_Barcode_Sequence,
P7_Barcode =library.P7_Barcode_Sequence,
concentration_from_Nanodrop = "",
additional_notes = "",
) %>%
select(!contains("library.")) %>%
select(!contains(c("Sequencing_Kit","Sequencing_Depth","Cost_Center","Lab", "MPI_probe_pool"))) %>%
relocate(Probe_Set, .after = Protocol)
nameOutput <- paste(paste("CaptureRequest","JenaLab",requestDate, sep = "_"),"tsv",sep = ".")
outputTSV <- paste(opts$outdir,nameOutput, sep = "/")
write_tsv(JenaTSV, file = outputTSV)
}
if (nrow(CoreUnit) > 0) {
Probe_Sets_Core_Unit <- Probe_Sets_Jena_CoreUnit %>%
select(Name,MPI_probe_pool)
code_probe_set <- Probe_Sets_Core_Unit %>%
filter(Name %in% CoreUnit$Probe_Set)
CoreUnitTSV <- libraryTab %>%
filter(library.Full_Library_Id %in% CoreUnit$Library_ID) %>%
left_join(CoreUnit, by = c("library.Full_Library_Id" = "Library_ID")) %>%
left_join(Probe_Sets_Core_Unit, by = c("Probe_Set" = "Name")) %>%
mutate(
Sample_type_submitted = "Library",
Account_name = ifelse(is.na(Cost_Center), library.Projects, as.character(Cost_Center)),
Contact_person_email = contact,
Core_Unit_MPI_EVA_ID = library.CoreDB_Id,
Customer_PandoraID = library.Full_Library_Id,
Sampling_Protocol = "",
Comments = "",
Weight_of_total_Material_Provided = "",
Weight_of_Material_to_be_used = "",
Comments_Samples = "",
Pre_Treatment = "",
fluidX_Rack_ID_of_Lysate = "",
fluidX_tube_ID_of_Lysate = "",
Volume_of_total_Lysate_Provided = "",
Volume_of_Lysate_to_be_used = "",
Comments_Extraction = "",
Pandora_batch_ID = "",
fluidX_Rack_ID_of_Extract = "",
fluidX_tube_ID_of_Extract = "",
Volume_of_total_Extract_Provided = "",
Volume_DNA_Extract_to_be_used = "",
UDG_Treatment = "",
Comments_LibraryPrep = "",
Shotgun_sequencing = "no",
Plate_ID_Pandora_batch_ID_ShotgunSequencing = "",
Plate_position_ShotgunSequencing = "",
Sequencing_depth_ShotgunSequencing = "",
Sequencing_package_ShotgunSequencing = "",
Comments_ShotgunSequencing = "",
Capture = "yes",
Plate_ID_Pandora_batch_ID_Capture = library.Batch,
Plate_position_Capture = library.Position_on_Plate,
ProbeSet = MPI_probe_pool,
Comments_Capture = "",
Capture_Sequencing = "yes",
Sequencing_depth_Capture = Sequencing_Depth,
Sequencing_package_Capture = Sequencing_Kit,
Comments_CaptureSequencing = "",
Shipping = "",
Plate_ID_Pandora_batch_ID_Aliquoting = "",
Plate_position_Aliquoting = "",
Destination_address = "",
Comments_Aliquoting = ""
) %>%
select(!contains("library.")) %>%
select(!contains(c("Sequencing_Kit","Cost_Center","Lab", "MPI_probe_pool"))) %>%
select(-Sequencing_Depth) %>%
select(-Probe_Set)
nameOutput <- paste(paste("CaptureRequest","CoreUnit",requestDate, sep = "_"),"tsv",sep = ".")
outputTSV <- paste(opts$outdir,nameOutput, sep = "/")
write_tsv(CoreUnitTSV, file = outputTSV)
}