Mercurial > repos > bgruening > imagej2_crop
annotate imagej2_analyze_skeleton_jython_script.py @ 0:018144807556 draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
author | bgruening |
---|---|
date | Tue, 24 Sep 2024 17:12:52 +0000 |
parents | |
children |
rev | line source |
---|---|
0
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
1 import math |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
2 import sys |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
3 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
4 from ij import IJ |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
5 from sc.fiji.analyzeSkeleton import AnalyzeSkeleton_ |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
6 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
7 BASIC_NAMES = [ |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
8 "Branches", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
9 "Junctions", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
10 "End-point Voxels", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
11 "Junction Voxels", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
12 "Slab Voxels", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
13 "Average branch length", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
14 "Triple Points", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
15 "Quadruple Points", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
16 "Maximum Branch Length", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
17 ] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
18 DETAIL_NAMES = [ |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
19 "Skeleton ID", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
20 "Branch length", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
21 "V1 x", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
22 "V1 y", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
23 "V1 z", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
24 "V2 x", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
25 "V2 y", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
26 "V2 z", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
27 "Euclidean distance", |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
28 ] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
29 OPTIONS = ["edm=Overwrite", "iterations=1", "count=1"] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
30 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
31 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
32 def get_euclidean_distance(vertex1, vertex2): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
33 x1, y1, z1 = get_points(vertex1) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
34 x2, y2, z2 = get_points(vertex2) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
35 return math.sqrt( |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
36 math.pow((x2 - x1), 2) + math.pow((y2 - y1), 2) + math.pow((z2 - z1), 2) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
37 ) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
38 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
39 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
40 def get_graph_length(graph): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
41 length = 0 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
42 for edge in graph.getEdges(): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
43 length = length + edge.getLength() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
44 return length |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
45 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
46 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
47 def get_points(vertex): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
48 # An array of Point, which has attributes x,y,z. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
49 point = vertex.getPoints()[0] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
50 return point.x, point.y, point.z |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
51 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
52 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
53 def get_sorted_edge_lengths(graph): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
54 # Return graph edges sorted from longest to shortest. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
55 edges = graph.getEdges() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
56 edges = sorted(edges, key=lambda edge: edge.getLength(), reverse=True) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
57 return edges |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
58 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
59 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
60 def get_sorted_graph_lengths(result): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
61 # Get the separate graphs (skeletons). |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
62 graphs = result.getGraph() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
63 # Sort graphs from longest to shortest. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
64 graphs = sorted(graphs, key=lambda g: get_graph_length(g), reverse=True) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
65 return graphs |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
66 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
67 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
68 def save(result, output, show_detailed_info, calculate_largest_shortest_path, sep="\t"): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
69 num_trees = int(result.getNumOfTrees()) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
70 outf = open(output, "wb") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
71 outf.write("# %s\n" % sep.join(BASIC_NAMES)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
72 for index in range(num_trees): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
73 outf.write("%d%s" % (result.getBranches()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
74 outf.write("%d%s" % (result.getJunctions()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
75 outf.write("%d%s" % (result.getEndPoints()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
76 outf.write("%d%s" % (result.getJunctionVoxels()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
77 outf.write("%d%s" % (result.getSlabs()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
78 outf.write("%.3f%s" % (result.getAverageBranchLength()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
79 outf.write("%d%s" % (result.getTriples()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
80 outf.write("%d%s" % (result.getQuadruples()[index], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
81 outf.write("%.3f" % result.getMaximumBranchLength()[index]) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
82 if calculate_largest_shortest_path: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
83 outf.write("%s%.3f%s" % (sep, result.shortestPathList.get(index), sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
84 outf.write("%d%s" % (result.spStartPosition[index][0], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
85 outf.write("%d%s" % (result.spStartPosition[index][1], sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
86 outf.write("%d\n" % result.spStartPosition[index][2]) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
87 else: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
88 outf.write("\n") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
89 if show_detailed_info: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
90 outf.write("# %s\n" % sep.join(DETAIL_NAMES)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
91 # The following index is a placeholder for the skeleton ID. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
92 # The terms "graph" and "skeleton" refer to the same thing. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
93 # Also, the SkeletonResult.java code states that the |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
94 # private Graph[] graph object is an array of graphs (one |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
95 # per tree). |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
96 for index, graph in enumerate(get_sorted_graph_lengths(result)): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
97 for edge in get_sorted_edge_lengths(graph): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
98 vertex1 = edge.getV1() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
99 x1, y1, z1 = get_points(vertex1) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
100 vertex2 = edge.getV2() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
101 x2, y2, z2 = get_points(vertex2) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
102 outf.write("%d%s" % (index + 1, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
103 outf.write("%.3f%s" % (edge.getLength(), sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
104 outf.write("%d%s" % (x1, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
105 outf.write("%d%s" % (y1, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
106 outf.write("%d%s" % (z1, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
107 outf.write("%d%s" % (x2, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
108 outf.write("%d%s" % (y2, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
109 outf.write("%d%s" % (z2, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
110 outf.write("%.3f" % get_euclidean_distance(vertex1, vertex2)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
111 if calculate_largest_shortest_path: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
112 # Keep number of separated items the same for each line. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
113 outf.write("%s %s" % (sep, sep)) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
114 outf.write(" %s" % sep) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
115 outf.write(" %s" % sep) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
116 outf.write(" \n") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
117 else: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
118 outf.write("\n") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
119 outf.close() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
120 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
121 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
122 # Fiji Jython interpreter implements Python 2.5 which does not |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
123 # provide support for argparse. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
124 input = sys.argv[-7] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
125 black_background = sys.argv[-6] == "yes" |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
126 prune_cycle_method = sys.argv[-5] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
127 prune_ends = sys.argv[-4] == "yes" |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
128 calculate_largest_shortest_path = sys.argv[-3] == "yes" |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
129 if calculate_largest_shortest_path: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
130 BASIC_NAMES.extend(["Longest Shortest Path", "spx", "spy", "spz"]) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
131 DETAIL_NAMES.extend([" ", " ", " ", " "]) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
132 show_detailed_info = sys.argv[-2] == "yes" |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
133 output = sys.argv[-1] |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
134 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
135 # Open the input image file. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
136 input_image_plus = IJ.openImage(input) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
137 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
138 # Create a copy of the image. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
139 input_image_plus_copy = input_image_plus.duplicate() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
140 image_processor_copy = input_image_plus_copy.getProcessor() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
141 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
142 # Set binary options. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
143 options_list = OPTIONS |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
144 if black_background: |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
145 options_list.append("black") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
146 options = " ".join(options_list) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
147 IJ.run(input_image_plus_copy, "Options...", options) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
148 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
149 # Convert image to binary if necessary. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
150 if not image_processor_copy.isBinary(): |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
151 IJ.run(input_image_plus_copy, "Make Binary", "") |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
152 |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
153 # Run AnalyzeSkeleton |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
154 analyze_skeleton = AnalyzeSkeleton_() |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
155 analyze_skeleton.setup("", input_image_plus_copy) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
156 if prune_cycle_method == "none": |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
157 prune_index = analyze_skeleton.NONE |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
158 elif prune_cycle_method == "shortest_branch": |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
159 prune_index = analyze_skeleton.SHORTEST_BRANCH |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
160 elif prune_cycle_method == "lowest_intensity_voxel": |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
161 prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
162 elif prune_cycle_method == "lowest_intensity_branch": |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
163 prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
164 result = analyze_skeleton.run( |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
165 prune_index, |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
166 prune_ends, |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
167 calculate_largest_shortest_path, |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
168 input_image_plus_copy, |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
169 True, |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
170 True, |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
171 ) |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
172 # Save the results. |
018144807556
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
bgruening
parents:
diff
changeset
|
173 save(result, output, show_detailed_info, calculate_largest_shortest_path) |