aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/gemma.py
blob: 5bdddc1d31833882b5e04d1926a5607aef08d672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Procedures related gemma computations"""
import random
import string


def generate_random_n_string(n_length):
    """Generate a random string that is N chars long"""
    return ''.join(random.choice(string.ascii_uppercase + string.digits)
                   for _ in range(n_length))


def generate_pheno_txt_file(trait_filename: str,
                            values: str,
                            tmpdir: str = "/tmp") -> str:
    """Given VALUES, and TMPDIR, generate a valide traits file"""
    trait_filename += f"_{generate_random_n_string(6)}"
    with open(f"{tmpdir}/gn2/{trait_filename}", "w") as _file:
        for value in values:
            if value == "x":
                _file.write("NA\n")
            else:
                _file.write(f"{value}\n")
    return f"{tmpdir}/gn2/{trait_filename}"