//SAMA
version=0.99;
//Copyright (C) 2015 Maël Montévil and Tessie Paulose
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
print("***************************");
print("Sarting R Sama version "+version);
//function to create a directory if it does not exist
function createdir(dir, suffix) {
dirres=dir+suffix+"/";
if(!File.isDirectory(dirres)){
File.makeDirectory(dirres);
}
return dirres;
}
//convert boolean in ImageJ to R string for boolean
function convertBool(bool) {
if(bool){
return "TRUE";
}
else{
return "FALSE";
}
}
// we progressively construct a R command starting with command0
command0="suppressPackageStartupMessages(library(\"Rsama\"));";
// Interface part
items=newArray("With","Without");
Quality=0;
labell=newArray("None","Treatment And Plate","Plate","Treatment","Filename");
Dialog.create("SAMA-Analyze");
Dialog.addMessage("*Were these parameters analyzed in SAMA-images?");
Dialog.addCheckbox(" Branching", true);
Dialog.addCheckbox(" Lumen", true);
Dialog.addCheckbox(" Thickness", false);
Dialog.addMessage("*Data handling");
Dialog.addCheckbox(" Put data together (only needed once)", true);
Dialog.addCheckbox(" Export sheet (optional)", false);
Dialog.addMessage("*Data analysis");
Dialog.addCheckbox(" Batch analyze treatment effect", true);
Dialog.addCheckbox(" Analyze Reproducibility", true);
Dialog.addMessage("*Choose a subset of the conditions?");
Dialog.addCheckbox("Use interface to choose conditions", false);
Dialog.addMessage("*Options for Analysis");
Dialog.addNumber("Quality Threshold",Quality );
Dialog.addNumber("Size Threshold (volume)",500);
Dialog.addMessage("*Options for Graphs");
Dialog.addChoice("Choose label used in PCA", labell);
Dialog.addCheckbox("Color graphs", true);
Dialog.show();
tree0 = Dialog.getCheckbox();
lumen0 = Dialog.getCheckbox();
bonus0 = Dialog.getCheckbox();
stitchdata = Dialog.getCheckbox();
exportt = Dialog.getCheckbox();
treatment = Dialog.getCheckbox();
consistency = Dialog.getCheckbox();
subcond = Dialog.getCheckbox();
Quality = Dialog.getNumber();
crisize = Dialog.getNumber();
labelr=Dialog.getChoice();
center = false;
colorr = Dialog.getCheckbox();
colorr=convertBool(colorr);
lumen=convertBool(lumen0);
tree=convertBool(tree0);
bonus=convertBool(bonus0);
center=convertBool(center);
chosendir = getDirectory("Choose Data Directory, the folder should be called SAMA-Image data");
dir=File.getParent(chosendir)+"/";
diroutput=createdir(dir,"SAMA-Analyze output/");
Rdatadir =dir+"SAMA-Image data/";
condd="c(\"\")";
nameout="";
filterwith="TRUE";
filter = "";
// start constructing the command streamed to R
if(stitchdata){
command=command0+"message(\"Putting data together...\");";
command=command+"mergeF(\""+Rdatadir+"\",lumen="+lumen+",tree="+tree+",bonus="+bonus+");";
}else{
command=command0;
}
// If the user chooses to select a subset of condition, we build the set of available conditions to display it in the interface.
if(subcond){
command=command+"getconditions(\""+Rdatadir+"\",\"external\",versioncounter=4);";
res=call("R_bind_sama.execCode",command);
command=command0;
open(Rdatadir+"combinedcdt.csv");
labels= newArray(nResults);
default=newArray(nResults);
for (i=0; i