'redirect output to function instead then saving to files
I have a list of data frames (list_CLUMP) in R with all the same number of columns and rows. Then I save them to files and I use them as input for a function that takes a bash script as commands. The bash script takes each file as input at --clump:
sapply(names(list_CLUMP),
function (x) write_tsv(list_CLUMP[[x]],file=paste(x, "stats.tsv", sep=".") ))
split_and_clump <- function (gwas_file){
reference_bed="Geno_filtered_common_allmale"
p_thresh = 0.005
files_out<-gsub(pattern=".stats.tsv",
replacement=".clumped",
x=gwas_file)
plink_command <- paste0(
"plink --bfile ", reference_bed,
# " --thin-indiv-count 100000 ",
" --clump ", gwas_file,
" --clump-r2 0.05 --clump-kb 500 --clump-p1 ", p_thresh,
" --out ", files_out)
system(plink_command)}
#### add PLINK command to PATH !!!!!
Sys.getenv("PATH")
old_path <- Sys.getenv("PATH")
Sys.setenv(PATH = paste(old_path, "/usr/local/Caskroom/miniconda/base/bin:/usr/local/Caskroom/miniconda/base/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
", sep = ":"))
files<-list.files(pattern = "*tsv")
lapply(files, split_and_clump)
I would like to pass the R list directly to the function, to the bash commands rather than saving the data frames to files and then use the files for input of the function. Any suggestion?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
