############################################################################################ # An example of an R script that illustrates how carthaGene can be setup as a server # for mapping which is controlled from R under Unix/Linux. # Thanks to Matthieu Falque (INRA Moulon) for this script ############################################################################################ #------------------------------------------------------------------------------------------------------------------------------------- # Initializes FIFOs and CarthaGene #------------------------------------------------------------------------------------------------------------------------------------- cg.open = function(rawName) { system("mkfifo CGfifoOut", intern=FALSE, ignore.stderr = FALSE, wait=TRUE, input=NULL) CGfifoIn <- fifo("CGfifoIn", "w+", blocking=FALSE) # creates fifo to send commands to CG CGfifoOut <- fifo("CGfifoOut", "r+", blocking=FALSE) # creates fifo to get commands from CG system("carthagene CGfifoOut", intern=FALSE, ignore.stderr = FALSE, wait=FALSE, input=NULL) # launches CG in background writeLines(paste("dsload", rawName), CGfifoIn) # sends command so that CG loads dataset writeLines("group -u", CGfifoIn) # dummy command, just to know when CG has finished loading the dataset cg.out=readLines(CGfifoOut, n=1) iOk=grep("group DistThres LODThres", cg.out) while (length(iOk)==0) { # waits for answer to "group -u" command cg.out=c(cg.out, readLines(CGfifoOut), n=1) iOk=grep("group DistThres LODThres", cg.out) } foo=readLines(CGfifoOut, n=-1) # empties buffer return(list(fifoIn=CGfifoIn, fifoOut=CGfifoOut)) } #------------------------------------------------------------------------------------------------------------------------------------- # Closes CarthaGene and FIFOs #------------------------------------------------------------------------------------------------------------------------------------- cg.close = function(fifoList) { # fifoList that was returned by cg.open CGfifoIn=fifoList$fifoIn CGfifoOut=fifoList$fifoOut writeLines("exit", CGfifoIn) # sends command so CG closes close(CGfifoIn) # closes connections close(CGfifoOut) unlink(CGfifoIn) unlink(CGfifoOut) system("rm CGfifoOut", intern=FALSE, ignore.stderr = FALSE, wait=TRUE, input=NULL) # removes fifo files system("rm CGfifoIn", intern=FALSE, ignore.stderr = FALSE, wait=TRUE, input=NULL) }