frame.setUiEnabled(false);
logArea.setText("");
String bamPath = bamPathEdit.getText();
String gffPath = gffPathEdit.getText();
String featureType = featureTypeField.getText();
ComputeCountsTask computeCountsTask = new ComputeCountsTask(bamPath, gffPath);
String pName = strandTypeCombo.getSelectedItem().toString();
computeCountsTask.setProtocol(LibraryProtocol.getProtocolByName(pName));
computeCountsTask.setCountingAlgorithm(countingAlgoCombo.getSelectedItem().toString());
computeCountsTask.addSupportedFeatureType(featureType);
computeCountsTask.setAttrName(featureNameField.getText());
if (pairedAnalysisBox.isSelected()) {
computeCountsTask.setPairedEndAnalysis();
if (!alreadySortedBox.isSelected()) {
computeCountsTask.setSortingRequired();
}
}
final JTextArea loggerDestArea = logArea;
computeCountsTask.setLogger( new LoggerThread() {
@Override
public void logLine(String msg) {
loggerDestArea.append(msg + "\n");
loggerDestArea.setCaretPosition(loggerDestArea.getText().length());
}
});
try {
computeCountsTask.run();
PrintWriter outWriter = new PrintWriter(new FileWriter(outputPathField.getText()));
Map<String,Double> counts = computeCountsTask.getReadCounts();
for (Map.Entry<String,Double> entry: counts.entrySet()) {
String str = entry.getKey() + "\t" + entry.getValue().longValue();
outWriter.println(str);
}
outWriter.flush();
if (saveStatsBox.isSelected()) {
PrintWriter statsWriter = new PrintWriter(new FileWriter(outputPathField.getText() + ".stats"));
String statsMessage = computeCountsTask.getOutputStatsMessage().toString();
statsWriter.println(statsMessage);
statsWriter.flush();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(frame, e.getMessage(),
getTitle(), JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
frame.setUiEnabled(true);
return;
}
StringBuilder message = new StringBuilder();
message.append("Counts generated!\n\n");
message.append(computeCountsTask.getOutputStatsMessage());
message.append("\nResult is saved to ").append(outputPathField.getText());
JOptionPane.showMessageDialog(frame, message.toString(),
getTitle(), JOptionPane.INFORMATION_MESSAGE);
logArea.append(message.toString());