aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-08-31 10:45:11 +0300
committerMuriithi Frederick Muriuki2021-08-31 10:45:11 +0300
commit64ce38b45839b6305b009f6e28b0f852409e9bda (patch)
tree9b645ae004289b963704cd6503255f4f0c3ac06d
parent750eff22f33fc8c78d529702369446e3acbdcae6 (diff)
downloadgenenetwork3-64ce38b45839b6305b009f6e28b0f852409e9bda.tar.gz
Parse QTLReaper outputs
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/qtlreaper.py: pass output files * tests/unit/computations/data/qtlreaper/main_output_sample.txt: sample test data * tests/unit/computations/data/qtlreaper/permu_output_sample.txt: sample test data * tests/unit/computations/test_qtlreaper.py: add tests Add code to parse the QTLReaper output data files.
-rw-r--r--gn3/computations/qtlreaper.py18
-rw-r--r--tests/unit/computations/data/qtlreaper/main_output_sample.txt11
-rw-r--r--tests/unit/computations/data/qtlreaper/permu_output_sample.txt27
-rw-r--r--tests/unit/computations/test_qtlreaper.py74
4 files changed, 130 insertions, 0 deletions
diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py
index c058e14..3b8e4db 100644
--- a/gn3/computations/qtlreaper.py
+++ b/gn3/computations/qtlreaper.py
@@ -90,3 +90,21 @@ def run_reaper(
subprocess.run(command_list, check=True)
return (output_filename, permu_output_filename)
+
+
+def parse_reaper_main_results(results_file):
+ with open(results_file, "r") as infile:
+ lines = infile.readlines()
+
+ def __parse_line(line):
+ items = line.strip().split("\t")
+ return items[0:2] + [float(item) for item in items[2:]]
+
+ header = lines[0].strip().split("\t")
+ return [dict(zip(header, __parse_line(line))) for line in lines[1:]]
+
+def parse_reaper_permutation_results(results_file):
+ with open(results_file, "r") as infile:
+ lines = infile.readlines()
+
+ return [float(line.strip()) for line in lines]
diff --git a/tests/unit/computations/data/qtlreaper/main_output_sample.txt b/tests/unit/computations/data/qtlreaper/main_output_sample.txt
new file mode 100644
index 0000000..12b11b4
--- /dev/null
+++ b/tests/unit/computations/data/qtlreaper/main_output_sample.txt
@@ -0,0 +1,11 @@
+ID Locus Chr cM Mb LRS Additive pValue
+T1 rs31443144 1 1.500 3.010 0.500 -0.074 1.000
+T1 rs6269442 1 1.500 3.492 0.500 -0.074 1.000
+T1 rs32285189 1 1.630 3.511 0.500 -0.074 1.000
+T1 rs258367496 1 1.630 3.660 0.500 -0.074 1.000
+T1 rs32430919 1 1.750 3.777 0.500 -0.074 1.000
+T1 rs36251697 1 1.880 3.812 0.500 -0.074 1.000
+T1 rs30658298 1 2.010 4.431 0.500 -0.074 1.000
+T1 rs51852623 1 2.010 4.447 0.500 -0.074 1.000
+T1 rs31879829 1 2.140 4.519 0.500 -0.074 1.000
+T1 rs36742481 1 2.140 4.776 0.500 -0.074 1.000
diff --git a/tests/unit/computations/data/qtlreaper/permu_output_sample.txt b/tests/unit/computations/data/qtlreaper/permu_output_sample.txt
new file mode 100644
index 0000000..64cff07
--- /dev/null
+++ b/tests/unit/computations/data/qtlreaper/permu_output_sample.txt
@@ -0,0 +1,27 @@
+4.44174
+5.03825
+5.08167
+5.18119
+5.18578
+5.24563
+5.24619
+5.24619
+5.27961
+5.28228
+5.43903
+5.50188
+5.51694
+5.56830
+5.63874
+5.71346
+5.71936
+5.74275
+5.76764
+5.79815
+5.81671
+5.82775
+5.89659
+5.92117
+5.93396
+5.93396
+5.94957
diff --git a/tests/unit/computations/test_qtlreaper.py b/tests/unit/computations/test_qtlreaper.py
new file mode 100644
index 0000000..ec23664
--- /dev/null
+++ b/tests/unit/computations/test_qtlreaper.py
@@ -0,0 +1,74 @@
+"""Module contains tests for gn3.computations.qtlreaper"""
+import os
+from unittest import TestCase
+from gn3.computations.qtlreaper import (
+ parse_reaper_main_results, parse_reaper_permutation_results)
+
+class TestQTLReaper(TestCase):
+ """Class for testing qtlreaper interface functions."""
+
+ def test_parse_reaper_main_results(self):
+ self.assertEqual(
+ parse_reaper_main_results(
+ "tests/unit/computations/data/qtlreaper/main_output_sample.txt"),
+ [
+ {
+ "ID": "T1", "Locus": "rs31443144", "Chr": 1, "cM": 1.500,
+ "Mb": 3.010, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs6269442", "Chr": 1, "cM": 1.500,
+ "Mb": 3.492, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs32285189", "Chr": 1, "cM": 1.630,
+ "Mb": 3.511, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs258367496", "Chr": 1, "cM": 1.630,
+ "Mb": 3.660, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs32430919", "Chr": 1, "cM": 1.750,
+ "Mb": 3.777, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs36251697", "Chr": 1, "cM": 1.880,
+ "Mb": 3.812, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs30658298", "Chr": 1, "cM": 2.010,
+ "Mb": 4.431, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs51852623", "Chr": 1, "cM": 2.010,
+ "Mb": 4.447, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs31879829", "Chr": 1, "cM": 2.140,
+ "Mb": 4.519, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ },
+ {
+ "ID": "T1", "Locus": "rs36742481", "Chr": 1, "cM": 2.140,
+ "Mb": 4.776, "LRS": 0.500, "Additive": -0.074,
+ "pValue": 1.000
+ }
+ ])
+
+ def test_parse_reaper_permutation_results(self):
+ self.assertEqual(
+ parse_reaper_permutation_results(
+ "tests/unit/computations/data/qtlreaper/permu_output_sample.txt"),
+ [4.44174, 5.03825, 5.08167, 5.18119, 5.18578, 5.24563, 5.24619,
+ 5.24619, 5.27961, 5.28228, 5.43903, 5.50188, 5.51694, 5.56830,
+ 5.63874, 5.71346, 5.71936, 5.74275, 5.76764, 5.79815, 5.81671,
+ 5.82775, 5.89659, 5.92117, 5.93396, 5.93396, 5.94957])