aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/qtlreaper.py
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-09-06 08:09:20 +0300
committerMuriithi Frederick Muriuki2021-09-06 08:09:20 +0300
commitd4943f1d01d89a3928c905f80914a23144126c8e (patch)
tree52d9077168fd96634510b6fa0c8af1606f96f0ac /gn3/computations/qtlreaper.py
parent679a1af832ad9585c7cf72996043edb08e1b0d10 (diff)
downloadgenenetwork3-d4943f1d01d89a3928c905f80914a23144126c8e.tar.gz
Provide function to organise parsed QTLReaper results
* gn3/computations/qtlreaper.py: Provide a function to organise the results by trait for easier use down the line. * tests/unit/computations/test_qtlreaper.py: provide a test to ensure that the organising function works as expected.
Diffstat (limited to 'gn3/computations/qtlreaper.py')
-rw-r--r--gn3/computations/qtlreaper.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py
index 9b20309..8c0e6de 100644
--- a/gn3/computations/qtlreaper.py
+++ b/gn3/computations/qtlreaper.py
@@ -86,6 +86,31 @@ def run_reaper(
subprocess.run(command_list, check=True)
return (output_filename, permu_output_filename)
+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),
+ "loci": [{
+ "Locus": locus["Locus"],
+ "cM": locus["cM"],
+ "Mb": locus["Mb"],
+ "LRS": locus["LRS"],
+ "Additive": locus["Additive"],
+ "pValue": locus["pValue"]
+ } for locus in chr_items]}
+
+ def __organise_by_id(identifier, items):
+ id_items = [item for item in items if item["ID"] == identifier]
+ unique_chromosomes = {item["Chr"] for item in id_items}
+ return {
+ "ID": identifier,
+ "chromosomes": [
+ __organise_by_chromosome(chromo, id_items)
+ for chromo in sorted(unique_chromosomes)]}
+
+ unique_ids = {res["ID"] for res in parsed_results}
+ return [__organise_by_id(_id, parsed_results) for _id in sorted(unique_ids)]
def parse_reaper_main_results(results_file):
"""