Mercurial > repos > imgteam > imagej2_noise
diff imagej2_analyze_skeleton_jython_script.py @ 2:756e062741dc draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 57a0433defa3cbc37ab34fbb0ebcfaeb680db8d5
author | imgteam |
---|---|
date | Sun, 05 Nov 2023 10:57:39 +0000 |
parents | 7a44772cc89f |
children | 73cc4e6a741d |
line wrap: on
line diff
--- a/imagej2_analyze_skeleton_jython_script.py Mon Sep 28 16:45:49 2020 +0000 +++ b/imagej2_analyze_skeleton_jython_script.py Sun Nov 05 10:57:39 2023 +0000 @@ -4,18 +4,37 @@ from ij import IJ from sc.fiji.analyzeSkeleton import AnalyzeSkeleton_ -BASIC_NAMES = ['Branches', 'Junctions', 'End-point Voxels', - 'Junction Voxels', 'Slab Voxels', 'Average branch length', - 'Triple Points', 'Quadruple Points', 'Maximum Branch Length'] -DETAIL_NAMES = ['Skeleton ID', 'Branch length', 'V1 x', 'V1 y', 'V1 z', 'V2 x', - 'V2 y', 'V2 z', 'Euclidean distance'] -OPTIONS = ['edm=Overwrite', 'iterations=1', 'count=1'] +BASIC_NAMES = [ + "Branches", + "Junctions", + "End-point Voxels", + "Junction Voxels", + "Slab Voxels", + "Average branch length", + "Triple Points", + "Quadruple Points", + "Maximum Branch Length", +] +DETAIL_NAMES = [ + "Skeleton ID", + "Branch length", + "V1 x", + "V1 y", + "V1 z", + "V2 x", + "V2 y", + "V2 z", + "Euclidean distance", +] +OPTIONS = ["edm=Overwrite", "iterations=1", "count=1"] def get_euclidean_distance(vertex1, vertex2): x1, y1, z1 = get_points(vertex1) x2, y2, z2 = get_points(vertex2) - return math.sqrt(math.pow((x2 - x1), 2) + math.pow((y2 - y1), 2) + math.pow((z2 - z1), 2)) + return math.sqrt( + math.pow((x2 - x1), 2) + math.pow((y2 - y1), 2) + math.pow((z2 - z1), 2) + ) def get_graph_length(graph): @@ -46,29 +65,29 @@ return graphs -def save(result, output, show_detailed_info, calculate_largest_shortest_path, sep='\t'): +def save(result, output, show_detailed_info, calculate_largest_shortest_path, sep="\t"): num_trees = int(result.getNumOfTrees()) - outf = open(output, 'wb') - outf.write('# %s\n' % sep.join(BASIC_NAMES)) + outf = open(output, "wb") + outf.write("# %s\n" % sep.join(BASIC_NAMES)) for index in range(num_trees): - outf.write('%d%s' % (result.getBranches()[index], sep)) - outf.write('%d%s' % (result.getJunctions()[index], sep)) - outf.write('%d%s' % (result.getEndPoints()[index], sep)) - outf.write('%d%s' % (result.getJunctionVoxels()[index], sep)) - outf.write('%d%s' % (result.getSlabs()[index], sep)) - outf.write('%.3f%s' % (result.getAverageBranchLength()[index], sep)) - outf.write('%d%s' % (result.getTriples()[index], sep)) - outf.write('%d%s' % (result.getQuadruples()[index], sep)) - outf.write('%.3f' % result.getMaximumBranchLength()[index]) + outf.write("%d%s" % (result.getBranches()[index], sep)) + outf.write("%d%s" % (result.getJunctions()[index], sep)) + outf.write("%d%s" % (result.getEndPoints()[index], sep)) + outf.write("%d%s" % (result.getJunctionVoxels()[index], sep)) + outf.write("%d%s" % (result.getSlabs()[index], sep)) + outf.write("%.3f%s" % (result.getAverageBranchLength()[index], sep)) + outf.write("%d%s" % (result.getTriples()[index], sep)) + outf.write("%d%s" % (result.getQuadruples()[index], sep)) + outf.write("%.3f" % result.getMaximumBranchLength()[index]) if calculate_largest_shortest_path: - outf.write('%s%.3f%s' % (sep, result.shortestPathList.get(index), sep)) - outf.write('%d%s' % (result.spStartPosition[index][0], sep)) - outf.write('%d%s' % (result.spStartPosition[index][1], sep)) - outf.write('%d\n' % result.spStartPosition[index][2]) + outf.write("%s%.3f%s" % (sep, result.shortestPathList.get(index), sep)) + outf.write("%d%s" % (result.spStartPosition[index][0], sep)) + outf.write("%d%s" % (result.spStartPosition[index][1], sep)) + outf.write("%d\n" % result.spStartPosition[index][2]) else: - outf.write('\n') + outf.write("\n") if show_detailed_info: - outf.write('# %s\n' % sep.join(DETAIL_NAMES)) + outf.write("# %s\n" % sep.join(DETAIL_NAMES)) # The following index is a placeholder for the skeleton ID. # The terms "graph" and "skeleton" refer to the same thing. # Also, the SkeletonResult.java code states that the @@ -80,23 +99,23 @@ x1, y1, z1 = get_points(vertex1) vertex2 = edge.getV2() x2, y2, z2 = get_points(vertex2) - outf.write('%d%s' % (index + 1, sep)) - outf.write('%.3f%s' % (edge.getLength(), sep)) - outf.write('%d%s' % (x1, sep)) - outf.write('%d%s' % (y1, sep)) - outf.write('%d%s' % (z1, sep)) - outf.write('%d%s' % (x2, sep)) - outf.write('%d%s' % (y2, sep)) - outf.write('%d%s' % (z2, sep)) - outf.write('%.3f' % get_euclidean_distance(vertex1, vertex2)) + outf.write("%d%s" % (index + 1, sep)) + outf.write("%.3f%s" % (edge.getLength(), sep)) + outf.write("%d%s" % (x1, sep)) + outf.write("%d%s" % (y1, sep)) + outf.write("%d%s" % (z1, sep)) + outf.write("%d%s" % (x2, sep)) + outf.write("%d%s" % (y2, sep)) + outf.write("%d%s" % (z2, sep)) + outf.write("%.3f" % get_euclidean_distance(vertex1, vertex2)) if calculate_largest_shortest_path: # Keep number of separated items the same for each line. - outf.write('%s %s' % (sep, sep)) - outf.write(' %s' % sep) - outf.write(' %s' % sep) - outf.write(' \n') + outf.write("%s %s" % (sep, sep)) + outf.write(" %s" % sep) + outf.write(" %s" % sep) + outf.write(" \n") else: - outf.write('\n') + outf.write("\n") outf.close() @@ -109,8 +128,8 @@ prune_ends = sys.argv[-4] == "yes" calculate_largest_shortest_path = sys.argv[-3] == "yes" if calculate_largest_shortest_path: - BASIC_NAMES.extend(['Longest Shortest Path', 'spx', 'spy', 'spz']) - DETAIL_NAMES.extend([' ', ' ', ' ', ' ']) + BASIC_NAMES.extend(["Longest Shortest Path", "spx", "spy", "spz"]) + DETAIL_NAMES.extend([" ", " ", " ", " "]) show_detailed_info = sys.argv[-2] == "yes" output = sys.argv[-1] @@ -135,14 +154,21 @@ # Run AnalyzeSkeleton analyze_skeleton = AnalyzeSkeleton_() analyze_skeleton.setup("", input_image_plus_copy) -if prune_cycle_method == 'none': +if prune_cycle_method == "none": prune_index = analyze_skeleton.NONE -elif prune_cycle_method == 'shortest_branch': +elif prune_cycle_method == "shortest_branch": prune_index = analyze_skeleton.SHORTEST_BRANCH -elif prune_cycle_method == 'lowest_intensity_voxel': +elif prune_cycle_method == "lowest_intensity_voxel": prune_index = analyze_skeleton.LOWEST_INTENSITY_VOXEL -elif prune_cycle_method == 'lowest_intensity_branch': +elif prune_cycle_method == "lowest_intensity_branch": prune_index = analyze_skeleton.LOWEST_INTENSITY_BRANCH -result = analyze_skeleton.run(prune_index, prune_ends, calculate_largest_shortest_path, input_image_plus_copy, True, True) +result = analyze_skeleton.run( + prune_index, + prune_ends, + calculate_largest_shortest_path, + input_image_plus_copy, + True, + True, +) # Save the results. save(result, output, show_detailed_info, calculate_largest_shortest_path)