Skip to content

Commit

Permalink
Customize Summary File Path
Browse files Browse the repository at this point in the history
Adding an option to customize the file path at which the summary text file is saved after processing all images.
  • Loading branch information
hansenjn committed Jun 30, 2023
1 parent 464def8 commit 9bfb15a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>SpermQ_</artifactId>
<version>0.2.3-SNAPSHOT</version>
<version>0.2.4-SNAPSHOT</version>
<groupId>JNH</groupId>
<description>An ImageJ plugin to analyze the flagellar beat of sperm and sperm steering. Copyright (C) 2017-2020: Jan N. Hansen, Sebastian Rassmann, Jan F. Jikeli, and Dagmar Wachten; research group Biophysical Imaging, Institute of Innate Immunity, Bonn, Germany (http://www.iii.uni-bonn.de/en/wachten_lab/). Funding: DFG priority program SPP 1726 &quot;Microswimmers&quot;. This software is part of the following publication: https://www.mdpi.com/2073-4409/8/1/10.</description>

Expand Down
73 changes: 62 additions & 11 deletions src/main/java/spermQ/main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***===============================================================================
SpermQ_.java Version v0.2.3
SpermQ_.java Version v0.2.4
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand All @@ -13,7 +13,7 @@ as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.tx
See the GNU General Public License for more details.
Copyright (C) 2016 - 2022: Jan N Hansen and Jan F Jikeli
Copyright (C) 2016 - 2023: Jan N Hansen and Jan F Jikeli
For any questions please feel free to contact me (jan.hansen@uni-bonn.de).
Expand All @@ -39,7 +39,7 @@ For any questions please feel free to contact me (jan.hansen@uni-bonn.de).
public class main implements PlugIn, Measurements{
//Name
static final String PLUGINNAME = "SpermQ_";
static final String PLUGINVERSION = "v0.2.3";
static final String PLUGINVERSION = "v0.2.4";
static final double threshold = 0.70;

//default settings loader
Expand Down Expand Up @@ -98,6 +98,12 @@ public class main implements PlugIn, Measurements{

@Override
public void run(String arg) {
// Initialize home path
String homePath = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
if(System.getProperty("os.name").toUpperCase().contains("MAC")){
homePath += System.getProperty("file.separator") + "Desktop";
}

/**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Load Default Settings
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
Expand Down Expand Up @@ -395,6 +401,11 @@ else if(selectedDSL.equals(selectionsDSL[14]) || selectedDSL.equals(selectionsDS
gd.setInsets(0,0,0); gd.addNumericField("FFT: Grouped consecutive time-steps", groupedTimesteps, 0);
gd.setInsets(0,0,0); gd.addNumericField("FFT: Do not analyze initial ... µm from head", neglectedInitialArclength, 0);
gd.setInsets(0,0,0); gd.addNumericField("Head rotation matrix radius", hrPlusMinusRange, 0);

gd.setInsets(10,0,0); gd.addMessage("Output of summary file", constants.BoldTxt);
gd.setInsets(-3,0,0); gd.addMessage("In the field below you may, if needed, adapt the file path where the file summarizing results for all analyzed images will be stored.", constants.PlTxt);
gd.setInsets(-3,0,0); gd.addStringField("File path for output of the summary txt-file: ", homePath, 30);


gd.showDialog();

Expand Down Expand Up @@ -424,6 +435,7 @@ else if(selectedDSL.equals(selectionsDSL[14]) || selectedDSL.equals(selectionsDS
groupedTimesteps = (int) gd.getNextNumber();
neglectedInitialArclength = (double) gd.getNextNumber();
hrPlusMinusRange = (int) hrPlusMinusRange;
homePath = gd.getNextString();

if (gd.wasCanceled())return;
}
Expand Down Expand Up @@ -499,12 +511,33 @@ public void windowClosing(WindowEvent winEvt) {
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/

//Initialize
ImagePlus imp;
String homePath = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
if(System.getProperty("os.name").toUpperCase().contains("MAC")){
homePath += System.getProperty("file.separator") + "Desktop";
ImagePlus imp;

//Checking for existing saving path for the summary
if(!new File(homePath).exists()) {
while(true) {
GenericDialog gd = new GenericDialog(PLUGINNAME);
// setInsets(top, left, bottom)
gd.setInsets(0,0,0); gd.addMessage(PLUGINNAME + ", version " + PLUGINVERSION + " (\u00a9 2013-" + constants.dateY.format(new Date()) + ", JF Jikeli \u0026 JN Hansen)", constants.Head1);

gd.setInsets(10,0,0); gd.addMessage("The path for saving the summary file does not exist.", constants.PlTxt);
gd.setInsets(0,0,0); gd.addMessage("Correct the path in the box below or enter an existing path for storing the summary file.", constants.PlTxt);

gd.setInsets(10,0,0); gd.addStringField("File path for saving the summary file: ", homePath, 30);

gd.showDialog();

homePath = gd.getNextString();

if (gd.wasCanceled()) return;

if(new File(homePath).exists()) {
break;
}
}
}


//get head selections
Roi [] selections = new Roi [tasks];
if(tethered){
Expand Down Expand Up @@ -977,8 +1010,16 @@ public void windowClosing(WindowEvent winEvt) {
+ " " + constants.df6US.format(freqSummaryCAngle [task][2][2]));


tools2D.addFooter(tp);
tp.saveAs(dir [task] + saveName + System.getProperty("file.separator") + "results.txt");
tools2D.addFooter(tp);
try {
tp.saveAs(dir [task] + saveName + System.getProperty("file.separator") + "results.txt");
}catch(Exception e) {
String out = "";
for(int err = 0; err < e.getStackTrace().length; err++){
out += " \n " + e.getStackTrace()[err].toString();
}
progress.notifyMessage("Failed to write the file path " + dir [task] + saveName + System.getProperty("file.separator") + "results.txt" + " .\nAn error occured:\n" + out, ProgressDialog.ERROR);
}

//save selection
rm = RoiManager.getInstance();
Expand Down Expand Up @@ -1314,10 +1355,20 @@ public void windowClosing(WindowEvent winEvt) {
}
}
tools2D.addFooter(tp);
tp.saveAs(homePath + System.getProperty("file.separator") + "SpermQ_Summary_" + constants.dateName.format(new Date()) + ".txt");

try {
tp.saveAs(homePath + System.getProperty("file.separator") + "SpermQ_Summary_" + constants.dateName.format(new Date()) + ".txt");
}catch(Exception e) {
String out = "";
for(int err = 0; err < e.getStackTrace().length; err++){
out += " \n " + e.getStackTrace()[err].toString();
}
progress.notifyMessage("Failed to save the file " + homePath + System.getProperty("file.separator") + "SpermQ_Summary_" + constants.dateName.format(new Date()) + ".txt " + " due to an error:\n" + out, ProgressDialog.ERROR);
}

System.gc();
done = true;
new WaitForUserDialog("All tasks have been processed. A summary file has been saved on the desktop!").show();
new WaitForUserDialog("All tasks have been processed. A summary file has been saved at\n" + homePath + "!").show();
}
}
}
8 changes: 4 additions & 4 deletions src/main/resources/plugins.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# #%L
# SpermQ_ plugin for ImageJ.
# %%
# Copyright (C) 2016-2022 Jan Niklas Hansen and Jan F Jikeli.
# Copyright (C) 2016-2023 Jan N. Hansen and Jan F Jikeli.
# %%
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
Expand All @@ -21,9 +21,9 @@
###
# Name: SpermQ

# Author: Jan Niklas Hansen <Jan.Hansen@uni-bonn.de>
# Version: 0.2.3
# Author: Jan N. Hansen <Jan.Hansen@uni-bonn.de>
# Version: 0.2.4
# Date: 2016/11/14
# Requires: ImageJ

Plugins>JNH>Analysis, "SpermQ v0.2.3", spermQ.main
Plugins>JNH>Analysis, "SpermQ v0.2.4", spermQ.main

0 comments on commit 9bfb15a

Please sign in to comment.