From 6c872943597f3664cca77abbdf56f074fc5231e6 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Tue, 31 Aug 2021 06:56:35 +0300 Subject: Fix bugs with `run_reaper` function Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/qtlreaper.py: Fix some bugs * qtlfilesexport.py: Test out running rust-qtlreaper Test out the qtlreaper interface code and fix some bugs caught in the process. --- gn3/computations/qtlreaper.py | 8 +++++--- qtlfilesexport.py | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py index 9b13a55..c058e14 100644 --- a/gn3/computations/qtlreaper.py +++ b/gn3/computations/qtlreaper.py @@ -42,7 +42,7 @@ def create_output_directory(path: str): def run_reaper( genotype_filename: str, traits_filename: str, - other_options: tuple = ("--n_permutations", 1000), + other_options: tuple = ("--n_permutations", "1000"), separate_nperm_output: bool = False, output_dir: str = TMPDIR): """ @@ -70,7 +70,7 @@ def run_reaper( The function will raise a `subprocess.CalledProcessError` exception in case of any errors running the `qtlreaper` command. """ - create_output_directory(output_dir) + create_output_directory("{}/qtlreaper".format(output_dir)) output_filename = "{}/qtlreaper/main_output_{}.txt".format( output_dir, random_string(10)) output_list = ["--main_output", output_filename] @@ -84,7 +84,9 @@ def run_reaper( command_list = [ REAPER_COMMAND, "--geno", genotype_filename, *other_options, # this splices the `other_options` list here - "--traits", traits_filename, "--main_output", output_filename] + "--traits", traits_filename, + *output_list # this splices the `output_list` list here + ] subprocess.run(command_list, check=True) return (output_filename, permu_output_filename) diff --git a/qtlfilesexport.py b/qtlfilesexport.py index 1db4ab6..799de31 100644 --- a/qtlfilesexport.py +++ b/qtlfilesexport.py @@ -9,6 +9,7 @@ replacing the variables in the angled brackets with the appropriate values """ from gn3.computations.slink import slink from gn3.db_utils import database_connector +from gn3.computations.qtlreaper import run_reaper from gn3.computations.heatmap import export_trait_data from gn3.db.traits import retrieve_trait_data, retrieve_trait_info from gn3.db.genotypes import build_genotype_file, load_genotype_samples @@ -57,5 +58,11 @@ def main(): generate_traits_file(strains_values, trait_values, traits_filename) print("Generated file: {}".format(traits_filename)) + main_output, permutations_output = run_reaper( + genotype_filename, traits_filename, separate_nperm_output=True) + + print("Main output: {}, Permutation output: {}".format( + main_output, permutations_output)) + if __name__ == "__main__": main() -- cgit v1.2.3