0

I have been using the Roi-Group Table plugin, which i have cited at the bottom of this post.

I am writing a macro and need to get the number of groups that were entered into the plugin, so that I may enter them into a loop that sequentially leads the user through tracing cells belonging to each group. So far, I have been able to implement a dialog box that asks the user how many cell types they entered into the ROI-Group table plugin. Then, the macro leads the user through tracing each cell type. In addition, I have tried exporting the group names into a txt file, then putting them into an array and reading the number of objects in the array. Getting them into an array was successful, but reading the amount of objects was not.

This is the first thing that I tried:

/*

Dialog.create(“How many cell types do you have?”); Dialog.addNumber(“No. cells:”, 8); Dialog.show(); numberGroups = Dialog.getNumber();

for (i=0; i<=numberGroups; i++){ run(“Roi Defaults…”, “color=red stroke=0 group=i”); waitForUser(“Leave dialog open until you finish tracing. Click ‘OK’ only when ready to move to next cell type”); } */

A dialog box showed up asking me how many groups I had, which I entered manually. The loop then led the user through tracing each cell type (group) chronologically, as expected. The good thing about this is that the loop works the way I want it to. The bad thing about this is that I do not want the numberGroups variable to be collected through the dialog box. Instead, I would like a way to acquire it from the software. I am trying to avoid manual entry.

In an attempt to collect the number of groups from the software, I tried to create an array from the cell types I had saved and exported from the Roi-Group Table plugin (this is what file I am opening). Then, I wanted to measure the length of the array (how many groups were listed in the file). The second step is where I got stuck. The code for this part is posted below:

/*

groupNames = File.openAsString(“/Users/sharondaniel/Volumes/SEAGATE/Mating ROI Manager.txt”); groupNames = newArray(groupNames); Array.print(groupNames); Array.copy(groupNames); */

When I print the array, I get the group names: "Reference Intensity,Background Intensity,GSC,Phase 1 Gb,Phase 2 Gb,Released Gb,2 CC,4-8 CC"

I have not been able to find any function/macro that can read the number of objects/length in the array. It would be very useful to me if someone could point me towards such a function/macro.

If measuring array length was successful, then I would get rid of the dialog box in the first macro and replace it with the new code, storing the length of the array as the new numberGroups variable.

Any feedback is appreciated! Also, this is my first post here so if there is anything I can do to make better/more useful posts, please let me know!

ROI-Group Table plugin: ( Thomas, L. (2020). LauLauThom/RoiGroupTable: ImageJ/Fiji RoiGroup Table (Version 1.0). Zenodo.[ doi:10.5281/ZENODO.4279048]

  • Regarding the length (number of items) "n" of an array named "A" in ImageJ-macro language, it's simply the Java-style n=A.length. – Herbie Jun 09 '23 at 08:19
  • @Herbie, that function does not exist for the IJM language. Instead, I use this: n = lengthof(A) – Sharon Daniel Jun 12 '23 at 14:34
  • Update (1): I tried to create an array out of the .txt file generated by the ROI-Group table plugin then print and measure the length of the array. I used the following code: groupNames = newArray(File.openAsString("/Users/sharondaniel/Volumes/SEAGATE/Mating ROI Manager.txt")); Array.print(groupNames); print("length of groupNames: " + lengthOf(groupNames)); The output was as follows:
    Reference Intensity,Background Intensity,GSC,Phase 1 Gb,Phase 2 Gb,Released Gb,2 CC,4-8 CC,new group length of groupNames: 1
    – Sharon Daniel Jun 12 '23 at 14:46
  • Update (2): I then tried to parse the array using the split function in ImageJ. It was unsuccessful. The code is as follows: groupNames = File.openAsString("/Users/sharondaniel/Volumes/SEAGATE/Mating ROI Manager.txt"); split(groupNames, ","); groupNamesSplit = newArray(groupNames); Array.print(groupNamesSplit); print("group length:" + lengthOf(groupNamesSplit)); The output is as follows: Reference Intensity,Background Intensity,GSC,Phase 1 Gb,Phase 2 Gb,Released Gb,2 CC,4-8 CC,new group group length:1 – Sharon Daniel Jun 12 '23 at 14:50
  • I have been given the solution from another forum. This is it: groupNames = File.openAsString("/Users/sharondaniel/Volumes/SEAGATE/Mating ROI Manager.txt"); splitGroupNames = split(groupNames, ","); Array.print(splitGroupNames); print("length of splitGroupNames: " + lengthOf(splitGroupNames)); With the following output: Reference Intensity, Background Intensity, GSC, Phase 1 Gb, Phase 2 Gb, Released Gb, 2 CC, 4-8 CC, new group length of splitGroupNames: 9 – Sharon Daniel Jun 12 '23 at 15:02
  • n=lengthOf(A) returns the length of a string (the number of chars), not the number of items of an array. n=A.length returns the number of items of array A and definitely works in the ImageJ-maco language. – Herbie Jun 22 '23 at 10:43

0 Answers0