source("../genomics/scripts/lab_helpers.R")
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(readr)
wlab <- write_db("Laboratory")
Loading required package: DBI
# set to current sequencing run
ligs <- wlab %>%
tbl("ligation") %>%
collect() %>%
select(-digest_id:-water, -well:-corr_date)
current<- wlab %>%
tbl("pcr") %>%
filter(SEQ == params$seq) %>%
collect() %>%
select(pcr_id, SEQ)
barcode <- wlab %>%
tbl("barcodes") %>%
collect()
# for SEQ04 the files are named differently
pcr_ids <- substr(current$pcr_id, 3,4)
# pull out only the pools in current sequencing run
for(i in seq(current$pcr_id)){
# define the log file
filename <- paste0("~/Downloads/", pcr_ids[i], "process.out.tsv")
# read in the log file
samples <- read_delim(filename, delim = "\t", col_names = c("barcode", "total_reads", "lack_rad_tag", "low_quality", "retained"),
col_types = cols("c", "c", "c", "c", "c")) #import all columns as character
# merge to barcodes to get barcode number and add pool to table
samples <- left_join(samples, barcode, by = "barcode") %>%
mutate(pool = current$pcr_id[i])
# merge to ligation_ids and remove barcode
samples <- left_join(samples, ligs, by = c("barcode_num", "pool")) %>%
select(-barcode)
dat <- wlab %>%
tbl("ligation") %>%
collect()
change <- dat %>%
filter(ligation_id %in% samples$ligation_id) %>%
select(-total_reads, -lack_rad_tag, -low_quality, -retained)
change <- left_join(change, samples, by = c("ligation_id", "barcode_num", "pool"))
dat <- change_rows(dat, change, "ligation_id")
dbWriteTable(wlab, "ligation", dat, row.names = F, overwrite = T)
}
LS0tCnRpdGxlOiAiQWRkIHNlcXVlbmNpbmcgcmVzdWx0cyB0byBkYXRhYmFzZSIKb3V0cHV0OiBodG1sX25vdGVib29rCnBhcmFtczoKICBzZXE6ICBTRVEwNAotLS0KCmBgYHtyfQpzb3VyY2UoIi4uL2dlbm9taWNzL3NjcmlwdHMvbGFiX2hlbHBlcnMuUiIpCmxpYnJhcnkocmVhZHIpCndsYWIgPC0gd3JpdGVfZGIoIkxhYm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