[Zooimage-commits] r188 - in pkg: phytoimage/inst/gui zooimage zooimage/R zooimage/inst/gui zooimage/man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Apr 14 19:18:41 CEST 2010
Author: phgrosjean
Date: 2010-04-14 19:18:41 +0200 (Wed, 14 Apr 2010)
New Revision: 188
Modified:
pkg/phytoimage/inst/gui/MenusZIDlgWin.txt
pkg/zooimage/NAMESPACE
pkg/zooimage/R/RealTime.R
pkg/zooimage/R/ZIClass.R
pkg/zooimage/R/gui.R
pkg/zooimage/R/utilities.R
pkg/zooimage/R/zzz.R
pkg/zooimage/inst/gui/MenusZIDlgWin.txt
pkg/zooimage/man/utilities.Rd
Log:
Cleaning of menus, elimination of choose.files() (windows only) and rework of confusion.bar()
Modified: pkg/phytoimage/inst/gui/MenusZIDlgWin.txt
===================================================================
--- pkg/phytoimage/inst/gui/MenusZIDlgWin.txt 2010-04-13 16:14:14 UTC (rev 187)
+++ pkg/phytoimage/inst/gui/MenusZIDlgWin.txt 2010-04-14 17:18:41 UTC (rev 188)
@@ -1,5 +1,5 @@
# PhytoImage1 Tk menu
-# by Ph. Grosjean, 2006 <phgrosjean at sciviews.org>
+# by Ph. Grosjean, 2006-2010 <phgrosjean at sciviews.org>
# Create a Tk menu (intended for a window called 'ZIDlgWin')
$Tk.ZIDlgWin
@@ -22,6 +22,11 @@
||$E&xit
|||From the &assistant Ctrl+X ~~ closeAssistant()
|||From &PhytoImage ~~ closePhytoImage()
+|$Real-time
+||&Start process... ~~ realtimeRun()
+||&Stop process... ~~ realtimeStop()
+||&Export results... ~~ realtimeSave()
+||&Remove data... ~~ realtimeReset()
|$Objects
||&Load ~~ loadObjects()
||&Save ~~ saveObjects()
@@ -36,9 +41,6 @@
||Image &analyzer (ImageJ) ~~ startPgm("ImageEditor", switchdir = TRUE, iconize = TRUE)
||&Metadata editor (Sc1) ~~ startPgm("ZIEditor", cmdline = selectFile("ZimZis"))
||--
-||&Zip-Zid viewer (Filzip) ~~ startPgm("ZipViewer", cmdline = selectFile("ZipZid"))
-||CD-DVD &burner (DeepBurner) ~~ startPgm("DVDBurner")
-||---
||Simple acquisition (&VueScan) ~~ startPgm("VueScan", switchdir = TRUE)
|$Functions
||$PhytoImage &Metadata (zim)
@@ -105,8 +107,8 @@
||Biomass conversion specification ~~ startPgm("ZIEditor", cmdline = file.path(getTemp("ZIetc"), "Conversion.txt"))
||-
||$R Graphs
-|||&New ~~ windows()
-|||&Activate next ~~ {dev.set(); bringToTop()}
+|||&New ~~ dev.new()
+|||&Activate next ~~ {dev.set(); if (isRgui()) bringToTop()}
|||&Close all ~~ graphics.off()
|$Options
||Change &active dir... ~~ Setwd(paste(tkchooseDirectory(), collapse = " "))
@@ -114,7 +116,7 @@
||Define decimal separator... ~~ optInOutDecimalSep()
|$Help
-||&Online help ~~ browseURL(findhtmlhelp("zooimage"))
+||&Online help ~~ help("phytoimage")
||&Manual Ctrl+H ~~ viewManual()
||&Web site... ~~ browseURL("http://www.sciviews.org/zooimage")
||-
Modified: pkg/zooimage/NAMESPACE
===================================================================
--- pkg/zooimage/NAMESPACE 2010-04-13 16:14:14 UTC (rev 187)
+++ pkg/zooimage/NAMESPACE 2010-04-14 17:18:41 UTC (rev 188)
@@ -19,6 +19,7 @@
export(Abd.sample)
export(AboutZI)
export(acquireImg)
+export(AddVignToTrain)
export(analyzeClass)
export(BFcorrection)
export(Bio.sample)
@@ -26,6 +27,7 @@
export(calib)
export(calibrate)
export(checkBF)
+export(ClassifVigns)
export(clean.after.zid)
export(ClearProgress)
export(closeAssistant)
@@ -108,6 +110,10 @@
export(readTrain)
export(read.zid)
export(read.ZITrain)
+export(realtimeReset)
+export(realtimeRun)
+export(realtimeSave)
+export(realtimeStop)
export(recode.ZITrain)
export(refresh.zims)
export(removeObjects)
Modified: pkg/zooimage/R/RealTime.R
===================================================================
--- pkg/zooimage/R/RealTime.R 2010-04-13 16:14:14 UTC (rev 187)
+++ pkg/zooimage/R/RealTime.R 2010-04-14 17:18:41 UTC (rev 188)
@@ -15,6 +15,413 @@
# You should have received a copy of the GNU General Public License
# along with ZooImage. If not, see <http://www.gnu.org/licenses/>.
+# TODO: rework all this!!!
+# Functions and dialog box created for the real time recogntion
+"realtimeRun" <- function ()
+{
+ # Process real time recognition during a FlowCAM experiment
+ # First remove existing file from the global environment before read a new sample
+ realtimeReset()
+ # Ask for an algorithm and one or several sample to compare
+ defval <- "Only One Sample"
+ opts <- c("Only One Sample",
+ "Comparison with One Other Sample",
+ "Comparison with Several Other Samples")
+ # Then, show the dialog box
+ res <- modalAssistant(paste(getTemp("ZIname"),
+ "Real-Time recognition for FlowCAM"),
+ c("This is a beta version of the real time recognition",
+ "of FlowCAM samples developed for the AMORE III project.",
+ "Warning! This method is only developed for FlowCAM data,",
+ "and with a classifier made with FlowCAM parameters only.",
+ "", "Select an option:", ""), init = defval,
+ options = opts, help.topic = "makeClass")
+ if (res == "ID_CANCEL") return(invisible())
+ # Only one sample
+ if (res == "Only One Sample") {
+ # Use default values for the classifier creation
+ print("You will only recognize in real-time one sample")
+
+ # Look if we have a classifier object defined
+ ZIC <- getTemp("ZI.ClassName")
+ if (is.null(ZIC)) ZIC <- ""
+ ZIC <- getVar("ZIClass", multi = FALSE, default = ZIC,
+ title = "Choose a classifier (ZIClass object):", warn.only = FALSE)
+ if (length(ZIC) == 0 || (length(ZIC) == 1 && ZIC == ""))
+ return(invisible())
+ ZICobj <- get(ZIC, envir = .GlobalEnv)
+
+ # Select the current sample
+ Current <- paste(as.character(tkgetOpenFile(filetypes =
+ "{{FlowCAM list file} {.lst}}",
+ title = "Select a lst file")), collapse = " ")
+
+ # Select a conversion table
+ ConvFile <- getKey("ConversionFile", file.path(getTemp("ZIetc"),
+ "Conversion.txt"))
+ # Does this file exists?
+ if (!file.exists(ConvFile) || ConvFile == "")
+ ConvFile <- file.path(getTemp("ZIetc"), "Conversion.txt")
+ # Ask for selecting a Conversion file
+ if (isWin()) {
+ ConvFile <- choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = c("Biomass Conversion table (*Conversion.txt)",
+ "*Conversion.txt"))
+ } else {
+ ConvFile <- tk_choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = matrix(c("Biomass Conversion table",
+ ".txt"), ncol = 2, byrow = TRUE))
+ }
+ if (length(ConvFile) == 0 || ConvFile == "")
+ return(invisible()) # Cancelled dialog box
+
+ # Select the size spectra option
+ # On windows() --> To change for zooimage 1.2-2
+ brks <- winDialogString("Breaks for size spectrum classes in mm (empty for no spectrum):",
+ default = "seq(0.25, 2, by = 0.1)")
+ #brks <- dialogString("Breaks for size spectrum classes (empty for no spectrum):",
+ # "Size spectrum classes", default = "seq(0.25, 2, by = 0.1)")
+ if (is.null(brks) || length(brks) == 0 || brks == "")
+ return(invisible())
+ brks <- eval(parse(text = brks))
+ # Choose options
+ # Default options
+ Abd.all <- TRUE
+ Abd.gp <- NULL
+ Spec.all <- NULL
+ Spec.gp <- NULL
+ Bio.all <- NULL
+ Bio.gp <- NULL
+ defval_Graphs <- "Total Abundance"
+ opts_Graphs <- c("Total Abundance", "Abundance of groups",
+ "Total Size Spectra", "Size Spectra of groups",
+ "Total Biomass", "Biomass of groups")
+ res <- modalAssistant(paste(getTemp("ZIname"),
+ "Real-Time recognition for FlowCAM"),
+ c("Select one type of plot you want to do",
+ "", "Select an option:", ""), init = defval_Graphs,
+ options = opts_Graphs, help.topic = "makeClass")
+ if (res == "Total Abundance") Abd.all <- TRUE
+ if (res == "Abundance of groups") {
+ Abd.all <- NULL
+ Abd.gp <- selectGroups(ZICobj)
+ }
+ if (res == "Total Size Spectra") {
+ Abd.all <- NULL
+ Spec.all <- TRUE
+ }
+ if (res == "Size Spectra of groups") {
+ Abd.all <- NULL
+ Spec.gp <- selectGroups(ZICobj)
+ }
+ if (res == "Total Biomass") {
+ Abd.all <- NULL
+ Bio.all <- TRUE
+ }
+ if (res == "Biomass of groups") {
+ Abd.all <- NULL
+ Bio.gp <- selectGroups(ZICobj)
+ }
+ # Loop parameters
+ #realtimeOptions(lstdir = Current, # path of the list file of the FlowCAM run
+ # ZIClass = ZICobj, # Classifer
+ # ZIprevSmp = NULL, # Comparison with one previous sample
+ # ZIlist = NULL, # Comparison several previous samples
+ # ################## One Sample
+ # Abd.all = Abd.all, # NULL or TRUE
+ # Abd.gp = Abd.gp, # NULL or groups to plot
+ # Spec.all = Spec.all, # NULL or TRUE
+ # Spec.gp = Spec.gp, # NULL or groups
+ # Bio.all = Bio.all, # NULL or TRUE
+ # Bio.gp = Bio.gp, # NULL or groups
+ # breaks = brks, # in mm
+ # conv = ConvFile, # or conversion table
+ # ################## More than one sample
+ # ZICompAbd = NULL,
+ # ZICompSpectra = NULL,
+ # ZICompBiomass = NULL,
+ # ZICompSlope = NULL,
+ # ZICompAbd.gp = NULL,
+ # ZICompBio.gp = NULL
+ #)
+ # Run automatic recognition and plot
+ tclFun(realtimeLoop)
+ realtimeLoop()
+ }
+ if (res == "Comparison with One Other Sample") {
+ cat("You will compare the current sample with sample already digitized\n")
+ # Look if we have a classifier object defined
+ ZIC <- getTemp("ZI.ClassName")
+ if (is.null(ZIC)) ZIC <- ""
+ ZIC <- getVar("ZIClass", multi = FALSE, default = ZIC,
+ title = "Choose a classifier (ZIClass object):", warn.only = FALSE)
+ if (length(ZIC) == 0 || (length(ZIC) == 1 && ZIC == ""))
+ return(invisible())
+ ZICobj <- get(ZIC, envir = .GlobalEnv)
+
+ # Select the current sample
+ Current <- paste(as.character(tkgetOpenFile(filetypes =
+ "{{FlowCAM list file} {.lst}}",
+ title = "Select the lst file of the current sample")), collapse = " ")
+ # Select the Previous sample
+ Prev <- paste(as.character(tkgetOpenFile(filetypes =
+ "{{FlowCAM list file} {.lst}}",
+ title = "Select the lst file of the previous sample")), collapse = " ")
+ # TODO: there is no Prev argument in selectSamples()!?
+ #Prev <- selectSamples(Prev = Prev)
+ # Select a conversion table
+ ConvFile <- getKey("ConversionFile", file.path(getTemp("ZIetc"),
+ "Conversion.txt"))
+ # Does this file exists?
+ if (!file.exists(ConvFile) || ConvFile == "")
+ ConvFile <- file.path(getTemp("ZIetc"), "Conversion.txt")
+ # Ask for selecting a Conversion file
+ if (isWin()) {
+ ConvFile <- choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = c("Biomass Conversion table (*Conversion.txt)",
+ "*Conversion.txt"))
+ } else {
+ ConvFile <- tk_choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = matrix(c("Biomass Conversion table",
+ ".txt"), ncol = 2, byrow = TRUE))
+ }
+ if (length(ConvFile) == 0 || ConvFile == "")
+ return(invisible()) # Cancelled dialog box
+
+ # Select the size spectra option
+ # On windows() --> To change for zooimage 1.2-2
+ brks <- winDialogString("Breaks for size spectrum classes in mm (empty for no spectrum):",
+ default = "seq(0.25, 2, by = 0.1)")
+ #brks <- dialogString("Breaks for size spectrum classes (empty for no spectrum):",
+ # "Size spectrum classes", default = "seq(0.25, 2, by = 0.1)")
+ if (is.null(brks) || length(brks) == 0 || brks == "")
+ return(invisible())
+ brks <- eval(parse(text = brks))
+ # Choose options
+ # Default options
+ ZICompAbd <- TRUE
+ ZICompSpectra <- NULL
+ ZICompBiomass <- NULL
+ ZICompSlope <- NULL
+ ZICompAbd.gp <- NULL
+ ZICompBio.gp <- NULL
+ defval_Graphs <- "Total Abundance"
+ opts_Graphs <- c("Total Abundance", "Abundance of groups",
+ "Total Size Spectra", "Total Biomass", "Biomass of groups",
+ "Slope of size spectra")
+ res <- modalAssistant(paste(getTemp("ZIname"),
+ "Real-Time recognition for FlowCAM"),
+ c("Select one type of plot you want to do",
+ "", "Select an option you want to compare:", ""),
+ init = defval_Graphs, options = opts_Graphs,
+ help.topic = "makeClass")
+ if (res == "Total Abundance")
+ ZICompAbd <- TRUE
+ if (res == "Abundance of groups") {
+ ZICompAbd <- NULL
+ ZICompAbd.gp <- selectGroups(ZICobj)
+ }
+ if (res == "Total Size Spectra") {
+ ZICompAbd <- NULL
+ ZICompSpectra <- TRUE
+ }
+ if (res == "Total Biomass") {
+ ZICompAbd <- NULL
+ ZICompBiomass <- TRUE
+ }
+ if (res == "Biomass of groups") {
+ ZICompAbd <- NULL
+ ZICompBio.gp <- selectGroups(ZICobj)
+ }
+ if (res == "Slope of size spectra") {
+ ZICompAbd <- NULL
+ ZICompSlope <- TRUE
+ }
+ # Loop parameters
+ #realtimeOptions(lstdir = Current, # path of the list file of the FlowCAM run
+ # ZIClass = ZICobj, # Classifer
+ # ZIprevSmp = Prev, # Comparison with one previous sample
+ # ZIlist = NULL, # Comparison several previous samples
+ # ################## One Sample
+ # Abd.all = NULL, # NULL or TRUE
+ # Abd.gp = NULL, # NULL or groups to plot
+ # Spec.all = NULL, # NULL or TRUE
+ # Spec.gp = NULL, # NULL or groups
+ # Bio.all = NULL, # NULL or TRUE
+ # Bio.gp = NULL, # NULL or groups
+ # breaks = brks, # in mm
+ # conv = ConvFile, # or conversion table
+ # ################## More than one sample
+ # ZICompAbd = ZICompAbd,
+ # ZICompSpectra = ZICompSpectra,
+ # ZICompBiomass = ZICompBiomass,
+ # ZICompSlope = ZICompSlope,
+ # ZICompAbd.gp = ZICompAbd.gp,
+ # ZICompBio.gp = ZICompBio.gp
+ #)
+ # Run automatic recognition and plot
+ tclFun(realtimeLoop)
+ realtimeLoop()
+ }
+ if (res == "Comparison with Several Other Samples") {
+ cat("You will compare the current sample with a list of samples already digitized\n")
+ # Look if we have a classifier object defined
+ ZIC <- getTemp("ZI.ClassName")
+ if (is.null(ZIC)) ZIC <- ""
+ ZIC <- getVar("ZIClass", multi = FALSE, default = ZIC,
+ title = "Choose a classifier (ZIClass object):", warn.only = FALSE)
+ if (length(ZIC) == 0 || (length(ZIC) == 1 && ZIC == ""))
+ return(invisible())
+ ZICobj <- get(ZIC, envir = .GlobalEnv)
+
+ # Select the current sample
+ Current <- paste(as.character(tkgetOpenFile(filetypes =
+ "{{FlowCAM list file} {.lst}}",
+ title = "Select the lst file of the current sample")), collapse = " ")
+ # Select the Previous sample
+ List <- list.files(choose.dir(,caption = "Select general directory"),
+ recursive = TRUE, pattern = ".lst$", full.names = TRUE)
+ ListSamples <- selectSamples(Samples = List)
+
+ # Select a conversion table
+ ConvFile <- getKey("ConversionFile", file.path(getTemp("ZIetc"),
+ "Conversion.txt"))
+ # Does this file exists?
+ if (!file.exists(ConvFile) || ConvFile == "")
+ ConvFile <- file.path(getTemp("ZIetc"), "Conversion.txt")
+ # Ask for selecting a Conversion file
+ if (isWin()) {
+ ConvFile <- choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = c("Biomass Conversion table (*Conversion.txt)",
+ "*Conversion.txt"))
+ } else {
+ ConvFile <- tk_choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = matrix(c("Biomass Conversion table",
+ ".txt"), ncol = 2, byrow = TRUE))
+ }
+ if (length(ConvFile) == 0 || ConvFile == "")
+ return(invisible()) # Cancelled dialog box
+
+ # Select the size spectra option
+ # On windows() --> To change for zooimage 1.2-2
+ brks <- winDialogString("Breaks for size spectrum classes in mm (empty for no spectrum):",
+ default = "seq(0.25, 2, by = 0.1)")
+ #brks <- dialogString("Breaks for size spectrum classes (empty for no spectrum):",
+ # "Size spectrum classes", default = "seq(0.25, 2, by = 0.1)")
+ if (is.null(brks) || length(brks) == 0 || brks == "") return(invisible())
+ brks <- eval(parse(text = brks))
+ # Choose options
+ # Default options
+ ZICompAbd <- TRUE
+ ZICompSpectra <- NULL
+ ZICompBiomass <- NULL
+ ZICompSlope <- NULL
+ ZICompAbd.gp <- NULL
+ ZICompBio.gp <- NULL
+ defval_Graphs <- "Total Abundance"
+ opts_Graphs <- c("Total Abundance", "Abundance of groups",
+ "Total Size Spectra", "Total Biomass", "Biomass of groups",
+ "Slope of size spectra")
+ res <- modalAssistant(paste(getTemp("ZIname"),
+ "Real-Time recognition for FlowCAM"),
+ c("Select one type of plot you want to do",
+ "", "Select an option you want to compare:", ""),
+ init = defval_Graphs, options = opts_Graphs,
+ help.topic = "makeClass")
+ if (res == "Total Abundance")
+ ZICompAbd <- TRUE
+ if (res == "Abundance of groups") {
+ ZICompAbd <- NULL
+ ZICompAbd.gp <- selectGroups(ZICobj)
+ }
+ if (res == "Total Size Spectra") {
+ ZICompAbd <- NULL
+ ZICompSpectra <- TRUE
+ }
+ if (res == "Total Biomass") {
+ ZICompAbd <- NULL
+ ZICompBiomass <- TRUE
+ }
+ if (res == "Biomass of groups") {
+ ZICompAbd <- NULL
+ ZICompBio.gp <- selectGroups(ZICobj)
+ }
+ if (res == "Slope of size spectra") {
+ ZICompAbd <- NULL
+ ZICompSlope <- TRUE
+ }
+ # Loop parameters
+ # realtimeOptions(lstdir = Current, # path of the list file of the FlowCAM run
+ # ZIClass = ZICobj, # Classifer
+ # ZIprevSmp = NULL, # Comparison with one previous sample
+ # ZIlist = ListSamples, # Comparison several previous samples
+ # ################## One Sample
+ # Abd.all = NULL, # NULL or TRUE
+ # Abd.gp = NULL, # NULL or groups to plot
+ # Spec.all = NULL, # NULL or TRUE
+ # Spec.gp = NULL, # NULL or groups
+ # Bio.all = NULL, # NULL or TRUE
+ # Bio.gp = NULL, # NULL or groups
+ # breaks = brks, # in mm
+ # conv = ConvFile, # or conversion table
+ # ################## More than one sample
+ # ZICompAbd = ZICompAbd,
+ # ZICompSpectra = ZICompSpectra,
+ # ZICompBiomass = ZICompBiomass,
+ # ZICompSlope = ZICompSlope,
+ # ZICompAbd.gp = ZICompAbd.gp,
+ # ZICompBio.gp = ZICompBio.gp
+ # )
+ # Run automatic recognition and plot
+ tclFun(realtimeLoop)
+ realtimeLoop()
+ }
+}
+
+"realtimeSave" <- function ()
+{
+ save.loop.res <- function (lst, Classif, breaks = seq(0.25, 2, by = 0.1),
+ conv = c(1, 0, 1), save.dir = NULL) {
+ res <- getTemp("rtRecord")
+ if (is.null(rec))
+ rec <- predict(Classif, read.lst(lst),
+ calc.vars = TRUE, class.only = FALSE)
+ if (!is.null(save.dir)) {
+ if (!is.character(save.dir))
+ stop("The exportation path must be a character string")
+ } else {
+ save.dir <- choose.dir()
+ }
+ Bio.sample(ZIDat = rec, conv = conv, exportdir = NULL, RealT = TRUE)
+ # TODO: what is Bio.tab???
+ #write.table(Bio.tab, file = paste(save.dir, paste(basename(dirname(lst)),
+ # "AbdBio.txt", sep = "_"), sep = "\\"), sep = "\t", dec = ".",
+ # col.names = TRUE, na = "NA", row.names = FALSE)
+ # Delete objects from R environment
+ rmTemp("rtData")
+ rmTemp("rtRecord")
+ rmTemp("rtTime")
+ }
+ save.loop.res(lst = getOption("Path"), Classif = getOption("Classifier"),
+ breaks = getOption("breaks"), conv = getOption("conv"),
+ save.dir = dirname(getOption("Path")))
+}
+
+"realtimeStop" <- function ()
+ assignTemp(".realtimeStopItFlag", TRUE)
+
+"realtimeReset" <- function () {
+ assignTemp("rtData", NULL)
+ assignTemp("rtRecords", NULL)
+ assignTemp("rtTime", NULL)
+}
+
"realtimeSlope" <- function (ZIDat, breaks, log = TRUE)
{
if (!"FIT_Diameter_ABD" %in% names(ZIDat))
@@ -57,15 +464,6 @@
return(invisible(timer))
}
-"realtimeStop" <- function ()
- assignTemp(".realtimeStopItFlag", TRUE)
-
-"realtimeReset" <- function () {
- assignTemp("rtData", NULL)
- assignTemp("rtRecords", NULL)
- assignTemp("rtTime", NULL)
-}
-
"realtimeOptions" <- function (
lstdir = ".", # Path of the list file of the current FlowCAM experiment
ZIClass, # Classifier to use
@@ -732,29 +1130,6 @@
}
}
-"save.loop.res" <- function (lst, Classif, breaks = seq(0.25, 2, by = 0.1),
-conv = c(1, 0, 1), save.dir = NULL) {
- res <- getTemp("rtRecord")
- if (is.null(rec))
- rec <- predict(Classif, read.lst(lst),
- calc.vars = TRUE, class.only = FALSE)
- if (!is.null(save.dir)) {
- if (!is.character(save.dir))
- stop("The exportation path must be a character string")
- } else {
- save.dir <- choose.dir()
- }
- Bio.sample(ZIDat = rec, conv = conv, exportdir = NULL, RealT = TRUE)
- # TODO: what is Bio.tab???
- #write.table(Bio.tab, file = paste(save.dir, paste(basename(dirname(lst)),
- # "AbdBio.txt", sep = "_"), sep = "\\"), sep = "\t", dec = ".",
- # col.names = TRUE, na = "NA", row.names = FALSE)
- # Delete objects from R environment
- rmTemp("rtData")
- rmTemp("rtRecord")
- rmTemp("rtTime")
-}
-
"Volume" <- function (Lst, FlowCell)
{
Height <- (767 - 0) * unique(Lst$FIT_Cal_Const)
Modified: pkg/zooimage/R/ZIClass.R
===================================================================
--- pkg/zooimage/R/ZIClass.R 2010-04-13 16:14:14 UTC (rev 187)
+++ pkg/zooimage/R/ZIClass.R 2010-04-14 17:18:41 UTC (rev 188)
@@ -217,7 +217,7 @@
}
# New function v1.2-2 using library gplots
-"confusion.tree" <- function (confmat, maxval, margin=NULL, Rowv = TRUE,
+"confusion.tree" <- function (confmat, maxval, margin = NULL, Rowv = TRUE,
Colv = TRUE)
{
nX <- nrow(confmat)
@@ -228,8 +228,8 @@
# Note: done in NAMESPACE
# require(RColorBrewer)
# require(gplots)
- mypalette <- brewer.pal(maxval-1, "Spectral")
- heatmap.2(confmat, col= c(0,mypalette), symm = TRUE, margin = margin,
+ mypalette <- brewer.pal(maxval - 1, "Spectral")
+ heatmap.2(confmat, col= c(0, mypalette), symm = TRUE, margin = margin,
trace = "both", Rowv = Rowv, Colv = Colv, cexRow = 0.2 + 1 / log10(nX),
cexCol = 0.2 + 1 / log10(nY), tracecol = "Black", linecol = FALSE)
}
@@ -237,75 +237,68 @@
# New function v 1.2-2 false positive and negative
"confusion.bar" <- function (confmat, mar = NULL)
{
- mustbe(confmat, c("table", "matrix"))
- Nn <- nrow(confmat)
+ if (!inherits(confmat, c("table", "matrix")))
+ stop("'confmat' must be a table or a matrix")
+ TP <- tp <- diag(confmat)
+ fn <- rowSums(confmat) - tp
+ fp <- colSums(confmat) - tp
+ # Express fn and fp in proportions
+ FN <- fn <- fn / (fn + tp)
+ FP <- fp <- fp / (tp + fp)
+ FP[is.na(FP)] <- 1
+ # Rescale values so that:
+ # fn/tp ratio and tp/fp ratio are kept, using same tp
+ # total fn + tp + fp makes 100
+ fp <- tp / (1 - fp) * fp
+ # Rescale all so that they sum to 1
+ scale <- fn + tp + fp
+ fn <- fn / scale * 100
+ tp <- tp / scale * 100
+ fp <- fp / scale * 100
+ # Just in case we have no tp at all:
+ fn[is.na(tp)] <- 50
+ fp[is.na(tp)] <- 50
+ tp[is.na(tp)] <- 0
+ res <- matrix(c(fp, tp, fn), ncol = 3)
+ colnames(res) <- c( "fp", "tp", "fn")
+ # Order items from smallest to largest tp
+ pos <- order(res[, 2], decreasing = TRUE)
+ res <- res[pos, ]
+ FN <- FN[pos]
+ FP <- FP[pos]
+ TP <- TP[pos]
- ## percent of correctly predicted objects in the test set
- pred.tok <- diag(confmat) / colSums(confmat) * 100
-
- # If there are no items good recognize 0/0 = NaN so replace NaN by 0 for
- # calculation
- if (NaN %in% pred.tok)
- pred.tok[pred.tok == "NaN"] <- 0
-
- # Percent of items in the test set predicted in its category
- pred.tfrac <- diag(confmat) / rowSums(confmat) * 100
- pred.tfrac[is.nan(pred.tfrac)] <- 0
- prediction <- cbind(pred.tok, pred.tfrac)
- prediction.df <- data.frame(prediction)
- CR <- prediction[1:Nn, 2]
- FN <- 100 - CR # flase negatives = objects which exist in the test set
- # but not in the training set;
-
- # they are wrongly predicted as not to belong to a particular group
- prediction.df$FN <- FN
-
- #put to scale
- CR2 <- prediction[1:Nn, 1]
- FP <- 100-CR2 # False positives
- prediction.df$FP <- FP
- prediction.df <- round(prediction.df, 0)
- Failure <- prediction.df[c("FN", "FP")]
-
- # Put all data to scale
- allN <- CR + FN # all negative
- allP <- CR2 + FP # all positive
- cr <- (CR / allN) * 100 # % good identify by pc
- cr2 <- (CR2 / allP) * 100 # % good identify by pc
- fn <- (FN / allN) * 100 # percentage of FN
- fp <- (FP / allP) * 100 # percentage of FP
- all <- matrix(c(fn, cr, cr2, fp), ncol = 4)
- colnames(all) <- c( "fn", "cr", "cr2", "fp")
- Order <- order(all[, 2] + all[, 3] , decreasing = TRUE)
- all2 <- t(all[Order, ]) # Transpose the sorted matrix
- Failure <- Failure[Order, ] # Sort failures
- Failure.mat <- as.matrix(Failure)
- Nmat <- ncol(all2)
-
- # Plotting of the data
- valx <- matrix(c(rep(2 , Nmat), rep(198, Nmat)), ncol = 2)
- valx2 <- matrix(c(rep(98, Nmat), rep(102, Nmat)), ncol = 2)
+ # Plot
+ if (is.null(mar)) mar <- c(1.1, 8.1, 4.1, 2.1)
omar <- par("mar")
on.exit(par(omar)) # mar = margin size c(bottom, left, top, right)
par(mar = mar)
- barplot(all2[, !is.na(all2[2, ])], horiz = TRUE,
- col = c("PeachPuff2", "green3", "green3", "lemonChiffon2"),
+ barplot(t(res), horiz = TRUE, col = c("PeachPuff2", "green3", "lemonChiffon2"),
xaxt = "n", las = 1, space = 0)
- text(valx, row(valx) - 0.45, Failure.mat , cex = 0.7)
- text(valx2, row(valx2) - 0.45, 100 - Failure.mat , cex = 0.7)
+ abline(v = (1:9) * 10, lty = 2)
+ abline(v = 50, lwd = 2)
+ # Print the fraction of fp and fn
+ text(rep(4, length(FP)), 1:length(FP) - 0.1,
+ paste(round((1 - FP) * 100), "%", sep = ""),
+ adj = c(1, 1), cex = 0.7)
+ text(rep(99, length(FN)), 1:length(FN) - 0.1,
+ paste(round((1 - FN) * 100), "%", sep = ""),
+ adj = c(1, 1), cex = 0.7)
+
+ # Print the number of true positives
+ xpos <- res[, 1] + res[, 2] / 2
+ text(xpos, 1:length(FN) - 0.1, round(TP),
+ adj = c(0.5, 1), cex = 0.7)
+
# Add a legend
- legend(100, Nmat + (Nmat / 15), legend = c("false negative (FN)",
- "true positive (TP)", "false positive (FP)"),
- xjust = 0.5, fill = c("PeachPuff2", "green3", "lemonChiffon2"),
+ legend(50, length(FN) * 1.05, legend = c("false positive (FP)",
+ "true positive (TP)", "false negative (FN)"),
+ xjust = 0.5, yjust = 1, fill = c("PeachPuff2", "green3", "lemonChiffon2"),
bty = "n", horiz = TRUE)
- legend(100, Nmat / 55, "Percentage", xjust = 0.5, bty = "n")
- segx0 <- rep(c(25, 50, 75, 125, 150, 175), 2)
- segy0 <- rep(c(0, Nmat), c(6, 6))
- segments(segx0[c(1:6)], segy0[c(1:6)], segx0[c(7:12)], segy0[c(7:12)],
- col = "red", lty = 2)
- valx3 <- c(25, 50, 75, 125, 150, 175)
- text(valx3[1:6], -(Nmat / 35), labels = segx0[c(1:3, 7:9)], cex = 0.7)
+ axis(2, 1:length(FN) - 0.5, tick = FALSE, las = 1, cex.axis = 0.7,
+ labels = names(attr(confmat, "nbr.per.class")))
+ title(main = "Precision tp/(tp+fp) at left versus recall tp/(tp+fn) at right")
}
"nnet2" <- function (formula, data, size = 7, rang = 0.1, decay = 5e-4,
Modified: pkg/zooimage/R/gui.R
===================================================================
--- pkg/zooimage/R/gui.R 2010-04-13 16:14:14 UTC (rev 187)
+++ pkg/zooimage/R/gui.R 2010-04-14 17:18:41 UTC (rev 188)
@@ -76,10 +76,6 @@
MenuStateItem("$Tk.ZIDlgWin/Apps", "Image &analyzer (ImageJ)", FALSE)
if (is.null(getOption("ImageViewer")))
MenuStateItem("$Tk.ZIDlgWin/Apps", "Image &viewer (XnView)", FALSE)
- if (is.null(getOption("ZipViewer")))
- MenuStateItem("$Tk.ZIDlgWin/Apps", "&Zip-Zid viewer (Filzip)", FALSE)
- if (is.null(getOption("DVDBurner")))
- MenuStateItem("$Tk.ZIDlgWin/Apps", "CD-DVD &burner (DeepBurner)", FALSE)
if (is.null(getOption("VueScan")))
MenuStateItem("$Tk.ZIDlgWin/Apps", "Simple acquisition (&VueScan)", FALSE)
@@ -143,7 +139,7 @@
# Focus to the active R graph (create one if there is no graph device)
### TODO: notify this command is not available elsewhere (inactivate menu?)
if (is.null(dev.list())) {
- device <- match.fun( getOption("device") )
+ device <- match.fun(getOption("device"))
device()
} else {
# Activate current graph window
@@ -292,9 +288,16 @@
# Did we selected "Another software..."?
if (res == "Another software...") {
# Ask for selecting this software
- Asoft <- choose.files(caption = "Select a program...", multi = FALSE,
- filters = c("Executables (*.exe;*.com;*.bat)", "*.exe;*.com;*.bat"))
- if (Asoft == "") return(invisible()) # Cancelled dialog box
+ if (isWin()) {
+ Asoft <- choose.files(caption = "Select a program...",
+ multi = FALSE, filters = c("Executables (*.exe;*.com;*.bat)",
+ "*.exe;*.com;*.bat"))
+ } else {
+ Asoft <- tk_choose.files(caption = "Select a program...",
+ multi = FALSE)
+ }
+ if (length(Asoft) == 0 || Asoft == "")
+ return(invisible()) # Cancelled dialog box
}
# Did we selected "VueScan"
if (res == "VueScan") {
@@ -320,23 +323,9 @@
# separate 'ZIEimport' objects (see FlowCAM import routine for an example)
# Get a list of 'ZIEimport' objects currently loaded in memory
- ### TODO... Rework everything. What follows is old code!
- ImgFilters <- as.matrix(data.frame(
- title = c(
- "Tiff image files (*.tif)",
- "Jpeg image files (*.jpg)",
- "Zooimage import extensions (Import_*.zie)",
- "Table and ImportTemplate.zie (*.txt)"),
- #, "FlowCAM zipped files (*.zfc)"),
- pattern = c("*.tif", "*.jpg", "Import_*.zie", "*.txt"))) #, "*.zfc")))
+ Images <- selectFile("Img", multi = TRUE, quote = FALSE,
+ title = "Select data to import...")
- # Get last image type that was selected
- Index <- as.numeric(getKey("ImageIndex", "1"))
-
- # Get a list of images
- Images <- choose.files(caption = "Select data to import...",
- multi = TRUE, filters = ImgFilters, index = Index)
-
# Look if there is at least one image selected
if (length(Images) == 0) return(invisible())
dir <- dirname(Images[1])
@@ -507,9 +496,8 @@
# Did we selected "Another config..."?
if (res == "Another config...") {
# Ask for selecting a .zic file containing the config
- otherGrp <- choose.files(caption = "Select a .zic file...",
- multi = FALSE,
- filters = c("ZooImage Classification Scheme (*.zic)", "*.zic"))
+ otherGrp <- selectFile("Zic", multi = FALSE, quote = FALSE,
+ title = "Select a .zic file...")
if (length(otherGrp) == 0 || otherGrp == "") return(invisible())
# Cancelled dialog box
res <- otherGrp
@@ -895,11 +883,17 @@
if (!file.exists(ConvFile) || ConvFile == "")
ConvFile <- file.path(getTemp("ZIetc"), "Conversion.txt")
# Ask for selecting a Conversion file
- ### TODO: use something that also works on other platforms than Windows!
- ConvFile2 <- choose.files(default = ConvFile,
- caption = "Select a conversion file...",
- multi = FALSE, filters = c("Biomass Conversion table (*Conversion.txt)",
- "*Conversion.txt"))
+ if (isWin()) {
+ ConvFile2 <- choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = c("Biomass Conversion table (*Conversion.txt)",
+ "*Conversion.txt"))
+ } else {
+ ConvFile2 <- tk_choose.files(default = ConvFile,
+ caption = "Select a conversion file...",
+ multi = FALSE, filters = matrix(c("Biomass Conversion table",
+ ".txt"), ncol = 2, byrow = TRUE))
+ }
if (length(ConvFile2) == 0 || ConvFile2 == "") return(invisible())
# Cancelled dialog box
# Read the data from this table
@@ -1064,11 +1058,12 @@
"loadObjects" <- function ()
{
- file <- choose.files(caption = "Select a RData file...", multi = FALSE,
- filters = c("R data (*.RData)", "*.RData"))
- if ( is.null(file) || length(file) == 0 || file == "")
- return(invisible()) # Cancelled dialog box
- if (file.exists(file)) load(file, envir = .GlobalEnv)
+ file <- selectFile("RData", multi = FALSE, quote = FALSE,
+ title = "Select a RData file...")
+ if ( is.null(file) || length(file) == 0 || file == "")
+ return(invisible()) # Cancelled dialog box
+ if (file.exists(file))
+ load(file, envir = .GlobalEnv)
}
"saveObjects" <- function ()
@@ -1091,12 +1086,14 @@
"listObjects" <- function ()
{
varlist <- objects(pos = 1)
+ if (length(varlist) == 0)
+ stop("No objects currently loaded in memory!\n")
Filter <- NULL
for (i in 1:length(varlist)) Filter[i] <- inherits(get(varlist[i]),
c("ZIDat", "ZIDesc", "ZITrain", "ZIClass", "ZIRes", "ZIRecode"))
varlist <- varlist[Filter]
if (length(varlist) == 0) {
- cat("No", getTemp("ZIname"), "objects currently loaded in memory!\n")
+ stop("No ", getTemp("ZIname"), " objects currently loaded in memory!\n")
} else {
print(varlist)
}
@@ -1115,10 +1112,8 @@
"calib" <- function ()
{
# Select a calibration file (*.tif or *.pgm) and calculate White/Black point
- ImgFilters <- as.matrix(data.frame(title = c("Tiff image files (*.tif)",
- "Pgm image files (*.pgm)"), pattern = c("*.tif", "*.pgm")))
- file <- choose.files(caption = "Select a calibration image...",
- multi = FALSE, filters = ImgFilters)
+ file <- selectFile("TifPgm", multi = FALSE, quote = FALSE,
+ title = "Select a calibration image...")
if (is.null(file) || length(file) == 0 || file == "")
return(invisible()) # Cancelled
if (file.exists(file)) {
@@ -1206,365 +1201,6 @@
return(res)
}
-
-# TODO: rework all this!!!
-# Functions and dialog box created for the real time recogntion
-"RealT" <- function ()
-{
- # Process real time recognition during a FlowCAM experiment
- # First remove existing file from the global environment before read a new sample
- realtimeReset()
- # Ask for an algorithm and one or several sample to compare
- defval <- "Only One Sample"
- opts <- c("Only One Sample",
- "Comparison with One Other Sample",
- "Comparison with Several Other Samples")
- # Then, show the dialog box
- res <- modalAssistant(paste(getTemp("ZIname"),
- "Real-Time recognition for FlowCAM"),
- c("This is a beta version of the real time recognition",
- "of FlowCAM samples developed for the AMORE III project.",
- "Warning! This method is only developed for FlowCAM data,",
- "and with a classifier made with FlowCAM parameters only.",
- "", "Select an option:", ""), init = defval,
- options = opts, help.topic = "makeClass")
- if (res == "ID_CANCEL") return(invisible())
- # Only one sample
- if (res == "Only One Sample") {
- # Use default values for the classifier creation
- print("You will only recognize in real-time one sample")
-
- # Look if we have a classifier object defined
- ZIC <- getTemp("ZI.ClassName")
- if (is.null(ZIC)) ZIC <- ""
- ZIC <- getVar("ZIClass", multi = FALSE, default = ZIC,
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/zooimage -r 188
More information about the Zooimage-commits
mailing list