From 753f7da6a468606aa672235c839054e3b913ac83 Mon Sep 17 00:00:00 2001 From: zsloan Date: Thu, 24 Mar 2022 20:00:52 +0000 Subject: Fix qtlreaper results sorting to deal with M as chromosome (should be at the end) Not sure how best to do this; I just had the sort algorithm change "M" to "z" (which will always be sorted last, behind X and Y) --- wqflask/wqflask/marker_regression/qtlreaper_mapping.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py index 801674e1..c4b495d7 100644 --- a/wqflask/wqflask/marker_regression/qtlreaper_mapping.py +++ b/wqflask/wqflask/marker_regression/qtlreaper_mapping.py @@ -183,7 +183,16 @@ def natural_sort(marker_list): Function to naturally sort numbers + strings, adopted from user Mark Byers here: https://stackoverflow.com/questions/4836710/does-python-have-a-built-in-function-for-string-natural-sort Changed to return indices instead of values, though, since the same reordering needs to be applied to bootstrap results """ - convert = lambda text: int(text) if text.isdigit() else text.lower() + + def convert(text): + if text.isdigit(): + return int(text) + else: + if text != "M": + return text.lower() + else: + return "z" + alphanum_key = lambda key: [convert(c) for c in re.split( '([0-9]+)', str(marker_list[key]['chr']))] return sorted(list(range(len(marker_list))), key=alphanum_key) -- cgit v1.2.3