From ab8b68819fc799552c6ea817d547151a6cb15198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20F=2E=20Mu=C3=B1oz?= Date: Thu, 29 Feb 2024 15:52:06 -0500 Subject: [PATCH] Add minor lint/docs changes, and prevent Windows systems from crashing (#58) add docs for p_values function - make cache dir compatible with WIN --- src/copairs/compute.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/copairs/compute.py b/src/copairs/compute.py index da78ec6..d290af8 100644 --- a/src/copairs/compute.py +++ b/src/copairs/compute.py @@ -1,5 +1,5 @@ -import os import itertools +import os from multiprocessing.pool import ThreadPool from pathlib import Path from typing import Callable @@ -135,7 +135,7 @@ def null_dist_cached(num_pos, total, seed, null_size, cache_dir): def get_null_dists(confs, null_size, seed): - cache_dir = Path.home() / f".copairs/seed{seed}/ns{null_size}" + cache_dir = Path.home() / ".copairs" / f"seed{seed}" / f"ns{null_size}" cache_dir.mkdir(parents=True, exist_ok=True) num_confs = len(confs) rng = np.random.default_rng(seed) @@ -151,7 +151,27 @@ def par_func(i): return null_dists -def p_values(ap_scores, null_confs, null_size: int, seed): +def p_values(ap_scores: np.ndarray, null_confs: np.ndarray, null_size: int, seed: int): + """Calculate p values for an array of ap_scores and null configurations. It uses the path + folder to cache null calculations. + + Parameters + ---------- + ap_scores : np.ndarray + Ap scores for which to calculate p value. + null_confs : np.ndarray + Number of average precisions calculated. It serves as an indicator of + how relevant is the resultant score. + null_size : int + seed : int + Random initializing value. + + Examples + -------- + FIXME: Add docs. + + + """ confs, rev_ix = np.unique(null_confs, axis=0, return_inverse=True) null_dists = get_null_dists(confs, null_size, seed) null_dists.sort(axis=1)