forked from bvilhjal/ldpred
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
81 lines (66 loc) · 4.23 KB
/
Copy pathtest.py
File metadata and controls
81 lines (66 loc) · 4.23 KB
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
"""
A test file for LDpred.
"""
import tempfile
import os
tf = tempfile.NamedTemporaryFile()
tmp_file_prefix = next(tempfile._get_candidate_names())
try:
print('Testing LDpred.\n')
print('Note that this test currently only tests the core functionality of LDpred.')
print('Please report bugs on github (https://github.com/bvilhjal/ldpred) or to Bjarni J Vilhjalmsson (bjarni.vilhjalmsson@gmail.com).\n')
coord_file = tmp_file_prefix + '.coord0.hdf5'
print('Coordinating test data into file %s' % coord_file)
cmd_str = 'python LDpred.py coord --gf=./test_data/LDpred_data_p0.001_train_0 --vgf=./test_data/LDpred_data_p0.001_test_0 --ssf=./test_data/LDpred_data_p0.001_ss_0.txt --ssf-format=STANDARD --N=10000 --out=%s' % coord_file
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems when coordinating data!'
coord_file = tmp_file_prefix + '.coord.hdf5'
print('Coordinating test data into file %s' % coord_file)
cmd_str = 'python LDpred.py --debug coord --gf=./test_data/LDpred_data_p0.001_train_0 --vbim=./test_data/LDpred_data_p0.001_test_0.bim --ssf=./test_data/LDpred_data_p0.001_ss_0.txt --ssf-format=STANDARD --beta --N=10000 --out=%s' % coord_file
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems when coordinating data!'
print('Running LDpred-inf with coordinated file prefix: %s ' % tmp_file_prefix)
cmd_str = 'python LDpred.py --debug inf --cf=%s --ldr=100 --ldf=%s --N=10000 --out=%s' % (coord_file, tmp_file_prefix, tmp_file_prefix)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems when running LDpred_inf!'
print('Running LDpred with coordinated file prefix: %s ' % tmp_file_prefix)
cmd_str = 'python LDpred.py --debug gibbs --cf=%s --ldr=100 --ldf=%s --f=0.001 --N=10000 --out=%s' % (coord_file, tmp_file_prefix, tmp_file_prefix)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems when running LDpred!'
print('Running P+T with coordinated file prefix: %s ' % tmp_file_prefix)
cmd_str = 'python LDpred.py --debug p+t --cf=%s --ldr=100 --p=0.001 --out=%s' % (coord_file, tmp_file_prefix)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems when running P+T!'
prs_file_prefix = tmp_file_prefix + 'prs'
print('Validating results with output file prefix: %s' % tmp_file_prefix)
cmd_str = 'python LDpred.py --debug score --gf=./test_data/LDpred_data_p0.001_test_0 --rf=%s --out=%s' % (tmp_file_prefix, prs_file_prefix)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems with the validation step!'
prs_file_prefix2 = tmp_file_prefix + 'prs_2'
print('Validating results with output file prefix: %s' % tmp_file_prefix)
cmd_str = 'python LDpred.py score --gf=./test_data/LDpred_data_p0.001_test_0 --rf=%s --out=%s' % (tmp_file_prefix, prs_file_prefix2)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems with the validation step!'
print('Test finished successfully!')
print('Validating results with output file prefix: %s' % tmp_file_prefix)
cmd_str = 'python LDpred.py score --gf=./test_data/LDpred_data_p0.001_test_0 --rf=%s --rf-format=P+T --out=%s' % (tmp_file_prefix, prs_file_prefix)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems with the P+T validation step!'
print('Test finished successfully!')
prs_file_prefix3 = tmp_file_prefix + 'prs_3'
print('Validating results with output file prefix: %s' % tmp_file_prefix)
cmd_str = 'python LDpred.py score --gf=./test_data/LDpred_data_p0.001_test_0 --only-score --rf=%s --rf-format=P+T --out=%s' % (tmp_file_prefix, prs_file_prefix3)
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems with the P+T validation step!'
print('Test finished successfully!')
except Exception as e:
print("Test failed: ",e)
print('Cleaning up files.')
cmd_str = 'rm %s*' % tmp_file_prefix
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems cleaning up test files! Testing stopped'
raise Exception('Test failed.')
print('Cleaning up files.')
cmd_str = 'rm %s*' % tmp_file_prefix
print(cmd_str + '\n')
assert os.system(cmd_str) == 0, 'Problems cleaning up test files! Testing stopped'