From 0c5778f2e73c8bd0896fc4e68323beea78d49be9 Mon Sep 17 00:00:00 2001 From: Shawn Martin Date: Thu, 28 Apr 2022 12:29:04 -0600 Subject: [PATCH] Used functional version of natural sort. --- .../plugins/slycat-dac/py/dac_compute_coords.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/web-server/plugins/slycat-dac/py/dac_compute_coords.py b/web-server/plugins/slycat-dac/py/dac_compute_coords.py index 0fbec471f..86e03753a 100755 --- a/web-server/plugins/slycat-dac/py/dac_compute_coords.py +++ b/web-server/plugins/slycat-dac/py/dac_compute_coords.py @@ -28,7 +28,11 @@ from scipy import spatial from sklearn.decomposition import PCA -from natsort import natsorted +# better version of natural sort +# from natsort import natsorted + +# for natural sort function +import re import cherrypy @@ -703,6 +707,16 @@ def compute_prop_dist_vec(prop_vec, vec_length): return prop_dist_vec / prop_dist_vec_max +# helper function for compute alpha to do natural sort +# taken from Ned Batchelder's blog +def natsorted( l ): + + convert = lambda text: int(text) if text.isdigit() else text + alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] + + return sorted(l, key=alphanum_key) + + # use max-min algorithm to choose landmarks def select_landmarks(num_points, num_landmarks, variable):