我在ImageJ mailing list 上问了这个问题。用户 Joost Willemse 对形成我的最终宏非常有帮助。这是完整的宏:
dir=getDirectory("Choose a Directory");
list = getFileList(dir);
Array.sort(list);
for (i=0; i<list.length; i+=3) {
open(list[i]);
blue=getTitle;
open(list[i+1]);
green=getTitle;
open(list[i+2]);
red=getTitle;
run("JACoP ", "imga="+red+" imgb="+blue+" thra=648 thrb=517 pearson mm");
run("JACoP ", "imga="+red+" imgb="+green+" thra=648 thrb=517 pearson mm");
run("JACoP ", "imga="+blue+" imgb="+green+" thra=648 thrb=517 pearson mm");
close(red);
close(green);
close(blue);
}
设置目录后,for循环开始。 i+=3 让迭代器以三步为单位计数(当我问这个问题时,我不知道这是可能的)!现在打开三个图像中的每一个,并保存它们的标题。最后,标题通过连接发送到run() 函数的字符串部分。然后图像被关闭。只要您的列表在开始之前在目录中正确排序,就可以正常工作。 确保在run() 函数中为 JACoP 设置阈值!!
此外,我在 R 中使用 grep() 和 gsub() 从日志中删除了系数值。这不是最有效的方法,但它可以完成工作。对于从日志文件中提取的任何内容,您可以根据需要修改此代码:
# This function takes the path to the log file. It then removes the Pearson's Coefficent, Manders M1/M2, and thresholded Manders M1/M2. It then gathers them into a table.
extract <- function(data){
dat <- read.table(data, header = FALSE, sep = "", fill = TRUE, stringsAsFactors = FALSE)
dat <- dat[ , "V1"]
coef <- dat[grep(pattern = "=", dat)]
coef <- as.numeric(gsub("r=|M1=|M2=", "",coef))
coef <- split(coef, ceiling(seq_along(coef)/5))
coef <- do.call(rbind.data.frame, coef)
names(coef) <- c("r", "M1", "M2", "M1(T)", "M2(T)")
coef <- cbind(Value = c("Red/Blue", "Red/Green", "Blue/Green"), coef)
return(coef)
}
请注意,coef <- as.numeric(gsub("r=|M1=|M2=", "",coef)) 需要根据您从日志文件中提取的内容进行修改。 coef <- split(coef, ceiling(seq_along(coef)/5)) 也是如此 - 将 5 更改为日志文件报告的内容数。
# Now just split the table into a list for each of the different analysis combinations fed into JACoP. Here I assume you set the output of the extract function to "dat".
output <- split(dat, dat$Value)
输出是输入宏的每个图像的所有分析值列表,除以所分析的不同 JACoP 颜色通道。例如:
$`Red/Blue`
Value r M1 M2 M1(T) M2(T)
Red/Blue 0.743871077 0.395698602 0.963246489 0.513951407 0.700130944
Red/Blue 0.460021089 0.605613993 0.456788982 0.125648321 0.424468211
Red/Blue 0.967115553 0.357528694 0.767577893 0.073250688 0.720399867
$`Red/Green`
Value r M1 M2 M1(T) M2(T)
Red/Green 0.79367778 0.36556424 0.722980958 0.487698812 0.381559727
Red/Green 0.262211518 0.063695185 0.653330753 0.276610328 0.132548249
Red/Green 0.483240639 0.348516661 0.961846834 0.832706515 0.356203613
$`Blue/Green`
Value r M1 M2 M1(T) M2(T)
Blue/Green 0.549159913 0.834823152 0.389143503 0.655878106 0.446664812
Blue/Green 0.144388419 0.844781823 0.534304211 0.79041495 0.844326066
Blue/Green 0.805481028 0.344139017 0.490682901 0.246814106 0.641006611