/* $Id: BatchNcbiBlast.java 74 2009-01-12 23:11:59Z weizhongli $
* $Author: weizhongli $
* ======================================================================
* Batch NCBI-BLAST
* ====================================================================== */
package easiest;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import java.awt.Point;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.JTabbedPane;
import java.awt.ComponentOrientation;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.lang.String;
import java.util.Properties;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import java.awt.Font;
import java.awt.Color;
public class BatchNcbiBlast {
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu helpMenu = null;
private JMenuItem exitMenuItem = null;
private JMenuItem aboutMenuItem = null;
private JDialog aboutDialog = null; // @jve:decl-index=0:visual-constraint="10,520"
private JPanel aboutContentPane = null;
private JLabel aboutVersionLabel = null;
private JTabbedPane jTabbedPane = null;
private JPanel jPanel = null;
private JPanel jPanel1 = null;
private JPanel jPanel2 = null;
private JPanel jPanel3 = null;
private JPanel jPanel4 = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JTextField jTextField = null;
private JButton jButton1 = null;
private JButton jButton2 = null;
private JLabel jLabel3 = null;
private JTextField jTextField1 = null;
private JButton jButton = null;
private JLabel jLabel4 = null;
private JButton jButton3 = null;
private JLabel jLabel5 = null;
private JLabel jLabel6 = null;
private JLabel jLabel7 = null;
private JButton jButton4 = null;
private JLabel jLabel8 = null;
private JLabel jLabel10 = null;
private JLabel jLabel2 = null;
private JLabel jLabel9 = null;
private JTextField jTextField3 = null;
private JLabel jLabel11 = null;
private JTextField jTextField4 = null;
private JButton jButton5 = null;
private JButton jButton6 = null;
private JButton jButton7 = null;
private JTextField jTextField5 = null;
private JLabel jLabel12 = null;
private Process process_formatdb = null;
private Process process_run = null;
private JButton jButton8 = null;
private JButton jButton9 = null;
private JTextArea jTextArea = null;
Properties defaultProps = null;
Properties applicationProps = null;
private String filePath = null;
private JButton jButton10 = null;
int jobStatus = 0;
private JScrollPane jScrollPane = null;
private JButton jButton11 = null;
private JLabel jLabel13 = null;
private JComboBox jComboBox = null;
private JLabel jLabel14 = null;
private JLabel jLabel15 = null;
private JLabel jLabel16 = null;
private JLabel jLabel17 = null;
private JLabel jLabel18 = null;
private JComboBox jComboBox1 = null;
private JTextField jTextField6 = null;
private JComboBox jComboBox2 = null;
private JTextField jTextField7 = null;
private JTextField jTextField8 = null;
private JLabel jLabel19 = null;
private JTextArea jTextArea1 = null;
private JLabel jLabel20 = null;
private JLabel jLabel21 = null;
private JLabel jLabel22 = null;
private JLabel jLabel23 = null;
private JLabel jLabel24 = null;
private JLabel jLabel26 = null;
private JLabel jLabel27 = null;
private JLabel jLabel28 = null;
private JLabel jLabel29 = null;
private JPanel jPanel5 = null;
private JLabel jLabel25 = null;
private JLabel jLabel30 = null;
private JLabel jLabel31 = null;
private JTextField jTextField9 = null;
private JTextField jTextField10 = null;
private JButton jButton12 = null;
private JButton jButton13 = null;
private JButton jButton14 = null;
private JLabel jLabel32 = null;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
private JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(900, 500);
jFrame.setContentPane(getJTabbedPane());
jFrame.setTitle("BatchNCBIBlast");
}
return jFrame;
}
/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
/**
* This method initiali zes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("File");
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("Help");
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
applicationProps.setProperty("binarypath", jTextField
.getText());
applicationProps.setProperty("blastdb", jTextField1
.getText());
applicationProps
.setProperty("input", jTextField3.getText());
applicationProps.setProperty("output", jTextField4
.getText());
applicationProps.setProperty("e-value", jTextField6
.getText());
applicationProps.setProperty("opengap", jTextField7
.getText());
applicationProps.setProperty("extendgap", jTextField8
.getText());
applicationProps.setProperty("parseoutput", jTextField10
.getText());
FileOutputStream out = null;
try {
out = new FileOutputStream("appProperties");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
applicationProps.store(out, "/* properties updated */");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.exit(0);
}
});
}
return exitMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog aboutDialog = getAboutDialog();
aboutDialog.pack();
Point loc = getJFrame().getLocation();
loc.translate(50, 50);
aboutDialog.setLocation(loc);
aboutDialog.setVisible(true);
}
});
}
return aboutMenuItem;
}
/**
* This method initializes aboutDialog
*
* @return javax.swing.JDialog
*/
private JDialog getAboutDialog() {
if (aboutDialog == null) {
aboutDialog = new JDialog(getJFrame(), true);
aboutDialog.setTitle("About");
aboutDialog.setContentPane(getAboutContentPane());
aboutDialog.setSize(400, 200);
}
return aboutDialog;
}
/**
* This method initializes aboutContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getAboutContentPane() {
if (aboutContentPane == null) {
aboutContentPane = new JPanel();
aboutContentPane.setLayout(new BorderLayout());
aboutContentPane.setSize(500,200);
aboutContentPane.add(getAboutVersionLabel(), BorderLayout.NORTH);
aboutContentPane.add(getJTextArea1(), BorderLayout.EAST);
}
return aboutContentPane;
}
/**
* This method initializes aboutVersionLabel
*
* @return javax.swing.JLabel
*/
private JLabel getAboutVersionLabel() {
if (aboutVersionLabel == null) {
aboutVersionLabel = new JLabel();
aboutVersionLabel.setText("BatchNcbiBlast @ easiEST Version 0.1");
aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
}
return aboutVersionLabel;
}
/**
* This method initializes jTabbedPane
*
* @return javax.swing.JTabbedPane
*/
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.setToolTipText("");
jTabbedPane.setName("");
jTabbedPane
.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
jTabbedPane.setTabPlacement(JTabbedPane.LEFT);
jTabbedPane.addTab("BLAST Location ", new ImageIcon("icons/n1.png"), getJPanel(), null);
jTabbedPane.addTab("Define Database ", new ImageIcon("icons/n2.png"), getJPanel1(), null);
jTabbedPane.addTab("Define Parameters ", new ImageIcon("icons/n3.png"), getJPanel2(), null);
jTabbedPane.addTab("Define Input & Output", new ImageIcon("icons/n4.png"), getJPanel3(), null);
jTabbedPane.addTab("Run BLAST ", new ImageIcon("icons/n5.png"), getJPanel4(), null);
jTabbedPane.addTab("Parse BLAST Result ", new ImageIcon("icons/n6.png"), getJPanel5(), null);
}
return jTabbedPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jLabel20 = new JLabel();
jLabel20.setBounds(new Rectangle(30, 11, 107, 31));
jLabel20.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel20.setText("STEP 1 ");
jLabel10 = new JLabel();
jLabel10.setBounds(new Rectangle(50, 85, 538, 16));
jLabel10.setText("Click the following button to download the installor, then run it to install locally.");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(53, 258, 63, 23));
jLabel5.setForeground(new Color(100, 140, 170));
jLabel5.setText("Required");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(30, 59, 554, 16));
jLabel1.setText("(1) If you have not installed NCBI-BLAST in your computer, please install the NCBI-BLAST.");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(32, 196, 585, 16));
jLabel.setFont(new Font("Dialog", Font.BOLD, 12));
jLabel.setText("(2) Please indicate the local NCBI-BLAST binary path." +
" (e.g. C:\\Users\\username\\tools\\ncbi-blast\\bin)");
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setToolTipText("");
jPanel.add(jLabel, null);
jPanel.add(jLabel1, null);
jPanel.add(getJTextField(), null);
jPanel.add(getJButton1(), null);
jPanel.add(getJButton2(), null);
jPanel.add(jLabel5, null);
jPanel.add(jLabel10, null);
jPanel.add(jLabel20, null);
}
return jPanel;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
jLabel27 = new JLabel();
jLabel27.setBounds(new Rectangle(49, 234, 61, 16));
jLabel27.setForeground(new Color(100, 140, 170));
jLabel27.setText("Required");
jLabel21 = new JLabel();
jLabel21.setBounds(new Rectangle(30, 14, 67, 24));
jLabel21.setText("STEP 2 ");
jLabel21.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel8 = new JLabel();
jLabel8.setBounds(new Rectangle(47, 98, 169, 16));
jLabel8.setText("Click to download databases:");
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(30, 290, 492, 23));
jLabel7.setText("(3) If you have not formatted the database, " +
"please format databases into BLAST indices.");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(49, 368, 438, 25));
jLabel6.setText("Note: Once formatted successfully, databases are OK for BLAST searching.");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(30, 44, 547, 18));
jLabel4.setText("(1) If you have not installed any database, " +
"please download the databbases you are interested in.");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(31, 165, 497, 22));
jLabel3.setText("(2) Indicate database location " +
"(e.g. C:\\Users\\wli\\tools\blastdb\\unipro_sprot.fasta).");
jPanel1 = new JPanel();
jPanel1.setLayout(null);
jPanel1.add(jLabel3, null);
jPanel1.add(getJTextField1(), null);
jPanel1.add(getJButton(), null);
jPanel1.add(jLabel4, null);
jPanel1.add(getJButton3(), null);
jPanel1.add(jLabel6, null);
jPanel1.add(jLabel7, null);
jPanel1.add(getJButton4(), null);
jPanel1.add(jLabel8, null);
jPanel1.add(getJButton8(), null);
jPanel1.add(getJButton11(), null);
jPanel1.add(jLabel21, null);
jPanel1.add(jLabel27, null);
}
return jPanel1;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel2() {
if (jPanel2 == null) {
jLabel26 = new JLabel();
jLabel26.setBounds(new Rectangle(269, 91, 334, 29));
jLabel26.setForeground(new Color(100, 140, 170));
jLabel26.setText("blastx: DNAs V.S. proteins; blastp: protein V.S. proteins");
jLabel22 = new JLabel();
jLabel22.setBounds(new Rectangle(30, 14, 67, 24));
jLabel22.setText("STEP 3");
jLabel22.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel17 = new JLabel();
jLabel17.setBounds(new Rectangle(29, 270, 106, 31));
jLabel17.setText("Extend Gap");
jLabel16 = new JLabel();
jLabel16.setBounds(new Rectangle(29, 227, 106, 29));
jLabel16.setText("Open Gap");
jLabel15 = new JLabel();
jLabel15.setBounds(new Rectangle(29, 181, 108, 30));
jLabel15.setText("Score Matrix");
jLabel14 = new JLabel();
jLabel14.setBounds(new Rectangle(28, 135, 109, 31));
jLabel14.setText("Expected Value (E)");
jLabel13 = new JLabel();
jLabel13.setBounds(new Rectangle(30, 91, 106, 32));
jLabel13.setText("Program");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(30, 45, 271, 31));
jLabel2.setText("Please set parameters (all required):");
jLabel2.setForeground(new Color(100, 140, 170));
jPanel2 = new JPanel();
jPanel2.setLayout(null);
jPanel2.add(jLabel2, null);
jPanel2.add(jLabel13, null);
jPanel2.add(getJComboBox(), null);
jPanel2.add(jLabel14, null);
jPanel2.add(jLabel15, null);
jPanel2.add(jLabel16, null);
jPanel2.add(jLabel17, null);
jPanel2.add(getJTextField6(), null);
jPanel2.add(getJComboBox2(), null);
jPanel2.add(getJTextField7(), null);
jPanel2.add(getJTextField8(), null);
jPanel2.add(jLabel22, null);
jPanel2.add(jLabel26, null);
}
return jPanel2;
}
/**
* This method initializes jPanel3
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel3() {
if (jPanel3 == null) {
jLabel29 = new JLabel();
jLabel29.setBounds(new Rectangle(31, 259, 61, 16));
jLabel29.setForeground(new Color(100, 140, 170));
jLabel29.setText("Required");
jLabel28 = new JLabel();
jLabel28.setBounds(new Rectangle(32, 123, 68, 16));
jLabel28.setForeground(new Color(100, 140, 170));
jLabel28.setText("Required");
jLabel23 = new JLabel();
jLabel23.setBounds(new Rectangle(30, 14, 67, 24));
jLabel23.setText("STEP 4");
jLabel23.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel18 = new JLabel();
jLabel18.setBounds(new Rectangle(29, 283, 98, 26));
jLabel18.setText("Output format: ");
jLabel11 = new JLabel();
jLabel11.setBounds(new Rectangle(30, 200, 141, 26));
jLabel11.setText("Output result file: ");
jLabel9 = new JLabel();
jLabel9.setBounds(new Rectangle(31, 64, 439, 27));
jLabel9.setText("Input sequence file (accept multiple sequences or large-scale data): ");
jPanel3 = new JPanel();
jPanel3.setLayout(null);
jPanel3.add(jLabel9, null);
jPanel3.add(getJTextField3(), null);
jPanel3.add(jLabel11, null);
jPanel3.add(getJTextField4(), null);
jPanel3.add(getJButton5(), null);
jPanel3.add(getJButton6(), null);
jPanel3.add(jLabel18, null);
jPanel3.add(getJComboBox1(), null);
jPanel3.add(jLabel23, null);
jPanel3.add(jLabel28, null);
jPanel3.add(jLabel29, null);
}
return jPanel3;
}
/**
* This method initializes jPanel4
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel4() {
if (jPanel4 == null) {
jLabel24 = new JLabel();
jLabel24.setBounds(new Rectangle(31, 15, 67, 24));
jLabel24.setText("STEP 5 ");
jLabel24.setFont(new Font("Dialog", Font.BOLD, 18));
jLabel19 = new JLabel();
jLabel19.setBounds(new Rectangle(31, 207, 287, 23));
jLabel19.setText("Job messages:");
jLabel12 = new JLabel();
jLabel12.setBounds(new Rectangle(30, 104, 311, 21));
jLabel12.setText("Your command:");
jPanel4 = new JPanel();
jPanel4.setLayout(null);
jPanel4.add(getJButton7(), null);
jPanel4.add(getJTextField5(), null);
jPanel4.add(jLabel12, null);
jPanel4.add(getJButton9(), null);
jPanel4.add(getJButton10(), null);
jPanel4.add(getJScrollPane(), null);
jPanel4.add(jLabel19, null);
jPanel4.add(jLabel24, null);
}
return jPanel4;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(52, 224, 381, 33));
jTextField.setText(defaultProps.getProperty("binarypath"));
jTextField.setText(applicationProps.getProperty("binarypath"));
}
return jTextField;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(48, 137, 358, 19));
jButton1
.setText("Downlad Windows version (blast-2.2.18-ia32-win32.exe)");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
Runtime
.getRuntime()
.exec(
"\"C:/Program Files/Internet Explorer/IEXPLORE.EXE\" "
+ "\"ftp://ftp.ncbi.nih.gov/blast/executables/release/2.2.18/blast-2.2.18-ia32-win32.exe\"");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return jButton1;
}
/**
* This method initializes jButton2
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (jButton2 == null) {
jButton2 = new JButton();
jButton2.setBounds(new Rectangle(444, 223, 83, 32));
jButton2.setText("Browse");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (filePath == null) {
filePath = new String(".");
}
JFileChooser fc = new JFileChooser(filePath);
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showOpenDialog(jButton2);
File ncbiBlastExe = fc.getSelectedFile();
String ncbiBlastExePath = ncbiBlastExe.getAbsolutePath();
jTextField.setText(ncbiBlastExePath);
filePath = ncbiBlastExePath;
}
});
}
return jButton2;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(new Rectangle(49, 202, 388, 31));
jTextField1.setText(defaultProps.getProperty("blastdb"));
jTextField1.setText(applicationProps.getProperty("blastdb"));
}
return jTextField1;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(446, 201, 79, 31));
jButton.setText("Browse");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (filePath == null) {
filePath = new String(".");
}
JFileChooser fc = new JFileChooser(filePath);
// fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.showOpenDialog(jButton);
File database = fc.getSelectedFile();
String databasepath = database.getAbsolutePath();
jTextField1.setText(databasepath);
filePath = databasepath;
}
});
}
return jButton;
}
/**
* This method initializes jButton3
*
* @return javax.swing.JButton
*/
private JButton getJButton3() {
if (jButton3 == null) {
jButton3 = new JButton();
jButton3.setBounds(new Rectangle(228, 92, 125, 30));
jButton3.setToolTipText("Swissprot protein database of UniProt");
jButton3.setPreferredSize(new Dimension(113, 25));
jButton3.setText("UniProt_sprot");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
Runtime
.getRuntime()
.exec(
"\"C:/Program Files/Internet Explorer/IEXPLORE.EXE\" \"ftp://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/uniprot_sprot.fasta.gz\"");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return jButton3;
}
/**
* This method initializes jButton4
*
* @return javax.swing.JButton
*/
private JButton getJButton4() {
if (jButton4 == null) {
jButton4 = new JButton();
jButton4.setBounds(new Rectangle(49, 322, 285, 29));
jButton4.setText("Format the chosen database as proteins");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String cmdFormatdb = new String();
String ncbiBlastExePath = jTextField.getText();
String databaseName = jTextField1.getText();
cmdFormatdb = ncbiBlastExePath + "/formatdb -i "
+ databaseName + " -p T -o F ";
try {
process_formatdb = Runtime.getRuntime().exec(
cmdFormatdb);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return jButton4;
}
/**
* This method initializes jTextField3
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
jTextField3.setBounds(new Rectangle(31, 91, 435, 29));
jTextField3.setText(defaultProps.getProperty("input"));
jTextField3.setText(applicationProps.getProperty("input"));
}
return jTextField3;
}
/**
* This method initializes jTextField4
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField4() {
if (jTextField4 == null) {
jTextField4 = new JTextField();
jTextField4.setBounds(new Rectangle(31, 229, 435, 32));
jTextField4.setText(defaultProps.getProperty("output"));
jTextField4.setText(applicationProps.getProperty("output"));
}
return jTextField4;
}
/**
* This method initializes jButton5
*
* @return javax.swing.JButton
*/
private JButton getJButton5() {
if (jButton5 == null) {
jButton5 = new JButton();
jButton5.setBounds(new Rectangle(479, 92, 92, 28));
jButton5.setText("Browse");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (filePath == null) {
filePath = new String(".");
}
JFileChooser fc = new JFileChooser(filePath);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.showOpenDialog(jButton5);
File input = fc.getSelectedFile();
String inputpath = input.getAbsolutePath();
jTextField3.setText(inputpath);
filePath = inputpath;
}
});
}
return jButton5;
}
/**
* This method initializes jButton6
*
* @return javax.swing.JButton
*/
private JButton getJButton6() {
if (jButton6 == null) {
jButton6 = new JButton();
jButton6.setBounds(new Rectangle(480, 229, 92, 30));
jButton6.setText("Browse");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (filePath == null) {
filePath = new String(".");
}
JFileChooser fc = new JFileChooser(filePath);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.showOpenDialog(jButton6);
File output = fc.getSelectedFile();
String outputpath = output.getAbsolutePath();
jTextField4.setText(outputpath);
filePath = outputpath;
}
});
}
return jButton6;
}
/**
* This method initializes jButton7
*
* @return javax.swing.JButton
*/
private JButton getJButton7() {
if (jButton7 == null) {
jButton7 = new JButton();
jButton7.setBounds(new Rectangle(29, 48, 107, 33));
jButton7.setText("Run BLAST");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jButton7.setEnabled(false);
jButton9.setEnabled(true);
runProg();
}
});
}
return jButton7;
}
/**
* This method initializes jTextField5
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField5() {
if (jTextField5 == null) {
jTextField5 = new JTextField();
jTextField5.setBounds(new Rectangle(29, 123, 655, 27));
}
return jTextField5;
}
/**
* This method initializes jButton8
*
* @return javax.swing.JButton
*/
private JButton getJButton8() {
if (jButton8 == null) {
jButton8 = new JButton();
jButton8.setBounds(new Rectangle(345, 323, 125, 29));
jButton8.setText("Stop formatting");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.out.println("Stop formatting.");
if (process_formatdb != null) {
process_formatdb.destroy();
}
}
});
}
return jButton8;
}
/**
* This method initializes jButton9
*
* @return javax.swing.JButton
*/
private JButton getJButton9() {
if (jButton9 == null) {
jButton9 = new JButton();
jButton9.setBounds(new Rectangle(31, 166, 105, 28));
jButton9.setText("Stop BLAST");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (process_run != null) {
process_run.destroy();
String processStop = new String("Search stopped\n");
jTextArea.append(processStop);
}
jButton7.setEnabled(true);
jButton9.setEnabled(false);
}
});
}
return jButton9;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (jTextArea == null) {
jTextArea = new JTextArea();
jTextArea.setEditable(false);
}
return jTextArea;
}
/**
* Load properties
*
* @throws IOException
*/
private void loadProperties() throws IOException {
// create and load default properties
defaultProps = new Properties();
FileInputStream in = new FileInputStream("defaultProperties");
defaultProps.load(in);
in.close();
// create application properties with default
applicationProps = new Properties(defaultProps);
in = new FileInputStream("appProperties");
applicationProps.load(in);
in.close();
}
public void runProg() {
new Thread() {
public void run() {
String outputFormat;
if (jComboBox1.getSelectedItem() == "HTML") {
outputFormat = " -T T ";
}
else if (jComboBox1.getSelectedItem() == "XML") {
outputFormat = " -m 7 ";
}
else {
outputFormat = "";
}
String cmdNcbiBlast =
jTextField.getText() + "/blastall " // Binary path
+ " -p " + jComboBox.getSelectedItem() // Program
+ " -d " + jTextField1.getText() // Database
+ " -e " + jTextField6.getText() // E-value
+ " -M " + jComboBox2.getSelectedItem() //Matrix
+ " -G " + jTextField7.getText() // Open gap
+ " -E " + jTextField8.getText() // Extend gap
+ outputFormat // Output format
+ " -i " + jTextField3.getText() // Input
+ " -o " + jTextField4.getText() // Output
; // finish setting
jTextField5.setText(cmdNcbiBlast);
jTextArea.setText("Search is started\n");
jobStatus = 1;
try {
// Run BLAST
process_run = Runtime.getRuntime().exec(cmdNcbiBlast);
String line;
String line_error;
// To see any stdout
BufferedReader input = new BufferedReader(
new InputStreamReader(process_run.getInputStream()));
while ((line = input.readLine()) != null) {
jTextArea.append(line);
}
// To see any error message
BufferedReader process_error = new BufferedReader(
new InputStreamReader(process_run.getErrorStream()));
while ((line_error = process_error.readLine()) != null) {
jTextArea.append(line_error + "\n");
}
input.close();
String endline = "Search is ended. " +
"You can check your output file:"
+ jTextField4.getText() + "\n";
jobStatus = 0;
jTextArea.append(endline);
jButton7.setEnabled(true);
jButton9.setEnabled(false);
} catch (Exception e1) {
System.out.println(e1.getMessage());
e1.printStackTrace();
}
}
}.start();
}
/**
* This method initializes jButton10
*
* @return javax.swing.JButton
*/
private JButton getJButton10() {
if (jButton10 == null) {
jButton10 = new JButton();
jButton10.setBounds(new Rectangle(149, 166, 112, 29));
jButton10.setText("Check status");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (jobStatus == 0) {
if (process_run == null) {
jTextArea.append("No search\n");
} else {
jTextArea.append("Search finished. " +
"You can check your output file: "
+ jTextField4.getText() + "\n");
}
} else {
jTextArea.append("Still searching\n");
}
}
});
}
return jButton10;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(32, 230, 647, 181));
jScrollPane.setViewportView(getJTextArea());
}
return jScrollPane;
}
/**
* This method initializes jButton11
*
* @return javax.swing.JButton
*/
private JButton getJButton11() {
if (jButton11 == null) {
jButton11 = new JButton();
jButton11.setPreferredSize(new Dimension(120, 25));
jButton11.setSize(new Dimension(139, 30));
jButton11.setLocation(new Point(362, 92));
jButton11.setText("RefSeq (2 files)");
jButton11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
Runtime
.getRuntime()
.exec(
"\"C:/Program Files/Internet Explorer/IEXPLORE.EXE\" \"ftp://ftp.ncbi.nih.gov/blast/db/refseq_protein.00.tar.gz\"");
Runtime
.getRuntime()
.exec(
"\"C:/Program Files/Internet Explorer/IEXPLORE.EXE\" \"ftp://ftp.ncbi.nih.gov/blast/db/refseq_protein.01.tar.gz\"");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
return jButton11;
}
/**
* This method initializes jComboBox
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (jComboBox == null) {
jComboBox = new JComboBox(new String[] {"blastx", "blastp"});
jComboBox.setBounds(new Rectangle(149, 92, 107, 27));
}
return jComboBox;
}
/**
* This method initializes jComboBox1
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox1() {
if (jComboBox1 == null) {
jComboBox1 = new JComboBox(new String[]{"XML", "TEXT", "HTML"});
jComboBox1.setBounds(new Rectangle(145, 283, 110, 27));
}
return jComboBox1;
}
/**
* This method initializes jTextField6
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField6() {
if (jTextField6 == null) {
jTextField6 = new JTextField("0.00001");
jTextField6.setBounds(new Rectangle(147, 136, 110, 29));
jTextField6.setText(defaultProps.getProperty("e-value"));
jTextField6.setText(applicationProps.getProperty("e-value"));
}
return jTextField6;
}
/**
* This method initializes jComboBox2
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox2() {
if (jComboBox2 == null) {
jComboBox2 = new JComboBox(new String[] {"BLOSUM62", "BLOSUM45", "BLOSUM80","PAM30", "PAM70"});
jComboBox2.setBounds(new Rectangle(149, 181, 107, 30));
}
return jComboBox2;
}
/**
* This method initializes jTextField7
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField7() {
if (jTextField7 == null) {
jTextField7 = new JTextField("11");
jTextField7.setBounds(new Rectangle(148, 227, 108, 32));
jTextField7.setText(defaultProps.getProperty("opengap"));
jTextField7.setText(applicationProps.getProperty("opengap"));
}
return jTextField7;
}
/**
* This method initializes jTextField8
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField8() {
if (jTextField8 == null) {
jTextField8 = new JTextField();
jTextField8.setBounds(new Rectangle(148, 269, 108, 32));
jTextField8.setText(defaultProps.getProperty("extendgap"));
jTextField8.setText(applicationProps.getProperty("extendgap"));
}
return jTextField8;
}
/**
* This method initializes jTextArea1
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea1() {
if (jTextArea1 == null) {
jTextArea1 = new JTextArea();
jTextArea1.setText(" BatchNcbiBlast is one of the " +
"applications of easiEST Project. \n" +
"It can be used to run batch NCBI-BLAST " +
"search step by step.\n");
}
return jTextArea1;
}
/**
* This method initializes jPanel5
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel5() {
if (jPanel5 == null) {
jLabel32 = new JLabel();
jLabel32.setBounds(new Rectangle(163, 92, 402, 16));
jLabel32.setText("Note: ONLY for BLAST XML output!");
jLabel32.setForeground(new Color(100, 140, 170));
jLabel31 = new JLabel();
jLabel31.setBounds(new Rectangle(30, 128, 122, 31));
jLabel31.setText("Output Parsed File");
jLabel30 = new JLabel();
jLabel30.setBounds(new Rectangle(30, 59, 122, 32));
jLabel30.setText("BLAST Result File");
jLabel25 = new JLabel();
jLabel25.setBounds(new Rectangle(31, 15, 67, 24));
jLabel25.setText("STEP 6");
jLabel25.setFont(new Font("Dialog", Font.BOLD, 18));
jPanel5 = new JPanel();
jPanel5.setLayout(null);
jPanel5.add(jLabel25, null);
jPanel5.add(jLabel30, null);
jPanel5.add(jLabel31, null);
jPanel5.add(getJTextField9(), null);
jPanel5.add(getJTextField10(), null);
jPanel5.add(getJButton12(), null);
jPanel5.add(getJButton13(), null);
jPanel5.add(getJButton14(), null);
jPanel5.add(jLabel32, null);
}
return jPanel5;
}
/**
* This method initializes jTextField9
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField9() {
if (jTextField9 == null) {
jTextField9 = new JTextField();
jTextField9.setBounds(new Rectangle(163, 61, 409, 32));
jTextField9.setText(defaultProps.getProperty("output"));
jTextField9.setText(applicationProps.getProperty("output"));
}
return jTextField9;
}
/**
* This method initializes jTextField10
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField10() {
if (jTextField10 == null) {
jTextField10 = new JTextField();
jTextField10.setBounds(new Rectangle(165, 128, 407, 31));
jTextField10.setText(defaultProps.getProperty("parseoutput"));
jTextField10.setText(applicationProps.getProperty("parseoutput"));
}
return jTextField10;
}
/**
* This method initializes jButton12
*
* @return javax.swing.JButton
*/
private JButton getJButton12() {
if (jButton12 == null) {
jButton12 = new JButton();
jButton12.setBounds(new Rectangle(576, 61, 85, 32));
jButton12.setText("Browse");
jButton12.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (filePath == null) {
filePath = new String(".");
}
JFileChooser fc = new JFileChooser(filePath);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.showOpenDialog(jButton12);
File parseInput = fc.getSelectedFile();
String parseInputPath = parseInput.getAbsolutePath();
jTextField9.setText(parseInputPath);
filePath = parseInputPath;
}
});
}
return jButton12;
}
/**
* This method initializes jButton13
*
* @return javax.swing.JButton
*/
private JButton getJButton13() {
if (jButton13 == null) {
jButton13 = new JButton();
jButton13.setBounds(new Rectangle(578, 127, 85, 31));
jButton13.setText("Browse");
jButton13.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if (filePath == null) {
filePath = new String(".");
}
JFileChooser fc = new JFileChooser(filePath);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.showOpenDialog(jButton13);
File parseOutput = fc.getSelectedFile();
String parseOutputPath = parseOutput.getAbsolutePath();
jTextField10.setText(parseOutputPath);
filePath = parseOutputPath;
}
});
}
return jButton13;
}
/**
* This method initializes jButton14
*
* @return javax.swing.JButton
*/
private JButton getJButton14() {
if (jButton14 == null) {
jButton14 = new JButton();
jButton14.setBounds(new Rectangle(167, 175, 90, 28));
jButton14.setText("Parse");
jButton14.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
runParser();
}
});
}
return jButton14;
}
public void runParser() {
new Thread() {
public void run() {
try {
if (jTextField9.getText() != null && jTextField10.getText() != null) {
String ext = jTextField9.getText().substring(jTextField9.getText().lastIndexOf('.')+1,
jTextField9.getText().length());
if (ext.equalsIgnoreCase("xml")) {
BlastResultParserXML.parseBlastResultXml(jTextField9.getText(), jTextField10.getText());
}
else if (ext.equalsIgnoreCase("txt")) {
BlastResultParserTXT.parseBlastResultTxt(jTextField9.getText(), jTextField10.getText());
}
else if (ext.equalsIgnoreCase("html") || ext.equalsIgnoreCase("htm")) {
BlastResultParserHTML.parseBlastResultHtml(jTextField9.getText(), jTextField10.getText());
}
else {
System.out.println("Wrong file format!");
}
}
else {
System.out.println("Please specify BLAST result file and output parsed file");
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}.start();
}
/**
* Launches this application
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
BatchNcbiBlast application = new BatchNcbiBlast();
try {
application.loadProperties();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
application.getJFrame().setVisible(true);
}
});
// Find the current working directory
// System.out.println(new File(".").getCanonicalPath());
}
}