Skip to content

Commit

Permalink
Fix versions and packages dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreRicoPSU committed Dec 5, 2022
1 parent be0e5e6 commit 18cef0e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 27 deletions.
8 changes: 4 additions & 4 deletions clarite/internal/calculations.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re

import numpy as np
from scipy import stats
from scipy.optimize import brentq as root

import re

from clarite.modules.analyze.utils import statsmodels_var_regex


Expand All @@ -30,7 +30,7 @@ def regTermTest(full_model, restricted_model, ddf, X_names, var_name):

def _pFsum(x, df, a, ddf):
tr = a.mean()
tr2 = (a ** 2).mean() / tr ** 2
tr2 = (a**2).mean() / tr**2
scale = tr * tr2
ndf = len(a) / tr2

Expand Down Expand Up @@ -63,7 +63,7 @@ def kprime0(z):
return (lam / (1 - 2 * z * lam)).sum()

def kpprime0(z):
return 2 * (lam ** 2 / (1 - 2 * z * lam) ** 2).sum()
return 2 * (lam**2 / (1 - 2 * z * lam) ** 2).sum()

if any(lam < 0):
lam_min = (1 / (2 * lam[lam < 0])).max() * 0.99999
Expand Down
4 changes: 3 additions & 1 deletion clarite/modules/analyze/regression/glm_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def __init__(
counts = self.data[self.outcome_variable].value_counts().to_dict()

categories = self.data[self.outcome_variable].cat.categories
categories = sorted(categories, reverse=True) # Sort reverse to keep control as 0 and case as 1
# Sort reverse to keep control as 0 and case as 1
if categories[0] == "Case" and categories[1] == "Control":
categories = sorted(categories, reverse=True)
codes, categories = zip(*enumerate(categories))
self.data[self.outcome_variable].replace(categories, codes, inplace=True)
self.description += (
Expand Down
4 changes: 2 additions & 2 deletions clarite/modules/analyze/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import Optional, List, Union
from typing import List, Optional, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -148,4 +148,4 @@ def statsmodels_var_regex(variable_name) -> str:
1) Categoricals may have the value encoded at the end (for example, Male[T.1.0])
2) Symbols in the variable name must be accounted for: (, ), -, +, etc
"""
return fr"^{re.escape(variable_name)}(\[T\..*\])?$"
return rf"^{re.escape(variable_name)}(\[T\..*\])?$"
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "clarite"
version = "2.2.0"
version = "2.2.2"
description = "CLeaning to Analysis: Reproducibility-based Interface for Traits and Exposures"
authors = ["Hall Lab <[email protected]>"]
license = "BSD-3-Clause"
Expand All @@ -16,12 +16,12 @@ classifiers=[
]

[tool.poetry.dependencies]
python = ">=3.7.1,<3.10"
python = ">=3.7.1,<3.8"
click = ">7"
pandas = ">1.1"
scipy = ">1.5"
pandas = "^1.2"
scipy = "^1.6"
seaborn = ">0.9"
statsmodels = ">0.10"
statsmodels = "^0.12"
matplotlib = "^3.4.2"
numpy = "^1.21.0"
rpy2 = "^3.4.5"
Expand All @@ -31,9 +31,9 @@ numpydoc = {version = "^1.1.0", optional = true}
sphinx_rtd_theme = {version = "^0.5.0", optional = true}
sphinx-copybutton = {version = "^0.3.0", optional = true}
ipython = {version = "^7.18.1", optional = true}
sphinx-click = {version = "^2.6", optional = true}
sphinx-click = {version = "^4", optional = true}
importlib-metadata = {version = "^2.0", python = "<3.8"}
pandas-genomics = ">=0.10.1"
pandas-genomics = "^0.11"

[tool.poetry.dev-dependencies]
codecov = "^2.1.11"
Expand All @@ -42,7 +42,7 @@ flake8 = "^3.9.2"
pytest = ">=4.6"
pytest-cov = "^2.12.1"
pytest-xdist = "^2.3.0"
black = "^21.6b0"
black = ">=22"

[tool.poetry.extras]
docs = ["sphinx", "numpydoc", "sphinx_rtd_theme", "sphinx-copybutton", "ipython", "sphinx-click"]
Expand Down
43 changes: 31 additions & 12 deletions tests/analyze/test_association_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,15 +987,34 @@ def test_edge_encondig_logistic_regression():
from pandas_genomics import sim

# Additive Main Effect for SNP1 without interaction
train_add_main_effect45 = sim.BAMS.from_model(eff1=sim.SNPEffectEncodings.ADDITIVE, eff2=sim.SNPEffectEncodings.ADDITIVE,
penetrance_base=0.45, main1=1, main2=0, interaction=0, random_seed=2021)
test_add_main_effect45 = sim.BAMS.from_model(eff1=sim.SNPEffectEncodings.ADDITIVE,
eff2=sim.SNPEffectEncodings.ADDITIVE, penetrance_base=0.45, main1=1, main2=0, interaction=0)
train_add_me_pb045 = train_add_main_effect45.generate_case_control(n_cases=5000, n_controls=5000)
test_add_me_pb045 = test_add_main_effect45.generate_case_control(n_cases=5000, n_controls=5000)
edge_weights_add_me_pb045 = train_add_me_pb045.genomics.calculate_edge_encoding_values(data=train_add_me_pb045["Outcome"], outcome_variable="Outcome")

edge_results_add_me_pb045 = clarite.analyze.association_study(
data=test_add_me_pb045, outcomes="Outcome", encoding="edge", edge_encoding_info=edge_weights_add_me_pb045)

assert 2 == 2
train = sim.BAMS.from_model(
eff1=sim.SNPEffectEncodings.ADDITIVE,
eff2=sim.SNPEffectEncodings.ADDITIVE,
penetrance_base=0.45,
main1=1,
main2=0,
interaction=0,
random_seed=2021,
)
test = sim.BAMS.from_model(
eff1=sim.SNPEffectEncodings.ADDITIVE,
eff2=sim.SNPEffectEncodings.ADDITIVE,
penetrance_base=0.45,
main1=1,
main2=0,
interaction=0,
)
train_add = train.generate_case_control(n_cases=5000, n_controls=5000)
test_add = test.generate_case_control(n_cases=5000, n_controls=5000)
edge_weights = train_add.genomics.calculate_edge_encoding_values(
data=train_add["Outcome"], outcome_variable="Outcome"
)

edge_results = clarite.analyze.association_study(
data=test_add,
outcomes="Outcome",
encoding="edge",
edge_encoding_info=edge_weights,
)

assert edge_results["Variable_type"][0] == "continuous"
Binary file modified tests/py_test_output/top_results_nhanesreal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/py_test_output/top_results_nhanesreal_no_cutoff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/py_test_output/top_results_nhanessmall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 18cef0e

Please sign in to comment.