forked from ymulyo/cancerSurvivalEstimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunBC.py
55 lines (49 loc) · 1.84 KB
/
runBC.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
import subprocess
import pandas as pd
import time
test_var = ['control' ,'year_of_birth','race','ethnicity','tumor_stage','days_to_last_follow_up','simple_somatic_mutations','genes_with_simple_somatic_mutations']
results=pd.DataFrame(columns=test_var)
propertiesResults=pd.DataFrame(columns=test_var)
t0 = time.time()
for t in range(0,5):
t1=time.time()
bashCommand = "python3 randomForestBC.py"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
runResults = []
propResults = []
f = open('BCrun.txt')
current = f.readline().replace('\n','')
tests = []
while (current != ''):
#print(current)
properties = []
mae = []
m = float('inf')
mins = []
if current in test_var:
tests.append(current)
#print(current)
current = f.readline().replace('\n','')
while (current not in test_var and current != ''):
current = current.replace('([','').replace(']','').replace(')','').replace(' ','')
current = current.split(',')
mae.append(current[6])
properties.append(current[0:6])
if float(current[6])<m:
mins=[]
mins.append(len(mae)-1)
m = float(current[6])
elif float(current[6])==m:
mins.append(len(mae))
current = f.readline().replace('\n','')
runResults.append(m)
propResults.append(properties[mins[0]])
results.loc[t]=runResults
propertiesResults.loc[t]=propResults
t2=time.time()
print('runtime (in seconds) = '+str(t2-t1))
results.to_csv('BCmae.csv')
propertiesResults.to_csv('BCproperties.csv')
t3=time.time()
print('Total time alotted (in seconds) = '+str(t3-t0))