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()
# pull out only the pools in current sequencing run
for(i in seq(current$pcr_id)){
  # define the log file
  filename <- paste0("~/Downloads/process", current$pcr_id[i], ".log.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)
}
LS0tCnRpdGxlOiAiQWRkIHNlcXVlbmNpbmcgcmVzdWx0cyB0byBkYXRhYmFzZSIKb3V0cHV0OiBodG1sX25vdGVib29rCnBhcmFtczoKICBzZXE6ICBTRVEzMQotLS0KCmBgYHtyfQpzb3VyY2UoIi4uL2dlbm9taWNzL3NjcmlwdHMvbGFiX2hlbHBlcnMuUiIpCmxpYnJhcnkocmVhZHIpCndsYWIgPC0gd3JpdGVfZGIoIkxh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