/ lncdid
lncdid
 1  #!/usr/bin/env Rscript
 2  
 3  suppressMessages(library(magrittr))
 4  
 5  d <- data.frame(id=commandArgs(trailingOnly=T))
 6  
 7  # input into sql approprate string. eg " '11523','10931' "
 8  l_in <-
 9     d$id %>%
10     gsub("[^0-9A-Za-z]", "", .) %>% # sanatize
11     gsub("^", "'", .) %>%           # add begin quote
12     gsub("$", "'", .) %>%           # add ending quote
13     unique %>%
14     paste(collapse=",")             # put commas between
15  
16  query <- sprintf("
17            select i.id as id, e.id as other, e.etype as etype
18            from enroll e
19            join enroll i on e.pid = i.pid
20            where i.id in (%s)", l_in)
21  
22  r <- LNCDR::db_query(query) 
23  if(nrow(r) == 0L) stop(paste(collapse=",", d$id) %>% sprintf('#no ids found! %s', .))
24  
25  f <- merge(r, d, by='id', all=T)
26  
27  # spit out results
28  write.table(f, file=stdout(), row.names=F, sep="\t", quote=F)