-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_testing.py
410 lines (340 loc) · 20.5 KB
/
model_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
import numpy as np
from sklearn.svm import SVR
#from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn.model_selection import cross_val_score
from statistics import mean
import math
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import scale
from pandas import DataFrame
import pickle
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVR
from sklearn.neighbors import KNeighborsRegressor
import time
from scipy import stats
import argparse
from sklearn.linear_model import ElasticNet
parser = argparse.ArgumentParser()
parser.add_argument("chr", action="store", help="put chromosome no")
args = parser.parse_args() #22
chrom = args.chr
pop = "AFA"
#time the whole script per chromosome
#open("/home/paul/mesa_models/python_ml_models/whole_script_chr"+str(chrom)+"_timer.txt", "w").write("Chrom"+"\t"+"Time(s)"+"\n")
#t0 = time.time()
#important functions needed
def get_filtered_snp_annot (snpfilepath):
snpanot = pd.read_csv(snpfilepath, sep="\t")
#snpanot = snpanot[((snpanot["refAllele"]=="A") & (snpanot["effectAllele"]=="C")) | ((snpanot["refAllele"]=="C") & (snpanot["effectAllele"]=="A")) | ((snpanot["refAllele"]=="A") & (snpanot["effectAllele"]=="G")) | ((snpanot["refAllele"]=="G") & (snpanot["effectAllele"]=="A")) | ((snpanot["refAllele"]=="T") & (snpanot["effectAllele"]=="G")) | ((snpanot["refAllele"]=="G") & (snpanot["effectAllele"]=="T")) | ((snpanot["refAllele"]=="T") & (snpanot["effectAllele"]=="C")) | ((snpanot["refAllele"]=="C") & (snpanot["effectAllele"]=="T"))]
snpanot = snpanot[(((snpanot["refAllele"]=="A") & (snpanot["effectAllele"]=="C")) | ((snpanot["refAllele"]=="C") & (snpanot["effectAllele"]=="A")) | ((snpanot["refAllele"]=="A") & (snpanot["effectAllele"]=="G")) | ((snpanot["refAllele"]=="G") & (snpanot["effectAllele"]=="A")) | ((snpanot["refAllele"]=="T") & (snpanot["effectAllele"]=="G")) | ((snpanot["refAllele"]=="G") & (snpanot["effectAllele"]=="T")) | ((snpanot["refAllele"]=="T") & (snpanot["effectAllele"]=="C")) | ((snpanot["refAllele"]=="C") & (snpanot["effectAllele"]=="T"))) & (snpanot["rsid"].notna())]
snpanot = snpanot.drop_duplicates(["varID"])
return snpanot
def get_gene_annotation (gene_anot_filepath, chrom, gene_types=["protein_coding"]):
gene_anot = pd.read_csv(gene_anot_filepath, sep="\t")
gene_anot = gene_anot[(gene_anot["chr"]==str(chrom)) & (gene_anot["gene_type"].isin(gene_types))]
return gene_anot
def get_gene_type (gene_anot, gene):
gene_type = gene_anot[gene_anot["gene_id"]==gene]
gene_type = gene_type.iloc[0,5]
return gene_type
def get_gene_name (gene_anot, gene):
gene_name = gene_anot[gene_anot["gene_id"]==gene]
gene_name = gene_name.iloc[0,2]
return gene_name
def get_gene_coords (gene_anot, gene):
gene_type = gene_anot[gene_anot["gene_id"]==gene]
gene_coord = [gene_type.iloc[0,3], gene_type.iloc[0,4]]
return gene_coord
def get_covariates (cov_filepath):
cov = pd.read_csv(cov_filepath, sep=" ")
cov = cov.set_index("IID") #make IID to be the row names
cov.index.names = [None] # remove the iid name from the row
pc = ["PC1", "PC2", "PC3"] #a list of the PCs to retain
cov = cov[pc]
return cov
def get_gene_expression(gene_expression_file_name, gene_annot):
expr_df = pd.read_csv(gene_expression_file_name, header = 0, index_col = 0, delimiter='\t')
expr_df = expr_df.T
inter = list(set(gene_annot['gene_id']).intersection(set(expr_df.columns)))
#print(len(inter))
expr_df = expr_df.loc[:, inter ]
return expr_df
def adjust_for_covariates (expr_vec, cov_df):
reg = LinearRegression().fit(cov_df, expr_vec)
ypred = reg.predict(cov_df)
residuals = expr_vec - ypred
residuals = scale(residuals)
return residuals
def get_maf_filtered_genotype(genotype_file_name, maf):
gt_df = pd.read_csv(genotype_file_name, 'r', header = 0, index_col = 0,delimiter='\t')
effect_allele_freqs = gt_df.mean(axis=1)
effect_allele_freqs = [ x / 2 for x in effect_allele_freqs ]
effect_allele_boolean = pd.Series([ ((x >= maf) & (x <= (1 - maf))) for x in effect_allele_freqs ]).values
gt_df = gt_df.loc[ effect_allele_boolean ]
gt_df = gt_df.T
return gt_df
def get_cis_genotype (gt_df, snp_annot, coords, cis_window=1000000):
snp_info = snpannot[(snpannot['pos'] >= (coords[0] - cis_window)) & (snpannot['rsid'].notna()) & (snpannot['pos'] <= (coords[1] + cis_window))]
if len(snp_info) == 0:
return 0
else:
gtdf_col = list(gt_df.columns)
snpinfo_col = list(snp_info["varID"])
intersect = snps_intersect(gtdf_col, snpinfo_col) #this function was defined earlier
cis_gt = gt_df[intersect]
return cis_gt
def calc_R2 (y, y_pred):
tss = 0
rss = 0
for i in range(len(y)):
tss = tss + (y[i])**2
rss = rss + (((y[i]) - (y_pred[i]))**2)
tss = float(tss)
rss = float(rss)
r2 = 1 - (rss/tss)
return r2
def calc_corr (y, y_pred):
num = 0
dem1 = 0
dem2 = 0
for i in range(len(y)):
num = num + ((y[i]) * (y_pred[i]))
dem1 = dem1 + (y[i])**2
dem2 = dem2 + (y_pred[i])**2
num = float(num)
dem1 = math.sqrt(float(dem1))
dem2 = math.sqrt(float(dem2))
rho = num/(dem1*dem2)
return rho
def snps_intersect(list1, list2):
return list(set(list1) & set(list2))
#chrom = 21 #chromosome number. #this is removed. and initialized early at the top
afa_snp = "/home/paul/mesa_models/AFA_"+str(chrom)+"_snp.txt"
gex = "/home/paul/mesa_models/meqtl_sorted_AFA_MESA_Epi_GEX_data_sidno_Nk-10.txt"
cov_file = "/home/paul/mesa_models/AFA_3_PCs.txt"
geneanotfile = "/home/paul/mesa_models/gencode.v18.annotation.parsed.txt"
snpfilepath = "/home/paul/mesa_models/AFA_"+str(chrom)+"_annot.txt"
#test data files
#test_snp = "/home/paul/mesa_models/his/HIS_"+str(chrom)+"_snp.txt"
#test_gex = "/home/paul/mesa_models/meqtl_sorted_HIS_MESA_Epi_GEX_data_sidno_Nk-10.txt"
#test_covfile = "/home/paul/mesa_models/his/HIS_3_PCs.txt"
#test_snpfile = "/home/paul/mesa_models/his/HIS_"+str(chrom)+"_annot.txt"
#train functioning
snpannot = get_filtered_snp_annot(snpfilepath)
geneannot = get_gene_annotation(geneanotfile, chrom)
cov = get_covariates(cov_file)
expr_df = get_gene_expression(gex, geneannot)
genes = list(expr_df.columns)
gt_df = get_maf_filtered_genotype(afa_snp, 0.01)
train_ids = list(gt_df.index)
adj_exp_frame = pd.DataFrame()
"""
#test functioning
test_snpannot = get_filtered_snp_annot(test_snpfile)
test_cov = get_covariates(test_covfile)
test_expr_df = get_gene_expression(test_gex, geneannot)
test_genes = list(test_expr_df.columns)
test_gt_df = get_maf_filtered_genotype(test_snp, 0.01)
test_ids = list(test_gt_df.index)
#frame to store the ypred and test adjusted expression
ypred_frame_rf = pd.DataFrame()
ypred_frame_svrl = pd.DataFrame()
ypred_frame_svr = pd.DataFrame()
ypred_frame_knn = pd.DataFrame()
ypred_frame_elnet = pd.DataFrame()
test_adj_exp_frame = pd.DataFrame()
#algorithms to use
rf = RandomForestRegressor(max_depth=None, random_state=1234, n_estimators=100)
svrl = SVR(kernel="linear", gamma="auto")
svr = SVR(kernel="rbf", gamma="auto")
knn = KNeighborsRegressor(n_neighbors=10, weights = "distance")
elnet = ElasticNet(alpha=0.1, random_state=1234)
#models = [rf,svrl,svr,knn]
#text file where to write out the cv and test results
#open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_rf_cor_test_chr"+str(chrom)+".txt", "w").write("gene_id"+"\t"+"gene_name"+"\t"+"pearson_yadj_vs_ypred (a)"+"\t"+"a_pval"+"\t"+"pearson_yobs_vs_ypred (b)"+"\t"+"b_pval"+"\t"+"spearman_yadj_vs_ypred (c)"+"\t"+"c_pval"+"\t"+"spearman_yobs_vs_ypred (d)"+"\t"+"d_pval"+"\n")
#open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_knn_cor_test_chr"+str(chrom)+".txt", "w").write("gene_id"+"\t"+"gene_name"+"\t"+"pearson_yadj_vs_ypred (a)"+"\t"+"a_pval"+"\t"+"pearson_yobs_vs_ypred (b)"+"\t"+"b_pval"+"\t"+"spearman_yadj_vs_ypred (c)"+"\t"+"c_pval"+"\t"+"spearman_yobs_vs_ypred (d)"+"\t"+"d_pval"+"\n")
#open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_svr_linear_cor_test_chr"+str(chrom)+".txt", "w").write("gene_id"+"\t"+"gene_name"+"\t"+"pearson_yadj_vs_ypred (a)"+"\t"+"a_pval"+"\t"+"pearson_yobs_vs_ypred (b)"+"\t"+"b_pval"+"\t"+"spearman_yadj_vs_ypred (c)"+"\t"+"c_pval"+"\t"+"spearman_yobs_vs_ypred (d)"+"\t"+"d_pval"+"\n")
#open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_svr_rbf_cor_test_chr"+str(chrom)+".txt", "w").write("gene_id"+"\t"+"gene_name"+"\t"+"pearson_yadj_vs_ypred (a)"+"\t"+"a_pval"+"\t"+"pearson_yobs_vs_ypred (b)"+"\t"+"b_pval"+"\t"+"spearman_yadj_vs_ypred (c)"+"\t"+"c_pval"+"\t"+"spearman_yobs_vs_ypred (d)"+"\t"+"d_pval"+"\n")
#open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_elnet_cor_test_chr"+str(chrom)+".txt", "w").write("gene_id"+"\t"+"gene_name"+"\t"+"pearson_yadj_vs_ypred (a)"+"\t"+"a_pval"+"\t"+"pearson_yobs_vs_ypred (b)"+"\t"+"b_pval"+"\t"+"spearman_yadj_vs_ypred (c)"+"\t"+"c_pval"+"\t"+"spearman_yobs_vs_ypred (d)"+"\t"+"d_pval"+"\n")
"""
for gene in genes:
#prepare test_adj_exp for writing out to a file
gg = [gene] #just to cast the gene id to list because pandas need it to be in list before it can be used as col name
coords = get_gene_coords(geneannot, gene)
expr_vec = expr_df[gene]#observed exp
adj_exp = adjust_for_covariates(list(expr_vec), cov)#adjusted exp
adj_exp_pd = pd.DataFrame(adj_exp)
adj_exp_pd.columns = gg
adj_exp_pd.index = train_ids
adj_exp_frame = pd.concat([adj_exp_frame, adj_exp_pd], axis=1, sort=True)
"""
if gene in test_genes:
coords = get_gene_coords(geneannot, gene)
gene_name = get_gene_name(geneannot, gene)
#print(gene)
expr_vec = expr_df[gene]#observed exp
test_expr_vec = test_expr_df[gene]#observed exp
#print(expr_vec)
adj_exp = adjust_for_covariates(list(expr_vec), cov)#adjusted exp
test_adj_exp = adjust_for_covariates(list(test_expr_vec), test_cov)#adjusted exp
#break
#expr_vec = expr_df[gene]
#adj_exp = adjust_for_covariates(expr_vec, cov)
cis_gt = get_cis_genotype(gt_df, snpannot, coords)
test_cis_gt = get_cis_genotype(test_gt_df, test_snpannot, coords)
if (type(cis_gt) != int) & (type(test_cis_gt) != int):#just to be sure the cis genotype is not empty
gg = [gene] #just to cast the gene id to list because pandas need it to be in list before it can be used as col name
#take the snps
train_snps = list(cis_gt.columns)
test_snps = list(test_cis_gt.columns)
snp_intersect = snps_intersect(train_snps, test_snps)
cis_gt = cis_gt[snp_intersect]
test_cis_gt = test_cis_gt[snp_intersect]
if (cis_gt.shape[1] > 0) & (test_cis_gt.shape[1] > 0): #make sure that the cis_gt is not empty
#build the model
#adj_exp = adj_exp.values #not needed after making adj_exp a numpy array above
cis_gt = cis_gt.values
test_cis_gt = test_cis_gt.values
test_yobs = test_expr_vec.values
#prepare test_adj_exp for writing out to a file
test_adj_exp_pd = pd.DataFrame(test_adj_exp)
test_adj_exp_pd.columns = gg
test_adj_exp_pd.index = test_ids
test_adj_exp_frame = pd.concat([test_adj_exp_frame, test_adj_exp_pd], axis=1, sort=True)
#these steps can be shortened with a loop where the models are in a list or dictionary
#Random Forest
#rf_t0 = time.time()#do rf and time it
#rf_cv = str(float(mean(cross_val_score(rf, cis_gt, adj_exp.ravel(), cv=5))))
#rf_t1 = time.time()
#rf_tt = str(float(rf_t1 - rf_t0))
elnet.fit(cis_gt, adj_exp.ravel())
ypred = elnet.predict(test_cis_gt)
#prepare ypred for writing out to a file
ypred_pd = pd.DataFrame(ypred)
ypred_pd.columns = gg
ypred_pd.index = test_ids
ypred_frame_elnet = pd.concat([ypred_frame_rf, ypred_pd], axis=1, sort=True)
pa = stats.pearsonr(test_adj_exp, ypred)
pacoef = str(float(pa[0]))
papval = str(float(pa[1]))
pb = stats.pearsonr(test_yobs, ypred)
pbcoef = str(float(pb[0]))
pbpval = str(float(pb[1]))
sc = stats.spearmanr(test_adj_exp, ypred)
sccoef = str(float(sc[0]))
scpval = str(float(sc[1]))
sd = stats.spearmanr(test_yobs, ypred)
sdcoef = str(float(sd[0]))
sdpval = str(float(sd[1]))
open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_elnet_cor_test_chr"+str(chrom)+".txt", "a").write(gene+"\t"+gene_name+"\t"+pacoef+"\t"+papval+"\t"+pbcoef+"\t"+pbpval+"\t"+sccoef+"\t"+scpval+"\t"+sdcoef+"\t"+sdpval+"\n")
rf.fit(cis_gt, adj_exp.ravel())
ypred = rf.predict(test_cis_gt)
#prepare ypred for writing out to a file
ypred_pd = pd.DataFrame(ypred)
ypred_pd.columns = gg
ypred_pd.index = test_ids
ypred_frame_rf = pd.concat([ypred_frame_rf, ypred_pd], axis=1, sort=True)
pa = stats.pearsonr(test_adj_exp, ypred)
pacoef = str(float(pa[0]))
papval = str(float(pa[1]))
pb = stats.pearsonr(test_yobs, ypred)
pbcoef = str(float(pb[0]))
pbpval = str(float(pb[1]))
sc = stats.spearmanr(test_adj_exp, ypred)
sccoef = str(float(sc[0]))
scpval = str(float(sc[1]))
sd = stats.spearmanr(test_yobs, ypred)
sdcoef = str(float(sd[0]))
sdpval = str(float(sd[1]))
open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_rf_cor_test_chr"+str(chrom)+".txt", "a").write(gene+"\t"+gene_name+"\t"+pacoef+"\t"+papval+"\t"+pbcoef+"\t"+pbpval+"\t"+sccoef+"\t"+scpval+"\t"+sdcoef+"\t"+sdpval+"\n")
#SVR Linear
#svrl_t0 = time.time()#time it
#svrl_cv = str(float(mean(cross_val_score(svrl, cis_gt, adj_exp.ravel(), cv=5))))
#svrl_t1 = time.time()
#svrl_tt = str(float(svrl_t1 - svrl_t0))
svrl.fit(cis_gt, adj_exp.ravel())
ypred = svrl.predict(test_cis_gt)
#prepare ypred for writing out to a file
yprep_pd = pd.DataFrame(ypred)
ypred_pd.columns = gg
ypred_pd.index = test_ids
ypred_frame_svrl = pd.concat([ypred_frame_svrl, ypred_pd], axis=1, sort=True)
pa = stats.pearsonr(test_adj_exp, ypred)
pacoef = str(float(pa[0]))
papval = str(float(pa[1]))
pb = stats.pearsonr(test_yobs, ypred)
pbcoef = str(float(pb[0]))
pbpval = str(float(pb[1]))
sc = stats.spearmanr(test_adj_exp, ypred)
sccoef = str(float(sc[0]))
scpval = str(float(sc[1]))
sd = stats.spearmanr(test_yobs, ypred)
sdcoef = str(float(sd[0]))
sdpval = str(float(sd[1]))
open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_svr_linear_cor_test_chr"+str(chrom)+".txt", "a").write(gene+"\t"+gene_name+"\t"+pacoef+"\t"+papval+"\t"+pbcoef+"\t"+pbpval+"\t"+sccoef+"\t"+scpval+"\t"+sdcoef+"\t"+sdpval+"\n")
#SVR RBF
#svr_t0 = time.time()#time it
#svr_cv = str(float(mean(cross_val_score(svr, cis_gt, adj_exp.ravel(), cv=5))))
#svr_t1 = time.time()
#svr_tt = str(float(svr_t1 - svr_t0))
svr.fit(cis_gt, adj_exp.ravel())
ypred = svr.predict(test_cis_gt)
#prepare ypred for writing out to a file
yprep_pd = pd.DataFrame(ypred)
ypred_pd.columns = gg
ypred_pd.index = test_ids
ypred_frame_svr = pd.concat([ypred_frame_svr, ypred_pd], axis=1, sort=True)
pa = stats.pearsonr(test_adj_exp, ypred)
pacoef = str(float(pa[0]))
papval = str(float(pa[1]))
pb = stats.pearsonr(test_yobs, ypred)
pbcoef = str(float(pb[0]))
pbpval = str(float(pb[1]))
sc = stats.spearmanr(test_adj_exp, ypred)
sccoef = str(float(sc[0]))
scpval = str(float(sc[1]))
sd = stats.spearmanr(test_yobs, ypred)
sdcoef = str(float(sd[0]))
sdpval = str(float(sd[1]))
open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_svr_rbf_cor_test_chr"+str(chrom)+".txt", "a").write(gene+"\t"+gene_name+"\t"+pacoef+"\t"+papval+"\t"+pbcoef+"\t"+pbpval+"\t"+sccoef+"\t"+scpval+"\t"+sdcoef+"\t"+sdpval+"\n")
#KNN
#knn_t0 = time.time()#time it
#knn_cv = str(float(mean(cross_val_score(knn, cis_gt, adj_exp.ravel(), cv=5))))
#knn_t1 = time.time()
#knn_tt = str(float(knn_t1 - knn_t0))
knn.fit(cis_gt, adj_exp.ravel())
ypred = knn.predict(test_cis_gt)
#prepare ypred for writing out to a file
yprep_pd = pd.DataFrame(ypred)
ypred_pd.columns = gg
ypred_pd.index = test_ids
ypred_frame_knn = pd.concat([ypred_frame_knn, ypred_pd], axis=1, sort=True)
pa = stats.pearsonr(test_adj_exp, ypred)
pacoef = str(float(pa[0]))
papval = str(float(pa[1]))
pb = stats.pearsonr(test_yobs, ypred)
pbcoef = str(float(pb[0]))
pbpval = str(float(pb[1]))
sc = stats.spearmanr(test_adj_exp, ypred)
sccoef = str(float(sc[0]))
scpval = str(float(sc[1]))
sd = stats.spearmanr(test_yobs, ypred)
sdcoef = str(float(sd[0]))
sdpval = str(float(sd[1]))
open("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_knn_cor_test_chr"+str(chrom)+".txt", "a").write(gene+"\t"+gene_name+"\t"+pacoef+"\t"+papval+"\t"+pbcoef+"\t"+pbpval+"\t"+sccoef+"\t"+scpval+"\t"+sdcoef+"\t"+sdpval+"\n")
ypred_frame_rf.to_csv("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_rf_predicted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
ypred_frame_svrl.to_csv("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_svr_linear_predicted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
ypred_frame_svr.to_csv("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_svr_rbf_predicted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
ypred_frame_knn.to_csv("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_knn_predicted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
test_adj_exp_frame.to_csv("/home/paul/mesa_models/python_ml_models/results/"+pop+"_pc_adjusted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
ypred_frame_elnet.to_csv("/home/paul/mesa_models/python_ml_models/results/AFA_2_"+pop+"_elnet_predicted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
"""
adj_exp_frame.to_csv("/home/paul/mesa_models/python_ml_models/results/"+pop+"_pc_adjusted_gene_expr_chr"+str(chrom)+".txt", header=True, index=True, sep="\t")
#t1 = time.time()
#total = str(float(t1-t0))
#open("/home/paul/mesa_models/python_ml_models/whole_script_chr"+str(chrom)+"_timer.txt", "a").write(str(chrom)+"\t"+total+"\n")
#coords = get_gene_coords(geneannot, "geneID")#this is where to loop for gene id
#adj_exp = adjust_for_covariates(expr_vec, cov) #this is loop side
#cis_gt = get_cis_genotype(gt_df, snpannot, coords) #this is loop side