Estefani Gaytan Nunez

upload

Showing 97 changed files with 166 additions and 2 deletions
...@@ -86,6 +86,9 @@ if __name__ == '__main__': ...@@ -86,6 +86,9 @@ if __name__ == '__main__':
86 scores[report[7:11]]['f1-score']=summaryScores[2] 86 scores[report[7:11]]['f1-score']=summaryScores[2]
87 87
88 print(DF(scores).T) 88 print(DF(scores).T)
89 + print('------------------------------- SAVING TABLE --------------------------------\n')
90 + with open(os.path.join(options.inputPath, str(options.figureName) ), 'w') as File:
91 +
89 scoresTable = DF(scores).T 92 scoresTable = DF(scores).T
90 93
91 imageName=os.path.join(options.outputPath, options.figureName) 94 imageName=os.path.join(options.outputPath, options.figureName)
......
1 +from optparse import OptionParser
2 +import re
3 +from collections import defaultdict as df
4 +import os
5 +import random
6 +from pandas import DataFrame as DF
7 +import matplotlib.pyplot as plt
8 +
9 +# Objective
10 +# Drawn figures of grid reports
11 +#
12 +# Input parameters
13 +# --inputPath=PATH Path of inputfiles
14 +# --outputPath=PATH Path to place output figures
15 +# --figureName single run specific name figure, multifigure first part of name
16 +# --inputFile Use it for a single report
17 +# --version CRF-script version of reports
18 +#
19 +# Output
20 +# training and test data set
21 +#
22 +# Examples
23 +# python figures-reports.py
24 +# --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/reports/
25 +# --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/figures/
26 +# --figureName FiguresGrid
27 +# --inputFile report_Run1_v11.txt
28 +# --version v11
29 +
30 +# python figures-tag-report.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/reports/ --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/figures/ --figureName FiguresGrid_v11 --version v11
31 +__author__ = 'egaytan'
32 +
33 +####################################################################################
34 +# FUNCTIONS #
35 +####################################################################################
36 +def Filter(rfile, options,v):
37 + if options[0]=='all':
38 + if rfile[0:6]=='report' and rfile[-7:-4]==v: return(True)
39 + elif rfile in options:
40 + return(True)
41 + return(False)
42 +
43 +####################################################################################
44 +# MAIN PROGRAM #
45 +####################################################################################
46 +
47 +if __name__ == '__main__':
48 + # Defining parameters
49 + parser = OptionParser()
50 + parser.add_option('--inputPath', dest='inputPath', help='Path of output from CoreNLP', metavar='PATH')
51 + parser.add_option('--outputPath', dest='outputPath', help='Path to place output figures', metavar='PATH')
52 + parser.add_option('--figureName', dest='figureName', help='Specific or first part of figurename', metavar='FILE')
53 + parser.add_option('--version', dest='version', help='script version', metavar='FILE')
54 + parser.add_option('--inputFile', dest='inputFile', help='Use it for a specific report files', metavar='FILE', default='all,')
55 +
56 + (options, args) = parser.parse_args()
57 + if len(args) > 0:
58 + parser.error('Any parameter given.\nFor multi input files be sure to seprate the filenames by coma')
59 + sys.exit(1)
60 +
61 + print('-------------------------------- PARAMETERS --------------------------------')
62 + print('Path of output from CoreNLP: ' + str(options.inputPath))
63 + print('Path to place output figures: ' + str(options.outputPath))
64 + print('Specific or first part of figurename: ' + str(options.figureName))
65 + print('CRF-script version: ' + str(options.version))
66 +
67 + print('-------------------------------- PROCESSING --------------------------------')
68 +
69 + rawInputRepotsList = str(options.inputFile).split(',')
70 + reportFileList = [ rfile for rfile in os.listdir(options.inputPath) if Filter(rfile, rawInputRepotsList, str(options.version)) ]
71 + scores = df(dict)
72 + #CV={}
73 + print('Report files: ' + str(options.inputFile ))
74 + print('\n'.join(reportFileList))
75 + print('----------------------------------- NOTE -----------------------------------')
76 + print('\n-------- All chosen report files should be in inputPath given---------------\n')
77 +
78 + print('------------------------------- SAVING DATA --------------------------------\n')
79 + OD, pH, Technique, Med, Temp, Vess, Agit, Phase, Air, Anti, Strain, Gtype, Substrain, Supp, Gversion = [], [], [], [], [], [], [], [], [], [], [], [], [], [], []
80 +
81 + precision = df(list)
82 + recall = df(list)
83 + fscore = df(list)
84 + support = df(list)
85 + for report in reportFileList:
86 + tags = {}
87 + with open(os.path.join(options.inputPath, report), 'r') as File:
88 + string = File.read()
89 + tags['OD']= re.findall('OD\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
90 + tags['pH']= re.findall('pH\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
91 + tags['Technique']= re.findall('Technique\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
92 + tags['Med']= re.findall('Med\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
93 + tags['Temp']= re.findall('Temp\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
94 + tags['Vess']= re.findall('Vess\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
95 + tags['Agit']= re.findall('Agit\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
96 + tags['Phase']= re.findall('Phase\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
97 + tags['Air']= re.findall('Air\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
98 + tags['Anti']= re.findall('Anti\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
99 + tags['Strain']= re.findall('Strain\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
100 + tags['Gtype']= re.findall('Gtype\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
101 + tags['Substrain']= re.findall('Substrain\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
102 + tags['Supp']= re.findall('Supp\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
103 + tags['Gversion']= re.findall('Gversion\s+(\d+.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)', string)[0]
104 +
105 + for k in tags.keys():
106 + precision[k].append(float(tags[k][0]))
107 + recall[k].append(float(tags[k][1]))
108 + fscore[k].append(float(tags[k][2]))
109 + #support[k].append(tags[k][3])
110 + print(DF(precision))
111 + print(precision)
112 + #lines = ['-', '--', '-.', ':', '.', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_']
113 + lines = ['-','--','-.',':','o','v','^','<','>','s','p','*','H','+','x','D','|']
114 + imageName = str(options.figureName) + '_' + str(options.version)
115 + fig = plt.figure()
116 + plt.rcParams.update({'font.size': 15})
117 + #fig.set_figheight(13)
118 + #fig.set_figwidth(20)
119 + plt.xlabel("Runs")
120 + plt.ylabel("score")
121 + plt.ylim(-0.2, 1.2)
122 + lines=['-', '--', '-.', ':', ',', 'o', 'v', '^', '<', '>', '1', '2', '3', '4', 's', 'p', '*', 'h', 'H', '+', 'x', 'D', 'd', '|', '_']
123 + for i,k in enumerate(tags.keys()):
124 + plt.grid(False)
125 +
126 + plt.plot(precision[k], lines[i], label=k, linewidth=8)
127 + plt.legend(loc='lower right')
128 + plt.tight_layout()
129 + plt.xticks(range(8),['run1', 'run2', 'run3', 'run4', 'run5', 'run6', 'run7', 'run8'])
130 + fig.savefig(imageName, bbox_inches='tight', pad_inches = 0.5)
1 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_1 --version _v12 > ../outputs/Run_1.txt
2 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_2 --version _v12 --S1 > ../outputs/Run_2.txt
3 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_3 --version _v12 --S2 > ../outputs/Run_3.txt
4 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_4 --version _v12 --S1 --S2 > ../outputs/Run_4.txt
5 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_5 --version _v12 --S3 > ../outputs/Run_5.txt
6 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_6 --version _v12 --S1 --S3 > ../outputs/Run_6.txt
7 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_7 --version _v12 --S2 --S3 > ../outputs/Run_7.txt
8 +python3 training_validation_v12.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_8 --version _v12 --S1 --S2 --S3 > ../outputs/Run_8.txt
9 +
10 +
1 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_1 --version _v13 > ../outputs/Run_1.txt
2 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_2 --version _v13 --S1 > ../outputs/Run_2.txt
3 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_3 --version _v13 --S2 > ../outputs/Run_3.txt
4 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_4 --version _v13 --S1 --S2 > ../outputs/Run_4.txt
5 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_5 --version _v13 --S3 > ../outputs/Run_5.txt
6 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_6 --version _v13 --S1 --S3 > ../outputs/Run_6.txt
7 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_7 --version _v13 --S2 --S3 > ../outputs/Run_7.txt
8 +python3 training_validation_v13.py --inputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/data-sets --trainingFile training-data-set-70.txt --testFile test-data-set-30.txt --outputPath /home/egaytan/automatic-extraction-growth-conditions/CRF/ --Gridname Run_8 --version _v13 --S1 --S2 --S3 > ../outputs/Run_8.txt
9 +
10 +
...@@ -423,7 +423,8 @@ if __name__ == "__main__": ...@@ -423,7 +423,8 @@ if __name__ == "__main__":
423 # Saving model 423 # Saving model
424 print(" Saving training model...") 424 print(" Saving training model...")
425 t1 = time() 425 t1 = time()
426 - nameModel = 'model_S1_' + str(options.S1) + '_S2_' + str(options.S2) + str(options.version) + '.mod' 426 + #nameModel = 'model_S1_' + str(options.S1) + '_S2_' + str(options.S2) + str(options.version) + '_S3_' + str(options.S3) + '.mod'
427 + nameModel = 'model_S1_' + str(options.S1) + '_S2_' + str(options.S2) + '_S3_' + str(options.S3) + '_' + str(options.Gridname) + str(options.version) + '.mod'
427 joblib.dump(crf, os.path.join(options.outputPath, "models", nameModel)) 428 joblib.dump(crf, os.path.join(options.outputPath, "models", nameModel))
428 print(" Saving training model done in: %fs" % (time() - t1)) 429 print(" Saving training model done in: %fs" % (time() - t1))
429 430
......
...@@ -423,7 +423,9 @@ if __name__ == "__main__": ...@@ -423,7 +423,9 @@ if __name__ == "__main__":
423 # Saving model 423 # Saving model
424 print(" Saving training model...") 424 print(" Saving training model...")
425 t1 = time() 425 t1 = time()
426 - nameModel = 'model_S1_' + str(options.S1) + '_S2_' + str(options.S2) + str(options.version) + '_S3_' + str(options.S3) + '.mod' 426 + #nameModel = 'model_S1_' + str(options.S1) + '_S2_' + str(options.S2) + str(options.version) + '_S3_' + str(options.S3) + '.mod'
427 + nameModel = 'model_S1_' + str(options.S1) + '_S2_' + str(options.S2) + '_S3_' + str(options.S3) + '_' + str(options.Gridname) + str(options.version) + '.mod'
428 +
427 joblib.dump(crf, os.path.join(options.outputPath, "models", nameModel)) 429 joblib.dump(crf, os.path.join(options.outputPath, "models", nameModel))
428 print(" Saving training model done in: %fs" % (time() - t1)) 430 print(" Saving training model done in: %fs" % (time() - t1))
429 431
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +mv model_S1_False_S2_False_v11_S3_False.mod model_S1_False_S2_False_S3_False_Run_1_v11.mod
2 +mv model_S1_True_S2_False_v11_S3_False.mod model_S1_True_S2_False_S3_False_Run_2_v11.mod
3 +mv model_S1_False_S2_True_v11_S3_False.mod model_S1_False_S2_True_S3_False_Run_3_v11.mod
4 +mv model_S1_True_S2_True_v11_S3_False.mod model_S1_True_S2_True_S3_False_Run_4_v11.mod
5 +mv model_S1_False_S2_False_v11_S3_True.mod model_S1_False_S2_False_S3_True_Run_5_v11.mod
6 +mv model_S1_True_S2_False_v11_S3_True.mod model_S1_True_S2_False_S3_True_Run_6_v11.mod
7 +mv model_S1_False_S2_True_v11_S3_True.mod model_S1_False_S2_True_S3_True_Run_7_v11.mod
8 +mv model_S1_True_S2_True_v11_S3_True.mod model_S1_True_S2_True_S3_True_Run_8_v11.mod
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.