major folder reorganisation, R pkg is now epclust/ at first level. Experimental usage...
[epclust.git] / old_C_code / stage1 / wrapper.R
diff --git a/old_C_code/stage1/wrapper.R b/old_C_code/stage1/wrapper.R
new file mode 100644 (file)
index 0000000..0ce9786
--- /dev/null
@@ -0,0 +1,42 @@
+ppam_exe = function(path=".", np=parallel::detectCores(), data=NULL,
+       args="DontLetMeEmptyPlease!")
+{
+       command_line = paste("mpirun -np ",np," ",path,"/ppam.exe cluster",sep="")
+
+       #if data provided (as data.frame or matrix...): binarize it, and add it as first argument
+       if (!is.null(data))
+       {
+               if (!is.character(data))
+               {
+                       #assuming matrix or data.frame, WITH row names
+                       #( identifiers; could be line number... e.g. data <- cbind(1:nrow(data),data) )
+                       write.table(data, "/tmp/data_csv", sep=",", row.names=FALSE, col.names=FALSE)
+                       system(paste(path,"/ppam.exe serialize /tmp/data_csv /tmp/data_bin 0 0",sep=""))
+               } else
+               {
+                       system(paste(path,"/ppam.exe serialize ",data," /tmp/data_bin 0 0",sep=""))
+               }
+               command_line = paste(command_line," /tmp/data_bin",sep="")
+       }
+
+       command_line = paste(command_line," ",args,sep="")
+       system(command_line)
+}
+
+#NOTE: identifiers in first column
+getMedoids = function(path=".", xmlResult = "ppamResult.xml",
+       finalSeries = "ppamFinalSeries.bin")
+{
+       system(paste(path,"/ppam.exe deserialize ",finalSeries," ppamFinalSeries.csv -1",sep=""))
+       curves = read.table("ppamFinalSeries.csv", sep=",")
+       library(XML)
+       ranks = as.integer( xmlToList( xmlParse(xmlResult) )$ranks )
+       return ( curves[ranks,] ) # == medoids
+}
+
+#TODO: check C function( is it correct?!)
+getDistor = function(path=".", xmlResult = "ppamResult.xml",
+       finalSeries = "ppamFinalSeries.bin")
+{
+       system(paste(path,"/ppam.exe classif ",finalSeries," ",xmlResult,sep=""))
+}