0
|
1 /**
|
|
2 *****************************************************************************
|
|
3 * <p>
|
|
4 * Copyright (c) Regents of the University of Minnesota. All Rights Reserved.
|
|
5 * <p>
|
|
6 * Author: Kevin Murray University of Minnesota - (murra668@umn.edu)
|
|
7 * <p>
|
|
8 *****************************************************************************
|
|
9 */
|
|
10 package kinamine;
|
|
11
|
|
12 import java.io.File;
|
|
13 import java.net.URL;
|
|
14 import java.util.ArrayList;
|
|
15 import java.util.ResourceBundle;
|
|
16 import javafx.event.ActionEvent;
|
|
17 import javafx.fxml.FXML;
|
|
18 import javafx.fxml.Initializable;
|
|
19 import javafx.geometry.Pos;
|
|
20 import javafx.scene.Scene;
|
|
21 import javafx.scene.control.Button;
|
|
22 import javafx.scene.control.Label;
|
|
23 import javafx.scene.control.TextField;
|
|
24 import javafx.scene.layout.VBox;
|
|
25 import javafx.stage.DirectoryChooser;
|
|
26 import javafx.stage.FileChooser;
|
|
27 import javafx.stage.FileChooser.ExtensionFilter;
|
|
28 import javafx.stage.Modality;
|
|
29 import javafx.stage.Stage;
|
|
30
|
|
31 /**
|
|
32 * Controller class for KinaMine GUI. Implements ActionEvents for GUI FXML frame
|
|
33 * - built in Scene Builder.
|
|
34 *
|
|
35 * @version 1.0
|
|
36 * @author murra668
|
|
37 */
|
|
38 public class KinaMineGUIController implements Initializable {
|
|
39
|
|
40 /**
|
|
41 * Textfields for Peptide Report path, FASTA Database path, Output
|
|
42 * Directory, FDR Score and Output Group Name.
|
|
43 */
|
|
44 @FXML
|
|
45 private TextField pepPath, fastaPath, outPath, fdrScore, outGroup;
|
|
46
|
|
47 /** Debug */
|
|
48 private boolean debug;
|
|
49
|
|
50 /** Location of last directory visited. */
|
|
51 @FXML
|
|
52 File lastDirectory;
|
|
53
|
|
54 /**
|
|
55 * Handles ActionEvent of pepBrowseButton being pressed. Opens file browser
|
|
56 * for selection of peptide report tabular file. Stores location of the pep
|
|
57 * report in the PepPath Textfield.
|
|
58 *
|
|
59 * @param event
|
|
60 */
|
|
61 @FXML
|
|
62 public void pepSearchClicked(ActionEvent event) {
|
|
63
|
|
64 /** Creates new FileChooser. */
|
|
65 final FileChooser fileChooser = new FileChooser();
|
|
66
|
|
67 /** Creates new ExtensionFilter for selection of tabular file. */
|
|
68 ExtensionFilter filter
|
|
69 = new ExtensionFilter("Tabular", "*.tabular", "*.txt");
|
|
70
|
|
71 /** Configures FileChooser with parameters and last directory. */
|
|
72 configFileChooser(fileChooser, lastDirectory, filter);
|
|
73
|
|
74 /** Opens FileChooser window. */
|
|
75 final File selectedFile
|
|
76 = fileChooser.showOpenDialog(KinaMine.stage);
|
|
77
|
|
78 /**
|
|
79 * If the selected file is non-null, set the text of the pepPath
|
|
80 * TextField to the absolute path of the file. Update last directory.
|
|
81 */
|
|
82 if (selectedFile != null) {
|
|
83 lastDirectory = new File(selectedFile.getParent());
|
|
84 pepPath.setText(selectedFile.getAbsolutePath());
|
|
85
|
|
86 }
|
|
87 }
|
|
88
|
|
89 /**
|
|
90 * Handles ActionEvent of fastaSearchButton being pressed. Opens a file
|
|
91 * browser for the selection of a FASTA database and stores the location of
|
|
92 * the file in the fastaPath Textfield.
|
|
93 *
|
|
94 * @param event
|
|
95 */
|
|
96 @FXML
|
|
97 public void fastaSearchClicked(ActionEvent event) {
|
|
98
|
|
99 /** Initialize new filechosoer. */
|
|
100 final FileChooser fileChooser = new FileChooser();
|
|
101
|
|
102 /** Create new extension filter */
|
|
103 ExtensionFilter filter
|
|
104 = new ExtensionFilter("Database", "*.fasta", "*.tabular");
|
|
105
|
|
106 /** Configure file chooser */
|
|
107 configFileChooser(fileChooser, lastDirectory, filter);
|
|
108
|
|
109 /** Open file select window. */
|
|
110 final File selectedFile
|
|
111 = fileChooser.showOpenDialog(KinaMine.stage);
|
|
112
|
|
113 /** Update fastapath and last directory, if not null */
|
|
114 if (selectedFile != null) {
|
|
115 lastDirectory = new File(selectedFile.getParent());
|
|
116 fastaPath.setText(selectedFile.getAbsolutePath());
|
|
117
|
|
118 }
|
|
119 }
|
|
120
|
|
121 /**
|
|
122 * Configures FileChooser.
|
|
123 *
|
|
124 * @param fileChooser
|
|
125 * @param lastDir
|
|
126 * @param filter
|
|
127 */
|
|
128 private static void configFileChooser(final FileChooser fileChooser,
|
|
129 File lastDir, ExtensionFilter filter) {
|
|
130
|
|
131 fileChooser.setTitle("Open File");
|
|
132
|
|
133 fileChooser.getExtensionFilters().add(filter);
|
|
134
|
|
135 /** If last directory exists, start file selection from there. */
|
|
136 if (lastDir == null) {
|
|
137 fileChooser.setInitialDirectory(
|
|
138 new File(System.getProperty("user.home")));
|
|
139 } else {
|
|
140 fileChooser.setInitialDirectory(lastDir);
|
|
141 }
|
|
142 }
|
|
143
|
|
144 /**
|
|
145 * Handles ActionEvent that browse output was clicked. Opens directory
|
|
146 * chooser and records path to directory chosen.
|
|
147 *
|
|
148 * @param event
|
|
149 */
|
|
150 public void browseFolderClicked(ActionEvent event) {
|
|
151
|
|
152 /** Initialize new DirectoryChooser */
|
|
153 final DirectoryChooser dirChooser = new DirectoryChooser();
|
|
154
|
|
155 dirChooser.setTitle("Choose Output Location");
|
|
156
|
|
157 /** Configure starting location for directory chooser. */
|
|
158 if (lastDirectory != null) {
|
|
159 dirChooser.setInitialDirectory(lastDirectory);
|
|
160 } else {
|
|
161 dirChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
|
162 }
|
|
163
|
|
164 /** Opens directory chooser window. */
|
|
165 final File output = dirChooser.showDialog(KinaMine.stage);
|
|
166
|
|
167 /** Set path if file not null */
|
|
168 if (output != null) {
|
|
169 outPath.setText(output.getAbsolutePath());
|
|
170 }
|
|
171
|
|
172 }
|
|
173
|
|
174 /**
|
|
175 * Handles event that submit button is clicked. Collects are required inputs
|
|
176 * for KineMineDriver.
|
|
177 *
|
|
178 * @param event
|
|
179 */
|
|
180 public void submitButtonClicked(ActionEvent event) {
|
|
181
|
|
182 /** Collect arguments */
|
|
183 String args[] = new String[5];
|
|
184 args[0] = pepPath.getText();
|
|
185 args[1] = fastaPath.getText();
|
|
186 args[2] = outPath.getText();
|
|
187 args[3] = fdrScore.getText();
|
|
188 args[4] = outGroup.getText();
|
|
189
|
|
190 ArrayList<String> error = checkForErrors(args);
|
|
191
|
|
192 /** Handle errors */
|
|
193 if (error.isEmpty()) {
|
|
194 boolean status = KinaMineDriver.run(args, debug = true);
|
|
195 completeWindow();
|
|
196 } else {
|
|
197 alertError(error);
|
|
198 }
|
|
199 }
|
|
200
|
|
201 public ArrayList<String> checkForErrors(String[] args) {
|
|
202
|
|
203 ArrayList<String> error = new ArrayList<>();
|
|
204
|
|
205 File pep = new File(args[0]);
|
|
206 File fasta = new File(args[1]);
|
|
207 File dir = new File(args[2]);
|
|
208 String score = args[3];
|
|
209
|
|
210 if (!pep.isFile()) {
|
|
211 error.add(args[0] + " is not a file.");
|
|
212 }
|
|
213 if (!pep.canRead()) {
|
|
214 error.add("Can't read peptide report: " + args[0]);
|
|
215 }
|
|
216 if (!fasta.isFile()) {
|
|
217 error.add(args[1] + " is not a file.");
|
|
218 }
|
|
219 if (!fasta.canRead()) {
|
|
220 error.add("Can't read database: " + args[0]);
|
|
221 }
|
|
222 if (!dir.isDirectory()){
|
|
223 error.add(dir + " is not a directory.");
|
|
224 }
|
|
225 if (!score.matches("[-+]?\\d*\\.?\\d+")) {
|
|
226 error.add("FDR Score: " + score + " is not a number.");
|
|
227 }
|
|
228
|
|
229 return error;
|
|
230 }
|
|
231
|
|
232 /**
|
|
233 * If error in arguments for KinaMineDriver, open error window and write
|
|
234 * error message to user.
|
|
235 *
|
|
236 * @param errors list of errors
|
|
237 */
|
|
238 public void alertError(ArrayList<String> errors) {
|
|
239
|
|
240 /** Format window. */
|
|
241 Stage window = new Stage();
|
|
242 window.initModality(Modality.APPLICATION_MODAL);
|
|
243 window.setTitle("Error");
|
|
244 window.setMinWidth(250);
|
|
245
|
|
246 /** Format message*/
|
|
247 String message = "";
|
|
248 for (String error : errors) {
|
|
249 message += error + "\n";
|
|
250 }
|
|
251 Label label = new Label(message);
|
|
252
|
|
253 /** Format Button */
|
|
254 Button closeButton = new Button("Close\n");
|
|
255 closeButton.setOnAction(e -> window.close());
|
|
256
|
|
257 /** Format layout */
|
|
258 VBox layout = new VBox(10);
|
|
259 layout.getChildren().addAll(label, closeButton);
|
|
260 layout.setAlignment(Pos.CENTER);
|
|
261
|
|
262 /** Set scene */
|
|
263 Scene scene = new Scene(layout);
|
|
264 window.setScene(scene);
|
|
265 window.showAndWait();
|
|
266
|
|
267 }
|
|
268
|
|
269 /**
|
|
270 * Opens window when Run is complete.
|
|
271 */
|
|
272 public void completeWindow() {
|
|
273
|
|
274 /** Format window. */
|
|
275 Stage window = new Stage();
|
|
276 window.initModality(Modality.APPLICATION_MODAL);
|
|
277 window.setMinWidth(250);
|
|
278
|
|
279 /** Format close button */
|
|
280 Label label = new Label("Run Complete");
|
|
281 Button closeButton = new Button("Done");
|
|
282 closeButton.setOnAction(e -> window.close());
|
|
283
|
|
284 /** Format layout */
|
|
285 VBox layout = new VBox(10);
|
|
286 layout.getChildren().addAll(label, closeButton);
|
|
287 layout.setAlignment(Pos.CENTER);
|
|
288
|
|
289 /** Set scene */
|
|
290 Scene scene = new Scene(layout);
|
|
291 window.setScene(scene);
|
|
292 window.showAndWait();
|
|
293
|
|
294 }
|
|
295
|
|
296 /**
|
|
297 * Initialize method for KinaMineGUI. Initializes all paths.
|
|
298 *
|
|
299 * @param url
|
|
300 * @param rb
|
|
301 */
|
|
302 @Override
|
|
303 public void initialize(URL url, ResourceBundle rb) {
|
|
304 System.out.println("Initializing...");
|
|
305 lastDirectory = null;
|
|
306 assert pepPath != null : "fx:id=\"pepPath\" was not injected: check your FXML file 'KinaMineGUI.fxml'.";
|
|
307 assert fastaPath != null : "fx:id=\"fastaPath\" was not injected: check your FXML file 'KinaMineGUI.fxml'.";
|
|
308 assert outPath != null : "fx:id=\"outPath\" was not injected: check your FXML file 'KinaMineGUI.fxml'.";
|
|
309
|
|
310 }
|
|
311
|
|
312 }
|