ini.trakem2.analysis
Class Compare

java.lang.Object
  extended by ini.trakem2.analysis.Compare

public class Compare
extends java.lang.Object


Nested Class Summary
static class Compare.CATAParameters
          Compare all to all parameters.
static class Compare.Chain
          Represents a list of concatenated pipes, where each pipe is parent of the next within the ProjectTree.
 
Field Summary
static int AVG_PHYS_DIST
           
static int COMBINED
           
static int COMBINED_SCORE_INDICES
           
static int CUM_PHYST_DIST
           
static int DISSIMILARITY
           
static int LEVENSHTEIN
           
static int MEDIAN_PHYS_DIST
           
static int PROXIMITY
           
static int PROXIMITY_MUT
           
static int STD_DEV
           
static int STD_DEV_ALL
           
static int TRANS_ROT
           
static int TRANS_ROT_SCALE
           
static int TRANS_ROT_SCALE_SHEAR
           
static double[] W
           
 
Method Summary
static Bureaucrat compareAllToAll(boolean to_file, java.lang.String regex, java.lang.String[] ignore, Project[] projects)
           
static Bureaucrat compareAllToAll(boolean to_file, java.lang.String regex, java.lang.String[] ignore, Project[] projects, boolean crop, boolean from_end, int max_n_elements, java.lang.String outgroup)
          Gets pipes for all open projects, and generates a matrix of dissimilarities, which gets passed on to the Worker thread and also to a file, if desired.
static VectorString3D condense(Compare.CATAParameters cp, VectorString3D[] vs, Worker worker)
          Do an all-to-all distance matrix of the given vs, then do a neighbor joining, do a weighted merge of the two VectorString3D being merged, and then finally output the resulting condensed unique VectorString3D with its source array full with all points that make each point in it.
static javax.vecmath.Vector3d[] createOrigin(VectorString3D x, VectorString3D y, VectorString3D z, int transform_type)
          Returns an array of 4 Vector3d: the three unit vectors in the same order as the vector strings, and the origin of coordinates.
static javax.vecmath.Vector3d[] createOrigin(VectorString3D x, VectorString3D y, VectorString3D z, int transform_type, javax.vecmath.Vector3d[] o_ref)
           
static java.util.ArrayList<Compare.Chain> createPipeChains(ProjectThing root_pt, LayerSet ls)
          For a given pipe, create a VectorString3D for each possible path, as determined by the Project Tree structure and the parent/child relationships.
static java.util.ArrayList<Compare.Chain> createPipeChains(ProjectThing root_pt, LayerSet ls, java.lang.String regex_exclude)
           
static javax.media.j3d.Transform3D createTransform(javax.vecmath.Vector3d[] o)
          Creates a transform with the 4 given vectors: X, Y, Z and translation of origin.
static java.util.Map<java.lang.String,javax.vecmath.Tuple3d> extractPoints(ProjectThing fiducial)
          Extracts the list of fiduciary points from the fiducial parent and, if their name is different than "ball", adds their title as key and their first ball as a fiduciary point value of the returned map.
protected static java.lang.Object[] findBestMatch(VectorString3D vs1, VectorString3D vs2, double delta, boolean skip_ends, int max_mut, float min_chunk)
           
protected static java.lang.Object[] findBestMatch(VectorString3D vs1, VectorString3D vs2, double delta, boolean skip_ends, int max_mut, float min_chunk, int distance_type, boolean direct, boolean substring_matching)
          Since comparing two sequences starting from one end or starting from the other is not the same at all, this method performs the match starting first from one end and then from the other.
static java.lang.Object[] findBestMatch(VectorString3D vs1, VectorString3D vs2, double delta, boolean skip_ends, int max_mut, float min_chunk, int distance_type, boolean direct, boolean substring_matching, double wi, double wd, double wm)
           
static java.lang.Object[] gatherChains(Project[] p, Compare.CATAParameters cp)
           
static java.lang.Object[] gatherChains(Project[] p, Compare.CATAParameters cp, java.lang.String[] ignore)
          Gather chains for all projects considering the cp.regex, and transforms all relative to the reference Project p[0].
static double[] makeEnvelope(Compare.CATAParameters cp, VectorString3D c)
          From a condensed VectorString3D, create the radius at each point.
static ij.gui.Plot makePlot(Compare.CATAParameters cp, java.lang.String name, VectorString3D c)
           
static java.lang.Object[] obtainOrigin(Line3D[] axes, int transform_type, javax.vecmath.Vector3d[] o_ref)
          Generate calibrated origin of coordinates.
static Bureaucrat reliabilityAnalysis(java.lang.String[] ignore)
          Reliability analysis of pipe comparisons: compares all to all, recording the score position of homonimous pipes in other projects.
static Bureaucrat reliabilityAnalysis(java.lang.String[] ignore, boolean output_arff, boolean weka_classify, boolean show_dialog, double delta, double wi, double wd, double wm)
           
static Bureaucrat reliabilityAnalysisSpaceExploration(java.lang.String[] ignore)
           
static double score(double seq_sim, double levenshtein, double median_phys_dist, double[] w)
           
static float[][] scoreAllToAll(VectorString3D[] vs, int distance_type, double delta, boolean skip_ends, int max_mut, float min_chunk, boolean direct, boolean substring_matching, Worker worker)
          Returns the half matrix of scores, with values copied from one half matrix to the other, and a diagonal of zeros.
static void testCreateOrigin(LayerSet ls, VectorString3D vs1, VectorString3D vs2, VectorString3D vs3)
           
static java.util.List<VectorString3D> transferVectorStrings(java.util.List<VectorString3D> vs, java.util.List<javax.vecmath.Tuple3d> source, java.util.List<javax.vecmath.Tuple3d> target, java.lang.Class<mpicbg.models.AffineModel3D> model_class)
          Transform all points of all VectorString3D in vs using a Moving Least Squares Transform defined by the pairing of points in source to those in target.
static java.util.List<VectorString3D> transferVectorStrings(java.util.List<VectorString3D> vs, java.util.Map<java.lang.String,javax.vecmath.Tuple3d> source, java.util.Map<java.lang.String,javax.vecmath.Tuple3d> target)
          Transfer vs via a moving least squares transform by matching source named points into equally named target named points.
static java.util.List<VectorString3D> transferVectorStrings(java.util.List<VectorString3D> vs, ProjectThing source_fiduciary, ProjectThing target_fiduciary)
           
static Bureaucrat variabilityAnalysis(Project reference_project, java.lang.String regex, java.lang.String[] ignore, boolean show_cata_dialog, boolean generate_plots, boolean show_plots, java.lang.String plot_dir_, boolean show_3D, boolean show_condensed_3D, boolean show_sources_3D, java.util.Map<Project,java.awt.Color> sources_color_table, boolean show_envelope_3D, float envelope_alpha, double delta_envelope, int envelope_type, boolean show_axes_3D, boolean heat_map, java.util.Map<java.lang.String,VectorString3D> map_condensed, Project[] projects)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANS_ROT

public static final int TRANS_ROT
See Also:
Constant Field Values

TRANS_ROT_SCALE

public static final int TRANS_ROT_SCALE
See Also:
Constant Field Values

TRANS_ROT_SCALE_SHEAR

public static final int TRANS_ROT_SCALE_SHEAR
See Also:
Constant Field Values

LEVENSHTEIN

public static final int LEVENSHTEIN
See Also:
Constant Field Values

DISSIMILARITY

public static final int DISSIMILARITY
See Also:
Constant Field Values

AVG_PHYS_DIST

public static final int AVG_PHYS_DIST
See Also:
Constant Field Values

MEDIAN_PHYS_DIST

public static final int MEDIAN_PHYS_DIST
See Also:
Constant Field Values

CUM_PHYST_DIST

public static final int CUM_PHYST_DIST
See Also:
Constant Field Values

STD_DEV

public static final int STD_DEV
See Also:
Constant Field Values

COMBINED

public static final int COMBINED
See Also:
Constant Field Values

PROXIMITY

public static final int PROXIMITY
See Also:
Constant Field Values

PROXIMITY_MUT

public static final int PROXIMITY_MUT
See Also:
Constant Field Values

STD_DEV_ALL

public static final int STD_DEV_ALL
See Also:
Constant Field Values

COMBINED_SCORE_INDICES

public static final int COMBINED_SCORE_INDICES
See Also:
Constant Field Values

W

public static final double[] W
Method Detail

obtainOrigin

public static java.lang.Object[] obtainOrigin(Line3D[] axes,
                                              int transform_type,
                                              javax.vecmath.Vector3d[] o_ref)
Generate calibrated origin of coordinates.


createOrigin

public static javax.vecmath.Vector3d[] createOrigin(VectorString3D x,
                                                    VectorString3D y,
                                                    VectorString3D z,
                                                    int transform_type)
Returns an array of 4 Vector3d: the three unit vectors in the same order as the vector strings, and the origin of coordinates. Expects: X, Y, Z where Z is the one to trust the most, Y the second most trusted, and X only for orientation. ZY define the plane, the direction of the perpendicular of which is given by the X.

Returns:
normalized vectors for transform_type == Compare.TRANS_ROT, otherwise NOT normalized.

createOrigin

public static javax.vecmath.Vector3d[] createOrigin(VectorString3D x,
                                                    VectorString3D y,
                                                    VectorString3D z,
                                                    int transform_type,
                                                    javax.vecmath.Vector3d[] o_ref)

testCreateOrigin

public static void testCreateOrigin(LayerSet ls,
                                    VectorString3D vs1,
                                    VectorString3D vs2,
                                    VectorString3D vs3)

createPipeChains

public static java.util.ArrayList<Compare.Chain> createPipeChains(ProjectThing root_pt,
                                                                  LayerSet ls)
                                                           throws java.lang.Exception
For a given pipe, create a VectorString3D for each possible path, as determined by the Project Tree structure and the parent/child relationships. A pipe is considered a potential branch when it is contained in an abstract child at the same tree level that the pipe itself in the tree. So: - lineage - branch 1 -pipe 1 - branch 2 - pipe 2 - branch 3 - pipe 3 Results in an ArrayList with: VS 1 VS 1 + 2 VS 1 + 3 An so on, recursively from the given pipe's parent.

Throws:
java.lang.Exception

createPipeChains

public static java.util.ArrayList<Compare.Chain> createPipeChains(ProjectThing root_pt,
                                                                  LayerSet ls,
                                                                  java.lang.String regex_exclude)
                                                           throws java.lang.Exception
Throws:
java.lang.Exception

findBestMatch

protected static final java.lang.Object[] findBestMatch(VectorString3D vs1,
                                                        VectorString3D vs2,
                                                        double delta,
                                                        boolean skip_ends,
                                                        int max_mut,
                                                        float min_chunk)

findBestMatch

protected static final java.lang.Object[] findBestMatch(VectorString3D vs1,
                                                        VectorString3D vs2,
                                                        double delta,
                                                        boolean skip_ends,
                                                        int max_mut,
                                                        float min_chunk,
                                                        int distance_type,
                                                        boolean direct,
                                                        boolean substring_matching)
Since comparing two sequences starting from one end or starting from the other is not the same at all, this method performs the match starting first from one end and then from the other. Then it performs a match starting from the middle of the longest stretches of pure mutations detected in the best of the matches above. Also, since strings may be reversed, the test against the reversed one is done as well. vs1 vs2 vs1.reversed() vs2.reversed() vs1 vs2.reversed() vs1.reversed() vs2 ASSUMES both VectorString3D are open.

Parameters:
direct - Whether to test vs1 against vs2 only, or to try all 4 possible combinations of reversed versus non-reversed and pick the best. Uses 1.1 weights for costs of insertion and deletion, as proven better by the parameter exploration. Uses weight of 1 for cost of mutation.

findBestMatch

public static final java.lang.Object[] findBestMatch(VectorString3D vs1,
                                                     VectorString3D vs2,
                                                     double delta,
                                                     boolean skip_ends,
                                                     int max_mut,
                                                     float min_chunk,
                                                     int distance_type,
                                                     boolean direct,
                                                     boolean substring_matching,
                                                     double wi,
                                                     double wd,
                                                     double wm)

score

public static final double score(double seq_sim,
                                 double levenshtein,
                                 double median_phys_dist,
                                 double[] w)

gatherChains

public static final java.lang.Object[] gatherChains(Project[] p,
                                                    Compare.CATAParameters cp)
                                             throws java.lang.Exception
Throws:
java.lang.Exception

gatherChains

public static final java.lang.Object[] gatherChains(Project[] p,
                                                    Compare.CATAParameters cp,
                                                    java.lang.String[] ignore)
                                             throws java.lang.Exception
Gather chains for all projects considering the cp.regex, and transforms all relative to the reference Project p[0]. Will ignore any for which a match exists in @param ignore.

Throws:
java.lang.Exception

compareAllToAll

public static Bureaucrat compareAllToAll(boolean to_file,
                                         java.lang.String regex,
                                         java.lang.String[] ignore,
                                         Project[] projects)

compareAllToAll

public static Bureaucrat compareAllToAll(boolean to_file,
                                         java.lang.String regex,
                                         java.lang.String[] ignore,
                                         Project[] projects,
                                         boolean crop,
                                         boolean from_end,
                                         int max_n_elements,
                                         java.lang.String outgroup)
Gets pipes for all open projects, and generates a matrix of dissimilarities, which gets passed on to the Worker thread and also to a file, if desired.

Parameters:
to_file - Whether to save the results to a file and popup a save dialog for it or not. In any case the results are stored in the worker's load, which you can retrieve like: Bureaucrat bu = Compare.compareAllToAll(true, null, null); Object result = bu.getWorker().getResult(); float[][] scores = (float[][])result[0]; ArrayList chains = (ArrayList)result[1];

scoreAllToAll

public static float[][] scoreAllToAll(VectorString3D[] vs,
                                      int distance_type,
                                      double delta,
                                      boolean skip_ends,
                                      int max_mut,
                                      float min_chunk,
                                      boolean direct,
                                      boolean substring_matching,
                                      Worker worker)
Returns the half matrix of scores, with values copied from one half matrix to the other, and a diagonal of zeros.

Parameters:
distance_type - ranges from 0 to 5, and includes: 0=Levenshtein, 1=Dissimilarity, 2=Average physical distance, 3=Median physical distance, 4=Cummulative physical distance and 5=Standard deviation.

createTransform

public static javax.media.j3d.Transform3D createTransform(javax.vecmath.Vector3d[] o)
Creates a transform with the 4 given vectors: X, Y, Z and translation of origin.


variabilityAnalysis

public static Bureaucrat variabilityAnalysis(Project reference_project,
                                             java.lang.String regex,
                                             java.lang.String[] ignore,
                                             boolean show_cata_dialog,
                                             boolean generate_plots,
                                             boolean show_plots,
                                             java.lang.String plot_dir_,
                                             boolean show_3D,
                                             boolean show_condensed_3D,
                                             boolean show_sources_3D,
                                             java.util.Map<Project,java.awt.Color> sources_color_table,
                                             boolean show_envelope_3D,
                                             float envelope_alpha,
                                             double delta_envelope,
                                             int envelope_type,
                                             boolean show_axes_3D,
                                             boolean heat_map,
                                             java.util.Map<java.lang.String,VectorString3D> map_condensed,
                                             Project[] projects)
Parameters:
reference_project - If null, then the first one found in the Project.getProjects() lists is used.
regex - A String (can be null) to filter objects by, to limit what gets processed. If regex is not null, then only ProjectThing nodes with the matching regex are analyzed (shallow: none of their children are questioned, but pipes will be built from them all).
generate_plots - Whether to generate the variability plots at all.
show_plots - If generate_plots, whether to show the plots in a stack image window or to save them.
show_3D - Whether to show any 3D data.
show_condensed_3D - If show_3D, whether to show the condensed vector strings, i.e. the "average" pipes.
show_sources_3D - If show_3D, whether to show the source pipes from which the condensed vector string was generated.
show_envelope_3D - If show_3D, whether to generate the variability envelope.
envelope_alpha - If show_envelope_3D, the envelope takes an alpha value between 0 (total transparency) and 1 (total opacity)
delta_envelope - The delta to resample the envelope to. When smaller than or equal to 1, no envelope resampling occurs.
show_axes_3D - If show_3D, whether to display the reference axes as well.
heat_map - If show_3D, whether to color the variability with a Fire LUT. If not show_condensed_3D, then the variability is shown in color-coded 3D spheres placed at the entry point to the neuropile.
map_condensed - If not null, all VectorString3D are put into this map.
projects - The list of projects to use.

makePlot

public static ij.gui.Plot makePlot(Compare.CATAParameters cp,
                                   java.lang.String name,
                                   VectorString3D c)

makeEnvelope

public static double[] makeEnvelope(Compare.CATAParameters cp,
                                    VectorString3D c)
From a condensed VectorString3D, create the radius at each point. The maximum provides the maximum radius from the condensed VectorString3D at @param c point-wise to the source points that generated it. Realize that the thickness of source VectorString3Ds is not considered, only their points.


condense

public static VectorString3D condense(Compare.CATAParameters cp,
                                      VectorString3D[] vs,
                                      Worker worker)
                               throws java.lang.Exception
Do an all-to-all distance matrix of the given vs, then do a neighbor joining, do a weighted merge of the two VectorString3D being merged, and then finally output the resulting condensed unique VectorString3D with its source array full with all points that make each point in it. Expects VectorString3D which are already calibrated and transformed.

Throws:
java.lang.Exception

transferVectorStrings

public static java.util.List<VectorString3D> transferVectorStrings(java.util.List<VectorString3D> vs,
                                                                   java.util.List<javax.vecmath.Tuple3d> source,
                                                                   java.util.List<javax.vecmath.Tuple3d> target,
                                                                   java.lang.Class<mpicbg.models.AffineModel3D> model_class)
                                                            throws java.lang.Exception
Transform all points of all VectorString3D in vs using a Moving Least Squares Transform defined by the pairing of points in source to those in target. In short, bring source into target.

Throws:
java.lang.Exception

transferVectorStrings

public static java.util.List<VectorString3D> transferVectorStrings(java.util.List<VectorString3D> vs,
                                                                   java.util.Map<java.lang.String,javax.vecmath.Tuple3d> source,
                                                                   java.util.Map<java.lang.String,javax.vecmath.Tuple3d> target)
                                                            throws java.lang.Exception
Transfer vs via a moving least squares transform by matching source named points into equally named target named points. If no points in common, returns null.

Throws:
java.lang.Exception

transferVectorStrings

public static java.util.List<VectorString3D> transferVectorStrings(java.util.List<VectorString3D> vs,
                                                                   ProjectThing source_fiduciary,
                                                                   ProjectThing target_fiduciary)
                                                            throws java.lang.Exception
Throws:
java.lang.Exception

extractPoints

public static java.util.Map<java.lang.String,javax.vecmath.Tuple3d> extractPoints(ProjectThing fiducial)
Extracts the list of fiduciary points from the fiducial parent and, if their name is different than "ball", adds their title as key and their first ball as a fiduciary point value of the returned map. The map is never null but could be empty. The values are calibrated.


reliabilityAnalysis

public static final Bureaucrat reliabilityAnalysis(java.lang.String[] ignore)
Reliability analysis of pipe comparisons: compares all to all, recording the score position of homonimous pipes in other projects. The reference project to which all other project objects are registered to is the first opened project, not the currently active ControlWindow tab! For each pipe in a brain, score against all other brains in which that pipe name exists, and record the score position within that brain. Uses default weights of 1.1 for costs of insertion and of deletion, and weight of 1 for cost of mutation. Chosen from parameter exploration results.


reliabilityAnalysis

public static final Bureaucrat reliabilityAnalysis(java.lang.String[] ignore,
                                                   boolean output_arff,
                                                   boolean weka_classify,
                                                   boolean show_dialog,
                                                   double delta,
                                                   double wi,
                                                   double wd,
                                                   double wm)

reliabilityAnalysisSpaceExploration

public static final Bureaucrat reliabilityAnalysisSpaceExploration(java.lang.String[] ignore)