From 1a3901b174d00af8fa7f5ae78b810de66024b5ab Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Fri, 27 Aug 2021 15:49:53 +0300 Subject: Export trait data to file Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Provide a function to export the given strains and traits data into a traits file for use with `rust-qtlreaper`. --- gn3/computations/heatmap.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gn3') diff --git a/gn3/computations/heatmap.py b/gn3/computations/heatmap.py index da13ceb..2f92048 100644 --- a/gn3/computations/heatmap.py +++ b/gn3/computations/heatmap.py @@ -229,3 +229,11 @@ def retrieve_strains_and_values(orders, strainlist, traits_data_list): values = [] return rets + +def generate_traits_file(strains, trait_values, traits_filename): + header = "Traits\t{}\n".format("\t".join(strains)) + data = [header] + [ + "T{}\t{}\n".format(i+1, "\t".join([str(i) for i in t])) + for i,t in enumerate(trait_values)] + with open(traits_filename, "w") as outfile: + outfile.writelines(data) -- cgit v1.2.3