
args=commandArgs(TRUE)

# Packages to load #######
library(gtools)
library(foreach)
library(doParallel)
library(data.table)

indir <- args[1] #"node-features-binned-concat"#
outdir <- args[2]#"node-features-binned-concat-vect"#

afiles <- list.files(indir, full.names=TRUE)

# parralel for loop for efficieny #############################
cores=detectCores()
cl <- makeCluster(cores[1])
registerDoParallel(cl)

foreach(i=1:length(afiles)) %dopar% {
  
    library(data.table)
    bs <- basename(afiles[i])
    bs1 <- strsplit(basename(afiles[i]), '[.]')[[1]][1]

    temp <- as.vector(as.matrix(fread(afiles[i], sep=' ')))
    tempy <- paste(temp, collapse=' ')
    tempz <- paste0(bs1,' ', tempy)

    # save features
    writeLines(tempz, paste0(outdir,'/',bs))

}

stopCluster(cl)

