aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/partial_correlations.py15
-rw-r--r--gn3/computations/qtlreaper.py16
2 files changed, 17 insertions, 14 deletions
diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py
index 3633a59..f7ddfd0 100644
--- a/gn3/computations/partial_correlations.py
+++ b/gn3/computations/partial_correlations.py
@@ -141,7 +141,7 @@ def find_identical_traits(
return acc + ident[1]
def __dictify_controls__(acc, control_item):
- ckey = tuple("{:.3f}".format(item) for item in control_item[0])
+ ckey = tuple("{item:.3f}" for item in control_item[0])
return {**acc, ckey: acc.get(ckey, tuple()) + (control_item[1],)}
return (reduce(## for identical control traits
@@ -181,8 +181,8 @@ def tissue_correlation(
assert len(primary_trait_values) == len(target_trait_values), (
"The lengths of the `primary_trait_values` and `target_trait_values` "
"must be equal")
- assert method in method_fns.keys(), (
- "Method must be one of: {}".format(",".join(method_fns.keys())))
+ assert method in method_fns, (
+ "Method must be one of: {','.join(method_fns.keys())}")
corr, pvalue = method_fns[method](primary_trait_values, target_trait_values)
return (corr, pvalue)
@@ -241,7 +241,7 @@ def partial_correlations_fast(# pylint: disable=[R0913, R0914]
function in GeneNetwork1.
"""
assert method in ("spearman", "pearson")
- with open(database_filename, "r") as dataset_file:
+ with open(database_filename, "r") as dataset_file: # pytest: disable=[W1514]
dataset = tuple(dataset_file.readlines())
good_dataset_samples = good_dataset_samples_indexes(
@@ -290,12 +290,15 @@ def build_data_frame(
if isinstance(zdata[0], float):
return x_y_df.join(pandas.DataFrame({"z": zdata}))
interm_df = x_y_df.join(pandas.DataFrame(
- {"z{}".format(i): val for i, val in enumerate(zdata)}))
+ {f"z{i}": val for i, val in enumerate(zdata)}))
if interm_df.shape[1] == 3:
return interm_df.rename(columns={"z0": "z"})
return interm_df
def compute_trait_info(primary_vals, control_vals, target, method):
+ """
+ Compute the correlation values for the given arguments.
+ """
targ_vals = target[0]
targ_name = target[1]
primary = [
@@ -629,7 +632,7 @@ def partial_correlations_entry(# pylint: disable=[R0913, R0914, R0911]
"status": "not-found",
"message": "None of the requested control traits were found."}
for trait in cntrl_traits:
- if trait["haveinfo"] == False:
+ if trait["haveinfo"] is False:
warnings.warn(
(f"Control traits {trait['trait_fullname']} was not found "
"- continuing without it."),
diff --git a/gn3/computations/qtlreaper.py b/gn3/computations/qtlreaper.py
index d1ff4ac..b61bdae 100644
--- a/gn3/computations/qtlreaper.py
+++ b/gn3/computations/qtlreaper.py
@@ -27,7 +27,7 @@ def generate_traits_file(samples, trait_values, traits_filename):
["{}\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:
+ with open(traits_filename, "w", encoding="utf8") as outfile:
outfile.writelines(data)
def create_output_directory(path: str):
@@ -68,13 +68,13 @@ def run_reaper(
The function will raise a `subprocess.CalledProcessError` exception in case
of any errors running the `qtlreaper` command.
"""
- create_output_directory("{}/qtlreaper".format(output_dir))
- output_filename = "{}/qtlreaper/main_output_{}.txt".format(
- output_dir, random_string(10))
+ create_output_directory(f"{output_dir}/qtlreaper")
+ output_filename = (
+ f"{output_dir}/qtlreaper/main_output_{random_string(10)}.txt")
output_list = ["--main_output", output_filename]
if separate_nperm_output:
- permu_output_filename: Union[None, str] = "{}/qtlreaper/permu_output_{}.txt".format(
- output_dir, random_string(10))
+ permu_output_filename: Union[None, str] = (
+ f"{output_dir}/qtlreaper/permu_output_{random_string(10)}.txt")
output_list = output_list + [
"--permu_output", permu_output_filename] # type: ignore[list-item]
else:
@@ -135,7 +135,7 @@ 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:
+ with open(results_file, "r", encoding="utf8") as infile:
lines = infile.readlines()
def __parse_column_float_value(value):
@@ -164,7 +164,7 @@ def parse_reaper_permutation_results(results_file):
"""
Parse the results QTLReaper permutations into a list of values.
"""
- with open(results_file, "r") as infile:
+ with open(results_file, "r", encoding="utf8") as infile:
lines = infile.readlines()
return [float(line.strip()) for line in lines]