Package versusSNP.blast

Source Code of versusSNP.blast.BlastExecutor

package versusSNP.blast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import javax.swing.JOptionPane;

import versusSNP.Document;
import versusSNP.Parameter;
import versusSNP.gui.UICaption;
import versusSNP.gui.widgets.ProgressBar;
import versusSNP.util.Utils;

public class BlastExecutor implements Runnable {
  public static final String[] MATRICES = new String[] { "BLOSUM100",
    "BLOSUM30", "BLOSUM35", "BLOSUM40", "BLOSUM45", "BLOSUM50",
    "BLOSUM55", "BLOSUM60", "BLOSUM62", "BLOSUM65", "BLOSUM70",
    "BLOSUM75", "BLOSUM80", "BLOSUM85", "BLOSUM90", "BLOSUMN",
    "DAYHOFF", "EDNAFULL", "GONNET", "IDENTITY", "MATCH", "PAM10",
    "PAM100", "PAM110", "PAM120", "PAM130", "PAM140", "PAM150",
    "PAM160", "PAM170", "PAM180", "PAM190", "PAM20", "PAM200",
    "PAM210", "PAM220", "PAM230", "PAM240", "PAM250", "PAM260",
    "PAM270", "PAM280", "PAM290", "PAM30", "PAM300", "PAM310",
    "PAM320", "PAM330", "PAM340", "PAM350", "PAM360", "PAM370",
    "PAM380", "PAM390", "PAM40", "PAM400", "PAM410", "PAM420",
    "PAM430", "PAM440", "PAM450", "PAM460", "PAM470", "PAM480",
    "PAM490", "PAM50", "PAM500", "PAM60", "PAM70", "PAM80", "PAM90" };
  private StringBuffer cmd1, cmd2;
  private String oPath;
  private Document document;

  private BlastExecutor() {
    super();
    cmd1 = new StringBuffer();
    cmd2 = new StringBuffer();
  }
 
  public BlastExecutor(String qPath, String sPath, String oPath, String thresholds, boolean filters, Document document) {
    this(qPath, sPath, oPath, MATRICES[7], thresholds, filters, BlastParser.BLASTN, document);
  }
 
  public BlastExecutor(String qPath, String sPath, String oPath, String matrix, String thresholds, boolean filters, Document document) {
    this(qPath, sPath, oPath, matrix, thresholds, filters, BlastParser.BLASTN, document);
  }
 
  public BlastExecutor(String qPath, String sPath, String oPath, String matrix, String thresholds, boolean filters, byte program, Document document) {
    this();
    this.oPath = oPath;
    this.document = document;
    cmd1.append(Parameter.path_program_formatdb).append(" -i ").append(sPath).append(" -o T -p F");
    cmd2.append(Parameter.path_program_blastall).append(" -i ").append(qPath)
        .append(" -d ").append(sPath).append(" -o ")
        .append(oPath).append(" -e ").append(thresholds).append(" -F ")
        .append(filters ? "T" : "F");
    switch (program) {
    case BlastParser.BLASTN: cmd2.append(" -p blastn"); break;
    case BlastParser.BLASTX: cmd2.append(" -p blastx"); break;
    case BlastParser.BLASTP: cmd2.append(" -p blastp"); break;
    }
    if (!matrix.equals(MATRICES[8]))
      cmd2.append(" -M ").append(matrix);
  }
 
  @Override
  public void run() {
    Parameter.createTempDirectory();
    ProgressBar progressBar = new ProgressBar(UICaption.progress_caption_run_blast, UICaption.progress_label_run_blast, true);
    progressBar.setVisible(true);
    try {
      Process proc;
      BufferedReader stderr;
      String line;
      proc = Runtime.getRuntime().exec(cmd1.toString());
      stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
      while ((line = stderr.readLine()) != null) {
        System.out.println(line);
      }
      proc = Runtime.getRuntime().exec(cmd2.toString());
      stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
      while ((line = stderr.readLine()) != null) {
        System.out.println(line);
      }
      proc.waitFor();
      progressBar.setLabelAntTitle(UICaption.progress_label_parse_blast, UICaption.progress_caption_parse_blast);
      new Thread(new BlastParser(oPath, document)).start();
    } catch (IOException e) {
      JOptionPane.showMessageDialog(null, UICaption.dialog_exception_runtime_exec, UICaption.dialog_caption_error, JOptionPane.ERROR_MESSAGE);
      return;
    } catch (InterruptedException e) {
      JOptionPane.showMessageDialog(null, UICaption.dialog_exception_runtime_exec, UICaption.dialog_caption_error, JOptionPane.ERROR_MESSAGE);
      return;
    } finally {
      progressBar.dispose();
    }
  }
 
  public static boolean checkThresholdsFormat(String strThresholds) {
    if (strThresholds.length() < 4)
      return false;
    if (!Character.isDigit(strThresholds.charAt(0)))
      return false;
    if (strThresholds.charAt(1) != 'e')
      return false;
    if (strThresholds.charAt(2) != '-')
      return false;
    if (!Utils.isDigit(strThresholds.substring(3)))
      return false;
    return true;
  }
}
TOP

Related Classes of versusSNP.blast.BlastExecutor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.