diff options
author | Frederick Muriuki Muriithi | 2022-12-02 07:26:13 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-12-02 07:26:13 +0300 |
commit | 156e6e4c372f3b4c24d5c07c02603a29d0d95412 (patch) | |
tree | 9ce8b0fd289a8bcce0729a289f8833a03922c0f3 /gn3 | |
parent | d1a425f924b2106115c05ac8054f2588c8e80446 (diff) | |
download | genenetwork3-156e6e4c372f3b4c24d5c07c02603a29d0d95412.tar.gz |
correlations: return `None` rather than zero for missing lit corrs
* gn3/computations/correlations.py: Return `None` for missing literature
correlations rather than zero. Update the sorting key to avoid issues with
comparing floats to NoneType objects
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/computations/correlations.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index 5a9ce62..8e8bea5 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -269,9 +269,9 @@ def fetch_lit_correlation_data( *tuple(reversed(query_values)))) lit_corr_results = cursor.fetchone() lit_results = (gene_id, lit_corr_results[0])\ - if lit_corr_results else (gene_id, 0) + if lit_corr_results else (gene_id, None) return lit_results - return (gene_id, 0) + return (gene_id, None) def lit_correlation_for_trait( @@ -339,14 +339,19 @@ def compute_all_lit_correlation(conn, trait_lists: List, """Function that acts as an abstraction for lit_correlation_for_trait""" + def __sorter__(trait_name): + val = list(trait_name.values())[0]["lit_corr"] + try: + return (0, -abs(val)) + except TypeError: + return (1, val) + lit_results = lit_correlation_for_trait( conn=conn, target_trait_lists=trait_lists, species=species, trait_gene_id=gene_id) - sorted_lit_results = sorted( - lit_results, - key=lambda trait_name: -abs(list(trait_name.values())[0]["lit_corr"])) + sorted_lit_results = sorted(lit_results, key=__sorter__) return sorted_lit_results |