Skip to content

Commit

Permalink
Add output of X,Y coordinates of the flagellar track
Browse files Browse the repository at this point in the history
  • Loading branch information
hansenjn committed Oct 30, 2020
1 parent 91b9e9d commit 6272ea4
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 8 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.1-SNAPSHOT</version>
<version>0.2.2-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
11 changes: 8 additions & 3 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.1
SpermQ_.java Version v0.2.2
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -39,7 +39,7 @@ For any questions please feel free to contact me ([email protected]).
public class main implements PlugIn, Measurements{
//Name
static final String PLUGINNAME = "SpermQ_";
static final String PLUGINVERSION = "v0.2.1";
static final String PLUGINVERSION = "v0.2.2";
static final double threshold = 0.70;

//default settings loader
Expand Down Expand Up @@ -1012,7 +1012,7 @@ public void windowClosing(WindowEvent winEvt) {
System.gc();
// tools2D.saveOrientedKymograph(traces, xyCal, savePath, tools2D.NOZ, tools2D.KYMOTANGENTANGLE, 0);
tools2D.saveOrientedKymographAsText(traces, xyCal, savePath, tools2D.NOZ, tools2D.KYMOTANGENTANGLE, 0);
System.gc();
System.gc();

progress.updateBarText("save kymographs and images z ...");

Expand All @@ -1028,6 +1028,11 @@ public void windowClosing(WindowEvent winEvt) {
tools2D.saveOrientedTraceImage(imp, traces, encoding, savePath, xyCal);
System.gc();

progress.updateBarText("save xy coordinates ...");

tools2D.saveXYCoordinates(traces, xyCal, savePath, progress);
System.gc();

//save progress dialog log file
progress.saveLog(dir [task] + saveName + System.getProperty("file.separator") +"log.txt");

Expand Down
134 changes: 132 additions & 2 deletions src/main/java/spermQ/tools2D.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***===============================================================================
SpermQ_.java Version 20190926
SpermQ_.java
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -33,14 +33,14 @@ For any questions please feel free to contact me ([email protected]).
import ij.gui.Roi;
import ij.gui.WaitForUserDialog;
import ij.process.*;
import ij.process.AutoThresholder.Method;
import ij.text.TextPanel;
import ij.measure.*;
import ij.plugin.frame.RoiManager;
import spermQ.edu.emory.mathcs.jtransforms.fft.*;
import spermQ.jnh.support.*;
import spermQ.skeleton_analysis.*;
import spermQ.skeletonize3D.Skeletonize3D_;

public class tools2D implements Measurements{
//encodings
public static final int NOZ = 0,
Expand Down Expand Up @@ -1746,6 +1746,136 @@ public static double getKymoTypeParameter (trackPoint2D p, int type, int encodin
}
}

public static void saveXYCoordinates(ArrayList<trace2D> traces, double calibration, String path, ProgressDialog progress){
//get arc min max and tmax
// double arcLengthMin = Double.POSITIVE_INFINITY;
double arcLengthMax = Double.NEGATIVE_INFINITY;
int tMax = 0;
progress.notifyMessage("Create XY Coordinate lists: nr of timepoints to save: " + traces.size(), ProgressDialog.LOG);
for(int i = 0; i < traces.size(); i++){
// if(!traces.get(i).oriented) continue;
if(traces.get(i).getTracePoints().size() <= 0){
progress.notifyMessage("Create XY Coordinate lists: trace " + i + " harbors 0 points", ProgressDialog.LOG);
continue;
}
if(traces.get(i).getFrame() > tMax){
tMax = traces.get(i).getFrame();
}

for(int j = 0; j < traces.get(i).getTracePoints().size(); j++){
if(traces.get(i).getTracePoints().get(j).getArcLengthPos() > arcLengthMax){
arcLengthMax = traces.get(i).getTracePoints().get(j).getArcLengthPos();
}
// if(traces.get(i).getTracePoints().get(j).getArcLengthPos() < arcLengthMin){
// arcLengthMin = traces.get(i).getTracePoints().get(j).getArcLengthPos();
// }
}
}

progress.notifyMessage("Create XY Coordinate lists: arc length maximum: " + constants.dfdialog.format(arcLengthMax), ProgressDialog.LOG);

//save all
double values [][] = new double [(int)Math.round(arcLengthMax / calibration)+1][2];
TextPanel tp = new TextPanel("Results");
String appText = "";
//save X
{
tp.clear();
tp.append("time arc length (micron)");
appText = "";
for(int a = 0; a < (int)Math.round(arcLengthMax / calibration)+1; a++){
appText += " " + constants.df3US.format(a*calibration);
}
tp.append(appText);

for(int i = 0; i < traces.size(); i++){
appText = "" + i;
if(traces.get(i).getTracePoints().size() <= 0){ //!traces.get(i).oriented ||
tp.append(appText);
continue;
}
// && Double.isNaN(traces.get(i).getThetaDegree(encoding))==false

for(int a = 0; a < (int)Math.round(arcLengthMax / calibration)+1; a++){
values [a][0] = 0.0;
values [a][1] = 0.0;
}

for(int j = 0; j < traces.get(i).getTracePoints().size(); j++){
try{
values[(int)Math.round(traces.get(i).getTracePoints().get(j).getArcLengthPos() / calibration)][0]
+= traces.get(i).getTracePoints().get(j).getX();
values[(int)Math.round(traces.get(i).getTracePoints().get(j).getArcLengthPos() / calibration)][1] += 1.0;
}catch (Exception e){
IJ.log("T" + i + ": problem in kymograph generation..." + " j" + j + " - "
+ (int)Math.round(traces.get(i).getTracePoints().get(j).getArcLengthPos() / calibration) + " length " + values.length);
}
}

for(int a = 0; a < (int)Math.round(arcLengthMax / calibration)+1; a++){
// IJ.log("j " + j + " i " + i + "xyz" + xyz + " enc " + encoding);
// IJ.log("al " + points.get(j).getArcLengthPos());
// IJ.log("al " + (int)Math.round(points.get(j).getArcLengthPos() * resolution));
// IJ.log("corrI " + getCorrectedIntensity8bit (points.get(j).getOrientedVector(encoding)[xyz], min, max));
appText += " ";
if(values[a][1]>0.0){
appText += constants.df6US.format(values[a][0]/values[a][1]);
}
}
tp.append(appText);
}
tools2D.addFooter(tp);
tp.saveAs(path + "_coordX.txt");
}

//save Y
{
tp.clear();
tp.append("time arc length (micron)");
appText = "";
for(int a = 0; a < (int)Math.round(arcLengthMax / calibration)+1; a++){
appText += " " + constants.df3US.format(a*calibration);
}
tp.append(appText);

for(int i = 0; i < traces.size(); i++){
appText = "" + i;
if(traces.get(i).getTracePoints().size() <= 0){ //!traces.get(i).oriented ||
tp.append(appText);
continue;
}
// && Double.isNaN(traces.get(i).getThetaDegree(encoding))==false

for(int a = 0; a < (int)Math.round(arcLengthMax / calibration)+1; a++){
values [a][0] = 0.0;
values [a][1] = 0.0;
}

for(int j = 0; j < traces.get(i).getTracePoints().size(); j++){
try{
values[(int)Math.round(traces.get(i).getTracePoints().get(j).getArcLengthPos() / calibration)][0]
+= traces.get(i).getTracePoints().get(j).getY();
values[(int)Math.round(traces.get(i).getTracePoints().get(j).getArcLengthPos() / calibration)][1] += 1.0;
}catch (Exception e){
IJ.log("T" + i + ": problem in kymograph generation..." + " j" + j + " - "
+ (int)Math.round(traces.get(i).getTracePoints().get(j).getArcLengthPos() / calibration) + " length " + values.length);
}
}

for(int a = 0; a < (int)Math.round(arcLengthMax / calibration)+1; a++){
appText += " ";
if(values[a][1]>0.0){
appText += constants.df6US.format(values[a][0]/values[a][1]);
}
}
tp.append(appText);
}
tools2D.addFooter(tp);
tp.saveAs(path + "_coordY.txt");
}

}

public static void saveOrientedKymographAsText(ArrayList<trace2D> traces, double calibration, String path, int encoding, int kymoType, int excludeHeadPoints){
double min = getKymographMin(kymoType), max = getKymographMax(kymoType);
String xyzText = getKymographTxtLabel(kymoType);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugins.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
# Name: SpermQ

# Author: Jan Niklas Hansen <[email protected]>
# Version: 0.2.1
# Version: 0.2.2
# Date: 2016/11/14
# Requires: ImageJ

Plugins>JNH>Analysis, "SpermQ v0.2.1", spermQ.main
Plugins>JNH>Analysis, "SpermQ v0.2.2", spermQ.main

0 comments on commit 6272ea4

Please sign in to comment.