### NetWalk edge list preprocess

args=commandArgs(TRUE)

# Packages to load ############################################################################
library(igraph)
library(gtools)

indir <- args[1]#"brain-hprd/dyn-net"# args[1]#
outdir <- args[2]#"dynamic-networks"# args[2]#

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

# for every age
for(k in 1:length(adirs)){
  
  temp <- read.csv(adirs[k], header=TRUE)

  #keep the minimum of the edge scores
  x <- graph_from_data_frame(temp, directed=FALSE,vertices=NULL)
  y <- simplify(x, remove.multiple=TRUE, remove.loops=TRUE,  edge.attr.comb ="min")
  z <- as.data.frame(get.edgelist(y))
  q <- E(y)$V3
  z$weight <- q

  write.table(z, paste0(outdir, '/', strsplit(basename(adirs[k]),'[.]')[[1]][1],'.txt'),  col.names=FALSE, row.names=FALSE, quote=FALSE, sep='\t')
  
}


