diff options
| author | ziejd2 | 2021-02-24 14:36:59 -0600 |
|---|---|---|
| committer | ziejd2 | 2021-02-24 14:36:59 -0600 |
| commit | 25b843f6bbacb1937bdb960777b73acbece64115 (patch) | |
| tree | 88645b9d1d8a0eea19d7229555bf8805571bc8b7 /sourcecodes/kfold_plotly.py | |
| parent | 33cedf36248f616aa37d1462c69a4a3058a5d92e (diff) | |
| download | BNW-25b843f6bbacb1937bdb960777b73acbece64115.tar.gz | |
GENENET8 update
Diffstat (limited to 'sourcecodes/kfold_plotly.py')
| -rw-r--r-- | sourcecodes/kfold_plotly.py | 86 |
1 files changed, 59 insertions, 27 deletions
diff --git a/sourcecodes/kfold_plotly.py b/sourcecodes/kfold_plotly.py index e038c796..102d01d2 100644 --- a/sourcecodes/kfold_plotly.py +++ b/sourcecodes/kfold_plotly.py @@ -1,15 +1,13 @@ -#!/home/jziebart/python/Python-2.7.15/python +#!/var/www/html/compbio/BNW_1.3/bnw-env/bin/python import os import sys -#sys.path.append('/home/jziebart/.local/bin') -#sys.path.append('/home/jziebart/.local/lib') - import plotly import plotly.graph_objs as go import csv import string + netID = sys.argv[-1] outfile = netID+"kfold_plotly.html" @@ -17,19 +15,26 @@ outfile = netID+"kfold_plotly.html" filename=netID+"kfoldCV.txt" f=open(filename,"r") #Read the first line to get the variable name -line=f.readline() -line = map(string.strip,line.strip().split(" ")) -print line -varName = line[-1] -print varName +lines=f.readlines() +line = lines.pop() +#line = map(string.strip,line.strip().split(" ")) +line = line.strip().split(" ") +#print line +varName = line[3][:-1] +#print varName +plot_title = varName+' k-fold validation' +#print plot_title +header = lines.pop(0) #Read type file to determine if it is continuous or discrete typefile = netID+"type.txt" tf=open(typefile,"r") line=tf.readline() -varnames = map(string.strip,line.strip().split("\t")) +#varnames = map(string.strip,line.strip().split("\t")) +varnames = line.strip().split("\t") line=tf.readline() -vartypes = map(string.strip,line.strip().split("\t")) +#vartypes = map(string.strip,line.strip().split("\t")) +vartypes = line.strip().split("\t") varindex = varnames.index(varName) cd_type = int(vartypes[varindex]) @@ -37,20 +42,32 @@ cd_type = int(vartypes[varindex]) if cd_type == 1: #Make scatterplot for continuous_data #Read introductory lines from file - for i in range(6): - line = f.readline() +# for i in range(6): +# line = f.readline() #Read the data x = [] y = [] - line = f.readline() - while line: - line = map(string.strip,line.strip().split("\t")) +# line = f.readline() +# while line: + for line in lines: + #line = map(string.strip,line.strip().split("\t")) + line = line.strip().split("\t") x.append(float(line[2])) y.append(float(line[3])) - line=f.readline() +# line=f.readline() data = [go.Scatter(x=x,y=y,mode='markers')] layout = go.Layout( + title=plot_title, + titlefont=dict( + family='Arial, sans-serif', + size=24, + color='black' + ), + title_xref="paper", + title_x=0.5, + title_xanchor="center", + title_yanchor="middle", xaxis=dict( autorange=True, title='Actual values', @@ -68,7 +85,8 @@ if cd_type == 1: size=18, color='black' ), - ) + ), + margin=dict(t=30,l=50,b=40) ) fig = go.Figure(data=data, layout = layout) plotly.offline.plot(fig,filename=outfile) @@ -76,17 +94,20 @@ if cd_type == 1: else: #Make bar chart for discrete data #Read introductory lines from file - for i in range(5): - line = f.readline() +# for i in range(5): +# line = f.readline() #Get names of states - line = map(string.strip,line.strip().split("\t")) - states = line[3:] + #header = map(string.strip,header.strip().split("\t")) + header = header.strip().split("\t") + states = header[3:] #Read the data actual = [] predicted = [] - line = f.readline() - while line: - line = map(string.strip,line.strip().split("\t")) +# line = f.readline() +# while line: + for line in lines: + #line = map(string.strip,line.strip().split("\t")) + line = line.strip().split("\t") actual.append(line[2]) predict_x = line[3:] predict_x = [float(x) for x in predict_x] @@ -99,7 +120,7 @@ else: if len(max_items) > 1: predicted.pop() actual.pop() - line=f.readline() +# line=f.readline() #Go through states and get number of true positives, false positives, and false negatives tp_all = [] @@ -128,6 +149,16 @@ else: data = [trace1,trace2,trace3] layout = go.Layout( barmode='group', + title=plot_title, + titlefont=dict( + family='Arial, sans-serif', + size=24, + color='black' + ), + title_xref="paper", + title_x=0.5, + title_xanchor="center", + title_yanchor="middle", xaxis=dict( autorange=True, title='State', @@ -145,7 +176,8 @@ else: size=18, color='black' ), - ) + ), + margin=dict(t=30,l=50,b=40), ) fig = go.Figure(data=data, layout = layout) plotly.offline.plot(fig,filename=outfile) |
