From 3f323734fcf258d28f3f7d33fdc1518ef9ec24a8 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Wed, 8 Sep 2021 10:54:48 +0300 Subject: Parse Chr value as int where possible * To ease sorting of data by numerical order down the line, sort the "Chr" values by numerical order. --- gn3/computations/qtlreaper.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'gn3') diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py index ec215e5..02d6572 100644 --- a/gn3/computations/qtlreaper.py +++ b/gn3/computations/qtlreaper.py @@ -86,11 +86,16 @@ def run_reaper( subprocess.run(command_list, check=True) return (output_filename, permu_output_filename) +def chromosome_sorter_key_fn(val): + if isinstance(val, int): + return val + return ord(val) + def organise_reaper_main_results(parsed_results): def __organise_by_chromosome(chr_name, items): chr_items = [item for item in items if item["Chr"] == chr_name] return { - "Chr": str(chr_name), + "Chr": chr_name, "loci": [{ "Locus": locus["Locus"], "cM": locus["cM"], @@ -125,9 +130,15 @@ def parse_reaper_main_results(results_file): except: return value + def __parse_column_int_value(value): + try: + return int(value) + except: + return value + def __parse_line(line): items = line.strip().split("\t") - return items[0:3] + [ + return items[0:2] + [__parse_column_int_value(items[2])] + [ __parse_column_float_value(item) for item in items[3:]] header = lines[0].strip().split("\t") -- cgit v1.2.3