You are viewing a read-only archive of the Blogs.Harvard network. Learn more.

Macros Done!

ø

Well. Another somewhat slow day, but not without progress. Managed to hash out the remainder of the ImageJ portion of the measurement interface. It seems to be quite reliably making measurements, with the intervening calculations of area, and writing them successfully to the “pipe” file—all the while keeping track of the measurement number to facilitate easy reference to the image displayed by the R portion of the interface. Huzzah!

Here the product of the last two days’ work—embarrassing though it may be that it took so long, I’m proud that it seems to work. Many may have been able to do it faster, but far more would not have been able to do it at all…

//Macros to collect radiolarian morphometric measurements for acquisition
//to the RadData database, via its R interface.
//Written by Ben Kotrc, Mar 1st, 2011
//Declare global variables
//Measurement number (in reference to R interface image)
var counter = 0;
//Microscope magnification (e.g. 16x, 40x, etc)
var objective = “??x.”;
//Macro to write all measurements of type “Length” taken since the last
//file write operation, with the current image file name, to the pipe file
macro “Save linear measurements to file [1]” {
//Get name of currently open image file
curfname=getInfo(“image.filename”);
//Loop through each row in the Results table
for (i=counter; i<nResults; i++){
//Extract the ith row from the “Length” column of the Results table
measurement = getResult(“Length”, i);
//Concatenate row of data to be appended to pipe file (data + filename)
insertion = d2s(measurement,2) + “\t” + curfname;
//Append the ith measurement to the Results table
File.append(insertion, “/Users/Ben/Dropbox/Harvard/By-Lineage\ Rads/RadData\ Database/pipefilename.txt”);
//Increment the measurement counter
counter++;
}
//Display in log window how many measurements have been written to file
print(“\\Clear”);
print(“Scale set to ” + objective + “.”);
print(d2s(counter,0) + ” measurements recorded to file.”);
}
//Macro to calculate the pore area proportion from the measurements added
//to the results table since the last file write operation, then write the
//number to file with the current image file name
macro “Save area measurement to file [2]” {
//Get name of currently open image file
curfname=getInfo(“image.filename”);
//Find the sum of all but the first row in the Results table
sum=0;
for (i=counter+1; i<nResults; i++){
sum = sum + getResult(“Area”,i);
}
//Find the pore area proportion
measurement = sum/getResult(“Area”,counter);
//Concatenate row of data to be appended to pipe file (data + filename)
insertion = d2s(measurement,4) + “\t” + curfname;
//Append the result to file
File.append(insertion, “/Users/Ben/Dropbox/Harvard/By-Lineage\ Rads/RadData\ Database/pipefilename.txt”);
//Increment the measurement counter
counter++;
//Display in log window how many measurements have been written to file
print(“\\Clear”);
print(“Scale set to ” + objective + “.”);
print(d2s(counter,0) + ” measurements recorded to file.”);
//Tidy up the Results table
IJ.deleteRows(counter,nResults-1);
setResult(“Area”,counter-1,measurement);
}
//Macro to insert a zero-valued measurement to the pipe file, and update
//the ImageJ results table accordingly
macro “Add zero measurement to file [3]” {
measurement = 0;
curfname = “No file”;
//Concatenate row of data to be appended to pipe file (data + filename)
insertion = d2s(measurement,4) + “\t” + curfname;
//Append the result to file
File.append(insertion, “/Users/Ben/Dropbox/Harvard/By-Lineage\ Rads/RadData\ Database/pipefilename.txt”);
//Update Results table to reflect added zero “measurement”
setResult(“Area”, counter, 0);
//Increment the measurement counter
counter++;
//Display in log window how many measurements have been written to file
print(“\\Clear”);
print(“Scale set to ” + objective + “.”);
print(d2s(counter,0) + ” measurements recorded to file.”);
}
//Macro to reset the tally of the number of measurements written to file,
//as displayed in the log window, to zero (use each time a new individual
//is started)
macro “Reset measurement counter [4]” {
//Clear the Results table
selectWindow(“Results”);
run(“Close”);
//Reset counter
counter = 0;
//Display in log window
print(“\\Clear”);
print(“Scale set to ” + objective + “.”);
print(d2s(counter,0) + ” measurements recorded to file.”);
}
\\Macro to set the appropriate scale for different microscope objectives
macro “Set magnification… [5]” {
Dialog.create(“Set magnification”);
Dialog.addChoice(“Objective:”, newArray(“16x”, “40x”, “80x”, “100x”));
Dialog.show();
objective = Dialog.getChoice();
if (objective == “16x”) {
run(“Set Scale…”, “distance=1190 known=26.3 pixel=1 unit=µm”);
} else if (objective == “40x”){
run(“Set Scale…”, “distance=1190 known=26.3 pixel=1 unit=µm”);
} else if (objective == “80x”){
run(“Set Scale…”, “distance=1190 known=26.3 pixel=1 unit=µm”);
} else if (objective == “1000x”){
run(“Set Scale…”, “distance=1190 known=26.3 pixel=1 unit=µm”);
}
//Print new magnification in log window, along with # of measurements taken
print(“\\Clear”);
print(“Scale set to ” + objective + “.”);
print(d2s(counter,0) + ” measurements recorded to file.”);
}
Well, that was fun, but now it’s time to move on and figure out how to parse the measurements this script writes to file into R and, in swift succession, into SQL queries that can shuttle the measurements safely into the database.
previous:
Micro Macro Steps
next:
Tying the Interface Together

Comments are closed.