|
a |
|
b/src/utils/UpSetR.java |
|
|
1 |
/* |
|
|
2 |
* To change this license header, choose License Headers in Project Properties. |
|
|
3 |
* To change this template file, choose Tools | Templates |
|
|
4 |
* and open the template in the editor. |
|
|
5 |
*/ |
|
|
6 |
package utils; |
|
|
7 |
|
|
|
8 |
import biodiscml.BestModelSelectionAndReport; |
|
|
9 |
import java.io.BufferedReader; |
|
|
10 |
import java.io.FileReader; |
|
|
11 |
import java.io.FileWriter; |
|
|
12 |
import java.io.PrintWriter; |
|
|
13 |
import java.util.ArrayList; |
|
|
14 |
import java.util.HashMap; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* |
|
|
18 |
* @author mickael |
|
|
19 |
*/ |
|
|
20 |
public class UpSetR { |
|
|
21 |
|
|
|
22 |
public void creatUpSetRDataset(String featureSelectionFile, String predictionsResultsFile) { |
|
|
23 |
System.out.println("# create UpSetR file"); |
|
|
24 |
String outfile = predictionsResultsFile.replace(".csv", ".UpSetR.csv"); |
|
|
25 |
//create header |
|
|
26 |
ArrayList<String> featuresHeader = new ArrayList<>(); |
|
|
27 |
try { |
|
|
28 |
BufferedReader br = new BufferedReader(new FileReader(featureSelectionFile.replace(".csv", ".arff"))); |
|
|
29 |
String line = br.readLine(); //relation |
|
|
30 |
br.readLine(); //empty line |
|
|
31 |
line = br.readLine(); // @attribute |
|
|
32 |
while (line.startsWith("@attribute")) { |
|
|
33 |
featuresHeader.add(line.replace("@attribute ", "").replaceAll(" \\w+$", "")); |
|
|
34 |
line = br.readLine(); |
|
|
35 |
} |
|
|
36 |
} catch (Exception e) { |
|
|
37 |
e.printStackTrace(); |
|
|
38 |
} |
|
|
39 |
featuresHeader.remove(featuresHeader.size() - 1); |
|
|
40 |
featuresHeader.remove(0); |
|
|
41 |
|
|
|
42 |
//output |
|
|
43 |
try { |
|
|
44 |
BufferedReader br = new BufferedReader(new FileReader(predictionsResultsFile)); |
|
|
45 |
PrintWriter pw = new PrintWriter(new FileWriter(outfile)); |
|
|
46 |
pw.println("ID," |
|
|
47 |
+ "TRAIN_10CV_MCC" |
|
|
48 |
+ ",TRAIN_LOOCV_MCC" |
|
|
49 |
+ ",TRAIN_BS_MCC" |
|
|
50 |
+ ",TEST_MCC" |
|
|
51 |
+ ",TRAIN_TEST_BS_MCC" |
|
|
52 |
+ ",AVG_MCC," |
|
|
53 |
+ featuresHeader.toString().replace("[", "").replace("]", "").trim() + ""); |
|
|
54 |
|
|
|
55 |
pw.flush(); |
|
|
56 |
String line = br.readLine(); |
|
|
57 |
|
|
|
58 |
while (br.ready()) { |
|
|
59 |
line = br.readLine(); |
|
|
60 |
BestModelSelectionAndReport.classificationObject co = new BestModelSelectionAndReport.classificationObject(line); |
|
|
61 |
|
|
|
62 |
//get ID |
|
|
63 |
ArrayList<String> featureList = co.featureList; |
|
|
64 |
featureList.remove(featureList.size() - 1); |
|
|
65 |
featureList.remove(0); |
|
|
66 |
int[] tab = new int[featuresHeader.size()]; |
|
|
67 |
try { |
|
|
68 |
for (String index : featureList) { |
|
|
69 |
tab[Integer.valueOf(index) - 2] = 1; |
|
|
70 |
} |
|
|
71 |
} catch (Exception e) { |
|
|
72 |
e.printStackTrace(); |
|
|
73 |
} |
|
|
74 |
String features = ""; |
|
|
75 |
for (int i : tab) { |
|
|
76 |
features += "," + i; |
|
|
77 |
} |
|
|
78 |
|
|
|
79 |
String out = "" + co.identifier + "" |
|
|
80 |
+ "," + co.hmValues.get("TRAIN_10CV_MCC") |
|
|
81 |
+ "," + co.hmValues.get("TRAIN_LOOCV_MCC") |
|
|
82 |
+ "," + co.hmValues.get("TRAIN_BS_MCC") |
|
|
83 |
+ "," + co.hmValues.get("TEST_MCC") |
|
|
84 |
+ "," + co.hmValues.get("TRAIN_TEST_BS_MCC") |
|
|
85 |
+ "," + co.hmValues.get("AVG_MCC") + features + ""; |
|
|
86 |
pw.println(out); |
|
|
87 |
} |
|
|
88 |
pw.close(); |
|
|
89 |
} catch (Exception e) { |
|
|
90 |
e.printStackTrace(); |
|
|
91 |
} |
|
|
92 |
System.out.println("UpSetR file: " + outfile); |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
public void creatUpSetRDatasetFromSignature(BestModelSelectionAndReport.classificationObject co_model, |
|
|
96 |
String featureSelectionFile, String predictionsResultsFile) { |
|
|
97 |
System.out.println("# create UpSetR file"); |
|
|
98 |
String outfile = predictionsResultsFile.replace(".csv", ".UpSetR.csv"); |
|
|
99 |
//create header |
|
|
100 |
ArrayList<String> alFeaturesOrder = new ArrayList<>(); |
|
|
101 |
try { |
|
|
102 |
BufferedReader br = new BufferedReader(new FileReader(featureSelectionFile.replace(".csv", ".arff"))); |
|
|
103 |
String line = br.readLine(); //relation |
|
|
104 |
br.readLine(); //empty line |
|
|
105 |
line = br.readLine(); // @attribute |
|
|
106 |
while (line.startsWith("@attribute")) { |
|
|
107 |
alFeaturesOrder.add(line.replace("@attribute ", "").replaceAll(" \\w+$", "")); |
|
|
108 |
line = br.readLine(); |
|
|
109 |
} |
|
|
110 |
} catch (Exception e) { |
|
|
111 |
e.printStackTrace(); |
|
|
112 |
} |
|
|
113 |
|
|
|
114 |
alFeaturesOrder.remove(alFeaturesOrder.size() - 1); |
|
|
115 |
|
|
|
116 |
//retreive signature |
|
|
117 |
String featuresHeader = ""; |
|
|
118 |
for (int i = 1; i < co_model.featureList.size() - 1; i++) { |
|
|
119 |
featuresHeader += "," + alFeaturesOrder.get(Integer.valueOf(co_model.featureList.get(i)) - 1); |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
//output |
|
|
123 |
try { |
|
|
124 |
//header |
|
|
125 |
BufferedReader br = new BufferedReader(new FileReader(predictionsResultsFile)); |
|
|
126 |
PrintWriter pw = new PrintWriter(new FileWriter(outfile)); |
|
|
127 |
pw.println("ID," |
|
|
128 |
+ "TRAIN_10CV_MCC" |
|
|
129 |
+ ",TRAIN_LOOCV_MCC" |
|
|
130 |
+ ",TRAIN_BS_MCC" |
|
|
131 |
+ ",TEST_MCC" |
|
|
132 |
+ ",TRAIN_TEST_BS_MCC" |
|
|
133 |
+ ",AVG_MCC" |
|
|
134 |
+ featuresHeader); |
|
|
135 |
|
|
|
136 |
pw.flush(); |
|
|
137 |
String line = br.readLine(); |
|
|
138 |
|
|
|
139 |
//content |
|
|
140 |
while (br.ready()) { |
|
|
141 |
line = br.readLine(); |
|
|
142 |
BestModelSelectionAndReport.classificationObject co_line = new BestModelSelectionAndReport.classificationObject(line); |
|
|
143 |
ArrayList<String> featureList = co_line.featureList; |
|
|
144 |
if (co_line.identifier.equals("trees.RandomForest_AUC_FB_19_0.9571_877")){ |
|
|
145 |
System.out.println(""); |
|
|
146 |
} |
|
|
147 |
|
|
|
148 |
HashMap<String, String> hmFeaturesLine = new HashMap<>(); |
|
|
149 |
for (int i = 1; i < co_line.featureList.size() - 1; i++) { |
|
|
150 |
hmFeaturesLine.put(co_line.featureList.get(i),""); |
|
|
151 |
} |
|
|
152 |
String presence = ""; |
|
|
153 |
for (int i = 1; i < co_model.featureList.size() - 1; i++) { |
|
|
154 |
if (hmFeaturesLine.containsKey(co_model.featureList.get(i) + "")) { |
|
|
155 |
presence += ",1"; |
|
|
156 |
} else { |
|
|
157 |
presence += ",0"; |
|
|
158 |
} |
|
|
159 |
} |
|
|
160 |
String out = "" + co_line.identifier + "" |
|
|
161 |
+ "," + co_line.hmValues.get("TRAIN_10CV_MCC") |
|
|
162 |
+ "," + co_line.hmValues.get("TRAIN_LOOCV_MCC") |
|
|
163 |
+ "," + co_line.hmValues.get("TRAIN_BS_MCC") |
|
|
164 |
+ "," + co_line.hmValues.get("TEST_MCC") |
|
|
165 |
+ "," + co_line.hmValues.get("TRAIN_TEST_BS_MCC") |
|
|
166 |
+ "," + co_line.hmValues.get("AVG_MCC") + presence + ""; |
|
|
167 |
pw.println(out); |
|
|
168 |
} |
|
|
169 |
pw.close(); |
|
|
170 |
} catch (Exception e) { |
|
|
171 |
e.printStackTrace(); |
|
|
172 |
} |
|
|
173 |
System.out.println("UpSetR file: " + outfile); |
|
|
174 |
} |
|
|
175 |
|
|
|
176 |
} |