//Show-Help-and-Functions macroName = "Show-Help-and-Functions"; macroShortDescription = "This macro writes links (URLs) to the documentation to the log window."; macroDescription = "This macro writes links (URLs) to the documentation to the log window." + "
Copy/paste into web browser to access the function of choise." + "
Check box to open this macro containing all available function now."; macroRelease = "first release 21-012015 by Martin Stöter (stoeter(at)mpi-cbg.de)"; macroHelpURL = "https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Macro-" + macroName; macroHtml = "" +"" + macroName + "\n" + macroRelease + "

" +"" + macroDescription + "

" +"Check for more help on this web page:
" +"" + macroHelpURL + "
" +"...get this URL from Log window!" +""; //start macro Dialog.create("Fiji macro: " + macroName); Dialog.addMessage("Fiji macro: " + macroName + " (Fiji-Tools-for-HCS by TDS@MPI-CBG)\n \n" + macroShortDescription + "\n \nClick 'OK' to go on, 'Cancel' to quit or 'Help' for online description."); Dialog.addHelp(macroHtml); Dialog.show; //////////////////////////////// M A C R O C O D E /////////////////////////////// listedFunctions = newArray("no URL","getFileListSubfolder", "getFolderList", "getFileType", "getFilteredFileList", "setDialogImageFileFilter", "getFilteredList", "getUniqueArrayValues", "getUniqueWellListCV7000"); Dialog.create("Print web links to log window..."); Dialog.addCheckbox("Open all functions as macro?" false); Dialog.addChoice("URLs to functions", listedFunctions, "no URL"); Dialog.show; openMacro = Dialog.getCheckbox; chosenFunction = Dialog.getChoice; if(chosenFunction == "getFileListSubfolder") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Find_all_files_from_folders_and_subfolders_getFileListSubfolder"); } if(chosenFunction == "getFolderList") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Find_all_folders_from_a_folder_getFolderList"); } if(chosenFunction == "getFileType") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Filter_a_list_of_filespaths_for_a_certain_file_extension_getFileType"); } if(chosenFunction == "getFilteredFileList") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Filter_a_list_of_filespaths_for_a_certain_stringtext_inside_the_path_getFilteredFileList"); } if(chosenFunction == "setDialogImageFileFilter") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Opens_a_dialog_window_to_user_define_the_test_filters_setDialogImageFileFilter"); } if(chosenFunction == "getFilteredList") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Filter_a_list_for_a_certain_stringtext_getFilteredList"); } if(chosenFunction == "getUniqueArrayValues") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Find_unique_values_in_list_getUniqueArrayValues"); } if(chosenFunction == "getUniqueWellListCV7000") { print("https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Find_unique_wells_in_file_list_of_CV7000getUniqueWellListCV7000"); } if(openMacro) open(getDirectory("macros") + "Scripts" + File.separator + "Plugins" + File.separator + "TDS macros" + File.separator + "Development" + File.separator + "Macro_Show_Help_And_Functions.ijm"); /* s1 = "This macro demonstrates how to display text in a text window.\n" s2 = "It uses the Plugins>New>Text Window commad to open the window\n" s3 = "if it is not already open. Note that newline characters (backslash-n) \n" s4 = "https://github.com/stoeter/Fiji-Tools-for-HCS/wiki/Useful-Functions-for-Fiji-Macros#Find_unique_wells_in_file_list_of_CV7000getUniqueWellListCV7000\n" requires("1.38m"); title1 = "Text Window"; title2 = "["+title1+"]"; f = title2; if (isOpen(title1)) print(f, "\\Update:"); // clears the window else run("Text Window...", "name="+title2+" width=72 height=8 menu"); print(f, s1); print(f, s2); print(f, s3+s4); */ //set array variables var fileExtension = ".tif"; //pre-definition of extension var filterStrings = newArray("","",""); //pre-definition of strings to filter var availableFilterTerms = newArray("no filtering", "include", "exclude"); //dont change this var filterTerms = newArray("no filtering", "no filtering", "no filtering"); //pre-definition of filter types var displayFileList = false; ///////////////////////////////////////////////////////////////////////////////////////////// //////// F U N C T I O N S ///////////// ///////////////////////////////////////////////////////////////////////////////////////////// var displayFileList = false; //shall array window be shown? //function get all files from folders and subfolders function getFileListSubfolder(inputPathFunction) { fileList = getFileList(inputPathFunction); //read file list Array.sort(fileList); returnedFileList = newArray(0); //this list stores all found files and is returned at the end of the function for (i=0; i < fileList.length; i++) { if ((File.separator == "\\") && (endsWith(fileList[i], "/"))) fileList[i] = replace(fileList[i],"/",File.separator); //fix windows/Fiji File.separator bug if (endsWith(fileList[i], File.separator)) { //if it is a folder returnedFileListTemp = newArray(0); returnedFileListTemp = getFileListSubfolder(inputPathFunction + fileList[i]); returnedFileList = Array.concat(returnedFileList, returnedFileListTemp); } else { //if it is a file returnedFileList = Array.concat(returnedFileList, inputPathFunction + fileList[i]); //print(i, inputPath + fileList[i]); } } if(inputPathFunction == inputPath) { //if local variable is equal to global path variable = if path is folder and NOT subfolder print(returnedFileList.length + " files found in selected folder and subfolders."); if (displayFileList) {Array.show("All files - all",returnedFileList);} } return returnedFileList; } var displayFileList = false; //shall array window be shown? //function get all folders from a folder function getFolderList(inputPathFunction) { fileListFunction = getFileList(inputPathFunction); //read file list Array.sort(fileList); returnedFileList = newArray(0); //this list stores all found files and is returned at the end of the function for (i=0; i < fileList.length; i++) { if ((File.separator == "\\") && (endsWith(fileList[i], "/"))) fileList[i] = replace(fileList[i],"/",File.separator); //fix windows/Fiji File.separator bug if (endsWith(fileList[i], File.separator)) returnedFileList = Array.concat(returnedFileList,fileList[i]);//if it is a folder } print(returnedFileList.length + " folders were found."); if (displayFileList) {Array.show("Found folders",returnedFileList);} return returnedFileList; } var fileExtension = ".tif"; //pre-definition of extension var displayFileList = false; //shall array window be shown? //function finds all files with certain extension function getFileType(fileListFunction) { returnedFileList = newArray(0); //this list stores all files found to have the extension and is returned at the end of the function if(lengthOf(fileExtension) > 0) { for (i = 0; i < fileListFunction.length; i++) { if (endsWith(fileListFunction[i],fileExtension)) returnedFileList = Array.concat(returnedFileList,fileListFunction[i]); } print(returnedFileList.length + " files found with extension " + fileExtension + "."); if (displayFileList) {Array.show("All files - filtered for " + fileExtension, returnedFileList);} } else { returnedFileList = fileListFunction; } return returnedFileList; } var filterStrings = newArray("","",""); //pre-definition of strings to filter var availableFilterTerms = newArray("no filtering", "include", "exclude"); //dont change this var filterTerms = newArray("no filtering", "no filtering", "no filtering"); //pre-definition of filter types var displayFileList = false; //shall array window be shown? //function filter a file list for a certain string function getFilteredFileList(fileListFunction) { skippedFilter = 0; for (i = 0; i < filterStrings.length; i++) { if (filterTerms[i] != availableFilterTerms[0]) { returnedFileList = newArray(0); //this list stores all files found to have the extension and is returned at the end of the function for (j = 0; j < fileList.length; j++) { if (filterTerms[i] == "include" && indexOf(fileList[j],filterStrings[i]) != -1) returnedFileList = Array.concat(returnedFileList,fileListFunction[j]); if (filterTerms[i] == "exclude" && indexOf(fileList[j],filterStrings[i]) <= 0) returnedFileList = Array.concat(returnedFileList,fileListFunction[j]); } print(returnedFileList.length + " files found after filter: " + filterTerms[i] + " text " + filterStrings[i] + "."); if (displayFileList) {Array.show("List of files - after filtering for " + filterStrings[i], returnedFileList);} fileListFunction = returnedFileList; } else skippedFilter++; } if (skippedFilter == filterStrings.length) returnedFileList = fileListFunction; //if no filter condition is selected return returnedFileList; } var fileExtension = ".tif"; //pre-definition of extension var filterStrings = newArray("","",""); //pre-definition of strings to filter var availableFilterTerms = newArray("no filtering", "include", "exclude"); //dont change this var filterTerms = newArray("no filtering", "no filtering", "no filtering"); //pre-definition of filter types var displayFileList = false; //shall array window be shown? //function open dialog to set image file list filter function setDialogImageFileFilter() { Dialog.create("Image file filter..."); //enable use inveractivity Dialog.addMessage("Define the files to be processed:"); Dialog.addString("Files should have this extension:", fileExtension); //add extension Dialog.addMessage("Define filter for files:"); for (i = 0; i < filterStrings.length; i++) { Dialog.addString((i + 1) + ") Filter this text from file list: ", filterStrings[i]); Dialog.addChoice((i + 1) + ") Files with text are included/excluded?", availableFilterTerms, filterTerms[i]); } Dialog.addCheckbox("Check file lists?", displayFileList); //if check file lists will be displayed Dialog.show(); fileExtension = Dialog.getString(); for (i = 0; i < filterStrings.length; i++) { filterStrings[i] = Dialog.getString(); filterTerms[i] = Dialog.getChoice(); } displayFileList = Dialog.getCheckbox(); } var displayList = false; //shall array window be shown? //function filter a list for a certain string (filter) function getFilteredList(inputList, filterStringFunction) { skippedFilter = 0; returnedList = newArray(0); //this list stores all items of the input list that were found to contain the filter string and is returned at the end of the function for (i = 0; i < inputList.length; i++) { if (indexOf(inputList[i],filterStringFunction) != -1) returnedList = Array.concat(returnedList,inputList[i]); } print(returnedList.length + " files found after filtering: " + filterStringFunction); if (displayList) {Array.show("List after filtering for " + filterStringFunction, returnedFileList);} return returnedList; } var displayList = false; //shall array window be shown? //function returnes the unique values of an array function getUniqueArrayValues(inputArray) { outputArray = newArray(inputArray[0]); //outputArray stores unique values, here initioalitaion with first element of inputArray for (i = 1; i < inputArray.length; i++) { j = 0; //counter for outputArray valueUnique = true; //as long as value was not found in array of unique values while (valueUnique && (outputArray.length > j)) { //as long as value was not found in array of unique values and end of array is not reached if(outputArray[j] == inputArray[i]) { valueUnique = false; //if value was found in array of unique values stop while loop } else { j++; } } //end while if (valueUnique) outputArray = Array.concat(outputArray,inputArray[i]); //if value was not found in array of unique values add it to the end of the array of unique values } print(outputArray.length + " unique values found."); if (displayList) {Array.show("List of " + outputArray.length + " unique values", outputArray);} return outputArray; } var displayList = false; //shall array window be shown? //function returnes the unique wells of an array of CV7000 files function getUniqueWellListCV7000(inputArray) { currentWell = substring(inputArray[0],lastIndexOf(inputArray[0],"_T00")-3,lastIndexOf(inputArray[0],"_T00")); //first well found returnedWellList = newArray(currentWell); //this list stores all unique wells found and is returned at the end of the function for (i = 1; i < inputArray.length; i++) { j = 0; //counter for returned well list valueUnique = true; //as long as value was not found in array of unique values while (valueUnique && (returnedWellList.length > j)) { //as long as value was not found in array of unique values and end of array is not reached currentWell = substring(inputArray[i],lastIndexOf(inputArray[i],"_T00")-3,lastIndexOf(inputArray[i],"_T00")); if(returnedWellList[j] == currentWell) { valueUnique = false; //if value was found in array of unique values stop while loop } else { j++; } } //end while if (valueUnique) returnedWellList = Array.concat(returnedWellList, currentWell); //if value was not found in array of unique values add it to the end of the array of unique values } print(returnedWellList.length + " wells found."); if (displayList) {Array.show("List of " + returnedWellList.length + " unique wells", returnedWellList);} return returnedWellList; } //////////////////////////////////////// E N D O F M A C R O ////////////////////////////