In [4]:
import NotebookImport
from Imports import path
In [5]:
import numpy as np
import pandas as pd
In [6]:
def tranfer_fx(x, adult_age=20):
x = np.float(x)
x=(x+1)/(1+adult_age)
y = np.log(x) if x <= 1 else x - 1
return y
def anti_tranfer_fx(x, adult_age=20):
if x < 0:
return (1+adult_age)*np.exp(x)-1
else:
return (1+adult_age)*x+adult_age
In [7]:
horvath_model = pd.read_table(path + 'data/Horvath_Model.csv', index_col=0,
skiprows=[0,1])
horvath_intercept = horvath_model.CoefficientTraining['(Intercept)']
horvath_model = horvath_model.iloc[1:]
def run_horvath_model(df):
'''
Uses global variables horvath_model and horvath_intercept. At some point I should
move this to a class.
Input data-frame should be normalized using Horvath's normalization script.
'''
df = df.T.fillna(horvath_model.medianByCpG).T
df = df.ix[horvath_model.CoefficientTraining.dropna().index]
pred_age = df.T.dot(horvath_model.CoefficientTraining.dropna()) + horvath_intercept
pred_age = pred_age.apply(anti_tranfer_fx)
pred_age.name = 'predicted age (Horvath)'
return pred_age
In [8]:
hannum_model = pd.read_csv(path + 'data/Hannum_All.csv', index_col=0)
def run_hannum_model(df):
df = df.ix[hannum_model.Coefficient.index]
pred_age = df.T.dot(hannum_model.Coefficient)
pred_age.name = 'predicted age (Hannum)'
return pred_age