complete wrapper.R; update TODO
[epclust.git] / old_C_code / stage1 / wrapper.R
1 ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL,
2 args="DontLetMeEmptyPlease!")
3 {
4 command_line = paste("mpirun -np ",np," ",path,"/ppam.exe cluster",sep="")
5
6 #if data provided (as data.frame or matrix...): binarize it, and add it as first argument
7 if (!is.null(data))
8 {
9 if (!is.character(data))
10 {
11 #assuming matrix or data.frame, WITH row names
12 #( identifiers; could be line number... e.g. data <- cbind(1:nrow(data),data) )
13 write.table(data, "/tmp/data_csv", sep=",", row.names=FALSE, col.names=FALSE)
14 system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
15 } else
16 {
17 system(paste(path,"/ppam.exe serialize ",data," /tmp/data_bin 0 0",sep=""))
18 }
19 command_line = paste(command_line," /tmp/data_bin",sep="")
20 }
21
22 command_line = paste(command_line," ",args,sep="")
23 system(command_line)
24 }
25
26 #NOTE: identifiers in first column
27 getMedoids = function(path=".", xmlResult = "ppamResult.xml",
28 finalSeries = "ppamFinalSeries.bin")
29 {
30 system(paste(path,"/ppam.exe deserialize ",finalSeries," ppamFinalSeries.csv -1",sep=""))
31 curves = read.table("ppamFinalSeries.csv", sep=",")
32 library(XML)
33 ranks = as.integer( xmlToList( xmlParse(xmlResult) )$ranks )
34 return ( curves[ranks,] ) # == medoids
35 }
36
37 getDistor = function(path=".", xmlResult = "ppamResult.xml",
38 finalSeries = "ppamFinalSeries.bin")
39 {
40 system(paste(path,"/ppam.exe classif ",finalSeries," ",xmlResult,sep=""))
41 }
42
43 serialize = function(path=".", csvSeries, binSeries, byCols=0, nbSeries=0)
44 {
45 system(paste(path,"/ppam.exe serialize ",csvSeries," ",binSeries," ",byCols," ",nbSeries,
46 sep=""))
47 }
48
49 deserialize = function(path=".", binSeries, csvSeries, ranks="-1")
50 {
51 system(paste(path,"/ppam.exe deserialize ",binSeries," ",csvSeries," ",ranks,sep=""))
52 return ( read.table(csvSeries, sep=",") )
53 }