aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-08-27 15:49:53 +0300
committerMuriithi Frederick Muriuki2021-08-27 15:49:53 +0300
commit1a3901b174d00af8fa7f5ae78b810de66024b5ab (patch)
tree2a3412075ba36a49f6137b4cd0fb7d5446aa905a
parent557e482c88ba3d44ae7d278b7222f37fa043b4d0 (diff)
downloadgenenetwork3-1a3901b174d00af8fa7f5ae78b810de66024b5ab.tar.gz
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`.
-rw-r--r--gn3/computations/heatmap.py8
1 files changed, 8 insertions, 0 deletions
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)