diff options
author | Muriithi Frederick Muriuki | 2021-08-27 15:55:41 +0300 |
---|---|---|
committer | Muriithi Frederick Muriuki | 2021-08-27 15:55:41 +0300 |
commit | a9fa309f4017d84cd30f6df90376042f20b1836b (patch) | |
tree | 695a353cd35b9736c7f8453d44d3e2b5143f1261 | |
parent | 28fde00ee2835d404157652548a4265be3accede (diff) | |
download | genenetwork3-a9fa309f4017d84cd30f6df90376042f20b1836b.tar.gz |
Test out generation of traits file
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi
* As part of the development effort, this commit provides a proof-of-concept
as a reference for generating the traits data file.
It might be useful for verifying that the functions that are called are
working as is expected.
-rw-r--r-- | qtlfilesexport.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/qtlfilesexport.py b/qtlfilesexport.py new file mode 100644 index 0000000..2e7c9c2 --- /dev/null +++ b/qtlfilesexport.py @@ -0,0 +1,67 @@ +""" +Test the qtlfiles export of traits files + +Run with: + + env SQL_URI="mysql://<user>:<password>@<host>:<port>/db_webqtl" python3 qtlfilesexport.py + +replacing the variables in the angled brackets with the appropriate values +""" +import random +import string +from gn3.computations.slink import slink +from gn3.db_utils import database_connector +from gn3.computations.heatmap import export_trait_data +from gn3.db.traits import retrieve_trait_data, retrieve_trait_info +from gn3.computations.heatmap import ( + cluster_traits, + compute_heatmap_order, + generate_traits_file, + retrieve_strains_and_values) + +TMPDIR = "tmp/qtltests" + +def trait_fullnames(): + """Return sample names for traits""" + return [ + "UCLA_BXDBXH_CARTILAGE_V2::ILM103710672", + "UCLA_BXDBXH_CARTILAGE_V2::ILM2260338", + "UCLA_BXDBXH_CARTILAGE_V2::ILM3140576", + "UCLA_BXDBXH_CARTILAGE_V2::ILM5670577", + "UCLA_BXDBXH_CARTILAGE_V2::ILM2070121", + "UCLA_BXDBXH_CARTILAGE_V2::ILM103990541", + "UCLA_BXDBXH_CARTILAGE_V2::ILM1190722", + "UCLA_BXDBXH_CARTILAGE_V2::ILM6590722", + "UCLA_BXDBXH_CARTILAGE_V2::ILM4200064", + "UCLA_BXDBXH_CARTILAGE_V2::ILM3140463"] + +def random_string(length): + return "".join( + random.choices( + string.ascii_letters + string.digits, k=length)) + +def main(): + """entrypoint function""" + conn = database_connector()[0] + threshold = 0 + traits = [ + retrieve_trait_info(threshold, fullname, conn) + for fullname in trait_fullnames()] + traits_data_list = [retrieve_trait_data(t, conn) for t in traits] + strains = list(set([k for td in traits_data_list for k in td["data"].keys()])) + exported_traits_data_list = [ + export_trait_data(td, strains) for td in traits_data_list] + slinked = slink(cluster_traits(exported_traits_data_list)) + orders = compute_heatmap_order(slinked) + strains_and_values = retrieve_strains_and_values( + orders, strains, exported_traits_data_list) + strains_values = strains_and_values[0][1] + strains_values2 = strains_and_values[1][1] + trait_values = [t[2] for t in strains_and_values] + traits_filename = "{}/traits_test_file_{}.txt".format( + TMPDIR, random_string(10)) + generate_traits_file(strains_values, trait_values, traits_filename) + print("Generated file: {}".format(traits_filename)) + +if __name__ == "__main__": + main() |