aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/qtlreaper.py
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-08-31 11:16:29 +0300
committerMuriithi Frederick Muriuki2021-08-31 11:16:29 +0300
commitb5e1d1176f1bf4f7c0b68b27beb15e99418f1650 (patch)
treef158a54b262214ca65394a7dc65a64590533cc0c /gn3/computations/qtlreaper.py
parente441509a59c20a051fd5ab94710513f1968a5e02 (diff)
downloadgenenetwork3-b5e1d1176f1bf4f7c0b68b27beb15e99418f1650.tar.gz
Fix linting errors, minor bugs and reorganise code
* Fix some linting errors and some minor bugs caught by the linter. Move the `random_string` function to separate module for use in multiple places in the code.
Diffstat (limited to 'gn3/computations/qtlreaper.py')
-rw-r--r--gn3/computations/qtlreaper.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py
index 3b8e4db..30c7051 100644
--- a/gn3/computations/qtlreaper.py
+++ b/gn3/computations/qtlreaper.py
@@ -3,17 +3,10 @@ This module contains functions to interact with the `qtlreaper` utility for
computation of QTLs.
"""
import os
-import random
-import string
import subprocess
+from gn3.random import random_string
from gn3.settings import TMPDIR, REAPER_COMMAND
-def random_string(length):
- """Generate a random string of length `length`."""
- return "".join(
- random.choices(
- string.ascii_letters + string.digits, k=length))
-
def generate_traits_file(strains, trait_values, traits_filename):
"""
Generate a traits file for use with `qtlreaper`.
@@ -25,11 +18,13 @@ def generate_traits_file(strains, trait_values, traits_filename):
computation of QTLs.
"""
header = "Trait\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[:-1])] + [
- "T{}\t{}".format(len(trait_values), "\t".join([str(i) for i in t]))
- for t in trait_values[-1:]]
+ data = (
+ [header] +
+ ["T{}\t{}\n".format(i+1, "\t".join([str(i) for i in t]))
+ for i, t in enumerate(trait_values[:-1])] +
+ ["T{}\t{}".format(
+ len(trait_values), "\t".join([str(i) for i in t]))
+ for t in trait_values[-1:]])
with open(traits_filename, "w") as outfile:
outfile.writelines(data)
@@ -93,6 +88,9 @@ def run_reaper(
def parse_reaper_main_results(results_file):
+ """
+ Parse the results file of running QTLReaper into a list of dicts.
+ """
with open(results_file, "r") as infile:
lines = infile.readlines()
@@ -104,6 +102,9 @@ def parse_reaper_main_results(results_file):
return [dict(zip(header, __parse_line(line))) for line in lines[1:]]
def parse_reaper_permutation_results(results_file):
+ """
+ Parse the results QTLReaper permutations into a list of values.
+ """
with open(results_file, "r") as infile:
lines = infile.readlines()