Hi all

I have a empty GUI , what i need to do now is to put the algorithms I have into the GUI. Im not very sure how im supposed to go about doing it. Calling of files would be easier to me as i do not have to copy n paste the codes into the GUI codes but im not sure how to go about doing it. Because when i called the file, nothing happens, do i have to do any changes to the algorithm java file?(changing of codes?)

Compute.addActionListener(new ActionListener() {
  			public void actionPerformed(ActionEvent e) {
    			if(target3.isSelected() && query3.isSelected() && DynPro.isSelected()) {
    				System.out.println("Sequence 1: "+seq1.getText());
    				System.out.println("Sequence 2: "+seq2.getText());
    				 MatchApplet DPTest = new MatchApplet();
    				 screen.append("Seq1: "+seq1.getText()+"\n");
    				 screen.append("Seq2: "+seq2.getText()+"\n");

the algorithm file is named DPtest. Should i change it to DPTest DPTest = new DPTest(); to call the file? or is there another way for me to take my input from the gui and let it run in the algorithm file and get the output shown in my gui again?

help would be much appreciated.

Recommended Answers

All 12 Replies

You certainly don't want the algorithm code in the GUI. Presumably the "algorithm file" has some method that takes input and returns the result? Instantiate the class containing your algorithm, and call whatever method is required, and put the return from that function wherever it is that you want it to be displayed.

You shouldn't have to change the algorithm file - if you do, it's badly written and needs to be be changed. :)

hi because my algorithm files have got buffered readers in it how do i input my things from my gui, put it into thealgorithm file and take the output out and display into the gui again?

I hesitate to ask, but - what are the buffered readers reading?

the buffered reader is to read a sequence from the input from the gui or should is just change it a string and put it through my algorithm? But im not sure how to input into my algorithm file and get the output.sorry for the trouble but im not familiar with java classes and methods..

You won't need a reader to get the data from the gui - the gui is there to get the data for you. It'll come to your algorithm as ints or doubles or Strings or whatever you're processing.

my input from the gui would be seq1.getText(); how do i put this input into my algorithm file? Is there a specific code or way for me to put it in and take the results out?

I may be a little dim, but I'm not following you. What's a "seq1" and how does it relate to your gui? Is it an object in your gui?

Better question: what is your algorithm doing, in brief, and what sort of input does it require?

seq1 is my text field that i would like the get the input from when the user types in smth..my algorithm is actually alignment techniques (for protein sequences). I'll be putting my algorithm and GUI codes below..


GUI codes:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;



class Layout extends JFrame {
   
   
   JFileChooser Querychooser = new JFileChooser();
   JFileChooser Targetchooser = new JFileChooser();
   //String choosertitle;

   
   	Layout() {

    	final JTextField upload1 = new JTextField(15);
    	final JTextField upload2 = new JTextField(15);
    	final JTextField seq1 = new JTextField(15);
    	final JTextField seq2 = new JTextField(15);
   		final JTextField txt1 = new JTextField(15);
   		final JTextField txt2 = new JTextField(15);
   		 	
    	final JRadioButton query1, query2, query3, target1, target2, target3;
    	
    	final JButton uploadQuery = new JButton("Upload");
  			uploadQuery.addActionListener(new ActionListener(){
  			public void actionPerformed(ActionEvent e) {
  	
 				if (e.getSource() == uploadQuery) {
      			int returnVal = Querychooser.showOpenDialog(Layout.this);

      			if (returnVal == JFileChooser.APPROVE_OPTION) {
        		File file = Querychooser.getSelectedFile();
        		//This is where a real application would open the file.
        		String x = file.getName();
        		upload1.setText(x);
        		System.out.println(file);//print out selected file
      			} 
      			else {
        		//log.append("Open command cancelled by user." + newline);
      			}
     			 //log.setCaretPosition(log.getDocument().getLength());
 												  }
  													   }	
  																});
 
    	final JButton uploadTarget= new JButton("Upload");
    	uploadTarget.addActionListener(new ActionListener(){
  			public void actionPerformed(ActionEvent e) {
  	
 				if (e.getSource() == uploadTarget) {
      			int returnVal2 = Targetchooser.showOpenDialog(Layout.this);

      			if (returnVal2 == JFileChooser.APPROVE_OPTION) {
        		File file2 = Targetchooser.getSelectedFile();
        		//This is where a real application would open the file.
        		//log.append("Opening: " + file.getName() + "." + newline);
        		String y = file2.getName();
        		upload2.setText(y);
        		System.out.println(file2);//print out selected file
      			}
      			 else {
      			}
     			 //log.setCaretPosition(log.getDocument().getLength());
 												  }
  													   }	
  																});
    	    	
    	 final JComboBox targetCombo = new JComboBox ();
    	 targetCombo.setEditable(true);
    	 targetCombo.addItem(" Please Select a PDB File ");
    	 targetCombo.setOpaque(true);
    	 
    	 final JComboBox queryCombo = new JComboBox();
    	 queryCombo.setEditable(true);
    	 queryCombo.addItem(" Please Select a PDB File ");
    	
    	query1 = new JRadioButton();
    	query1.setLayout(new FlowLayout());
		query1.add(upload1);
		query1.add(uploadQuery);
		
   
	
    	query2 = new JRadioButton();
    	query2.setLayout(new FlowLayout());
    	query2.add(new JLabel("Select PDB File :"));
    	query2.add(queryCombo);

	File dir = new File("I:\\MP Project\\Pre-processing\\Raw Files");
        FilenameFilter filter = new FilenameFilter()
        {
        public boolean accept(File dir, String name)
            {
                return name.endsWith(".txt");
            }
        };
        String[] var = dir.list(filter);
        
        if (var == null)
        {
       		System.out.println("JCOMBO BOX Directory is INCORRECT or does not exist!");
        }
        else
        {
            for (int i=0; i<var.length; i++) //populate the combo
            {
                String filename = var[i];
				queryCombo.addItem(filename);
				targetCombo.addItem(filename);
				
            }
        }
    	
    	/////////////////////////////////

    	query3 = new JRadioButton();
    	query3.setLayout(new FlowLayout());
    	query3.add(new JLabel("    Enter Sequence :"));
		query3.add(seq1);
		
		
		
		
    	target1 = new JRadioButton();
    	target1.setLayout(new FlowLayout());
    	target1.add(upload2);
		target1.add(uploadTarget);
	
    	target2 = new JRadioButton();
    	target2.setLayout(new FlowLayout());
    	target2.add(new JLabel("Select PDB File :"));
    	target2.add(targetCombo);

    	target3 = new JRadioButton();
		target3.setLayout(new FlowLayout());
    	target3.add(new JLabel("    Enter Sequence :"));		
		target3.add(seq2);
		
///////////////////////////////////////////////////////
    	final ButtonGroup group1 = new ButtonGroup();
    	group1.add(query1);
    	group1.add(query2);
    	group1.add(query3);
    
    	//target group button
    	final ButtonGroup group2 = new ButtonGroup();
    	group2.add(target1);
    	group2.add(target2);
    	group2.add(target3);       
///////////////////////////////////////////////////////   
       
query1.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(query1.isSelected()) {
      query1.setEnabled(true);
      uploadQuery.setEnabled(true);
      upload1.setEnabled(true);
      queryCombo.setEnabled(false);
      seq1.setEnabled(false);
    } 
  }
});
    
query2.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(query2.isSelected()) {
      query2.setEnabled(true);
      upload1.setEnabled(false);
      uploadQuery.setEnabled(false);
      seq1.setEnabled(false);
      queryCombo.setEnabled(true);
  }
  }
});    
    
query3.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(query3.isSelected()) {
      query3.setEnabled(true);
      upload1.setEnabled(false);
      uploadQuery.setEnabled(false);
      queryCombo.setEnabled(false);
      seq1.setEnabled(true);
  }
  }
});      
    
target1.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(target1.isSelected()) {
      upload2.setEnabled(true);
      uploadTarget.setEnabled(true);
      targetCombo.setEnabled(false);
      seq2.setEnabled(false);
  }
  }
});   
 
target2.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(target2.isSelected()) {
      upload2.setEnabled(false);
      uploadTarget.setEnabled(false);
      targetCombo.setEnabled(true);
      seq2.setEnabled(false);
  }
  }
});    

target3.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(target3.isSelected()) {
      upload2.setEnabled(false);
      uploadTarget.setEnabled(false);
      targetCombo.setEnabled(false);
      seq2.setEnabled(true);
  }
  }
});
 
   	
    	JPanel querypane = new JPanel();
    	querypane.setLayout(new BoxLayout(querypane, BoxLayout.Y_AXIS));
    	querypane.setSize(10,10);
    	querypane.setBorder(BorderFactory.createTitledBorder("Query Structure"));
    	querypane.add(query1);
    	querypane.add(query2);
    	querypane.add(query3);

		JPanel targetpane = new JPanel();
		targetpane.setLayout(new BoxLayout(targetpane, BoxLayout.Y_AXIS));
		targetpane.setSize(10,10);
		targetpane.setBorder(BorderFactory.createTitledBorder("Target Structure"));
    	targetpane.add(target1);
    	targetpane.add(target2);
    	targetpane.add(target3);
    		
		final JCheckBox GeoHash, SuperPos, DynPro;
		
		GeoHash = new JCheckBox();
		GeoHash.setLayout(new FlowLayout());
		GeoHash.add(new JLabel("    Geometric Hashing"));
		GeoHash.add(new JButton("Results"));
		
		SuperPos = new JCheckBox();
		SuperPos.setLayout(new FlowLayout());
		SuperPos.add(new JLabel("    Superposition"));
		SuperPos.add(new JButton("Results"));
		
		DynPro = new JCheckBox();
		DynPro.setLayout(new FlowLayout());
		DynPro.add(new JLabel("    Dynamic Programming"));
		DynPro.add(new JButton("Results"));

		JPanel algorithmpane = new JPanel();
    	algorithmpane.setLayout(new BoxLayout(algorithmpane, BoxLayout.X_AXIS));
    	algorithmpane.setBorder(BorderFactory.createTitledBorder("Algorithms"));
    	algorithmpane.add(GeoHash);
    	algorithmpane.add(SuperPos);
    	algorithmpane.add(DynPro);	
    	
    	final JTextArea screen = new JTextArea(20,60);
    	JPanel resultpane = new JPanel();
    	resultpane.setLayout(new FlowLayout());
    	resultpane.setLayout(new BoxLayout(resultpane, BoxLayout.X_AXIS));
    	resultpane.add(screen, BorderLayout.CENTER);
    	resultpane.setBorder(BorderFactory.createTitledBorder("Results"));	
		
		
		
		
		
		
		JButton Compute, Print, Save;
		
		Compute = new JButton("Compute");
		Compute.setLayout(new BoxLayout(Compute, BoxLayout.X_AXIS));
		
			Compute.addActionListener(new ActionListener() {
  			public void actionPerformed(ActionEvent e) {
    			if(target3.isSelected() && query3.isSelected() && DynPro.isSelected()) {
    				System.out.println("Sequence 1: "+seq1.getText());
    				System.out.println("Sequence 2: "+seq2.getText());
    				 MatchApplet DPTest = new MatchApplet();
    				 screen.append("Seq1: "+seq1.getText()+"\n");
    				 screen.append("Seq2: "+seq2.getText()+"\n");

  }
  }
});		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		Print = new JButton("Print");
		Print.setLayout(new BoxLayout(Print, BoxLayout.X_AXIS));
		
		Save = new JButton("Save");
		Save.setLayout(new BoxLayout(Save, BoxLayout.X_AXIS));
		
		JPanel bottom = new JPanel();
		bottom.setLayout(new FlowLayout());
		bottom.add(Compute);
		bottom.add(Print);
		bottom.add(Save);
	
		Container contentPane = getContentPane();
		contentPane.add(querypane);
		contentPane.add(targetpane);
		contentPane.add(algorithmpane); 
		contentPane.add(resultpane);
		contentPane.add(bottom);
		//contentPane.add(chooser); 
			  
    		}//end of Layout()

    public static void main(String[] args) {
    	
    	//create frame
    	Layout frame = new Layout() ;
    	frame.setResizable(false);
    	frame.setTitle("Biomolecular Structure Comparison");
    	frame.setSize(700,680);
    	frame.setLayout(new FlowLayout());
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frame.setLocation(100,0);
    	frame.setVisible(true); 
   
		    }//end of main		    	
    }//end of class

Algorithm Codes (Alignment technique) :

import java.io.*;
import java.awt.*;
import javax.swing.*;

class MatchApplet extends JApplet {


//  TextField seq1in = new TextField("HEAGAWGHEE");
//  TextField seq2in = new TextField("PAWHEAE");

	TextArea outputArea;
	JButton button;
	JButton reset;

	JTextField tF1;
	JTextField tF2;

	JLabel l1;
	JLabel l2;

	String s1;
	String s2;


	public static void main(String[] args)
	{
		//Application for program
  		Frame f = new Frame();
  		f.addWindowListener(new java.awt.event.WindowAdapter()
  		{
       	public void windowClosing(java.awt.event.WindowEvent e)
       	{
       	System.exit(0);
      	};
     	});

  		MatchApplet ut = new MatchApplet();
  		ut.setSize(900,900); // same size as defined in the HTML APPLET
  		f.add(ut);
  		f.pack();
  		ut.init();
  		f.setSize(900,900 + 100); // add 20, seems enough for the Frame title,
  		f.show();
		//end of application for program

	}//end of public static void main(String[] args)



  	public void init()
	{

  		String display1="";
  		String display2="";

		try
		{
       	    BufferedReader in1 = new BufferedReader(new FileReader("C:\\Users\\Royston\\Documents\\My Received Files\\1a00(50).txt"));	//reading files in specified directory
  			BufferedReader in2 = new BufferedReader(new FileReader("C:\\Users\\Royston\\Documents\\My Received Files\\1a0a(50).txt"));	//reading files in specified directory

  			String str1;
			while ((str1 = in1.readLine()) != null)	//file reading
			{
  				display1 = str1;
  				System.out.print(display1);
  			}
  			in1.close();

  			System.out.println("");

			String str2;
			while ((str2 = in2.readLine()) != null)	//file reading
			{
  				display2 = str2;
  				System.out.print(display2);
  			}
			in2.close();



		Container c = getContentPane();
		c.setLayout(new FlowLayout());

		outputArea = new TextArea(40,110);
		Font font = new Font("Courier", Font.PLAIN, 12);
		outputArea.setFont(font);
		outputArea.setEditable(false);

		tF1 = new JTextField(display1);
		tF2 = new JTextField(display2);

		l1 = new JLabel("Sequence 1:");
		l2 = new JLabel("Sequence 2:");

		c.add(l1);
		c.add(tF1);
		c.add(l2);
		c.add(tF2);
		c.add(outputArea);


	final Substitution sub = new Blosum50();

		s1 += tF1.getText();
		s2 += tF2.getText();
		Output out = new Output ()
		{
	  		public void print(String s)
	  		{ outputArea.append(s); }

	  		public void println(String s)
	  		{ outputArea.append(s); outputArea.append("\n"); }

	  		public void println()
	  		{ outputArea.append("\n"); }
		};

	outputArea.setText("");
      (new NW      (sub, 8,     s1, s2)).domatch(out, "GLOBAL ALIGNMENT");
      (new SW      (sub, 8,     s1, s2)).domatch(out, "LOCAL ALIGNMENT");


      }catch( IOException ioException ) {}

  }//end of init()

}//end of class




// The class of substitution (scoring) matrices

abstract class Substitution {
  public int[][] score;

  void buildscore(String residues, int[][] residuescores) {
    // Allow lowercase and uppercase residues (ASCII code <= 127):
    score = new int[127][127];
    for (int i=0; i<residues.length(); i++) {
      char res1 = residues.charAt(i);
      for (int j=0; j<=i; j++) {
        char res2 = residues.charAt(j);
        score[res1][res2] = score[res2][res1]
	  = score[res1][res2+32] = score[res2+32][res1]
	  = score[res1+32][res2] = score[res2][res1+32]
	  = score[res1+32][res2+32] = score[res2+32][res1+32]
	  = residuescores[i][j];
      }
    }
  }

  abstract public String getResidues();
}


// The BLOSUM50 substitution matrix for amino acids (Durbin et al, p 16)

class Blosum50 extends Substitution {

  private String residues = "ARNDCQEGHILKMFPSTWYV";

  public String getResidues()
  { return residues; }

  private int[][] residuescores =
            /* A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V */
  { /* A */ {  5                                                          },
    /* R */ { -2, 7                                                       },
    /* N */ { -1,-1, 7                                                    },
    /* D */ { -2,-2, 2, 8                                                 },
    /* C */ { -1,-4,-2,-4,13                                              },
    /* Q */ { -1, 1, 0, 0,-3, 7                                           },
    /* E */ { -1, 0, 0, 2,-3, 2, 6                                        },
    /* G */ {  0,-3, 0,-1,-3,-2,-3, 8                                     },
    /* H */ { -2, 0, 1,-1,-3, 1, 0,-2,10                                  },
    /* I */ { -1,-4,-3,-4,-2,-3,-4,-4,-4, 5                               },
    /* L */ { -2,-3,-4,-4,-2,-2,-3,-4,-3, 2, 5                            },
    /* K */ { -1, 3, 0,-1,-3, 2, 1,-2, 0,-3,-3, 6                         },
    /* M */ { -1,-2,-2,-4,-2, 0,-2,-3,-1, 2, 3,-2, 7                      },
    /* F */ { -3,-3,-4,-5,-2,-4,-3,-4,-1, 0, 1,-4, 0, 8                   },
    /* P */ { -1,-3,-2,-1,-4,-1,-1,-2,-2,-3,-4,-1,-3,-4,10                },
    /* S */ {  1,-1, 1, 0,-1, 0,-1, 0,-1,-3,-3, 0,-2,-3,-1, 5             },
    /* T */ {  0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 2, 5          },
    /* W */ { -3,-3,-4,-5,-5,-1,-3,-3,-3,-3,-2,-3,-1, 1,-4,-4,-3,15       },
    /* Y */ { -2,-1,-2,-3,-3,-1,-2,-3, 2,-1,-1,-2, 0, 4,-3,-2,-2, 2, 8    },
    /* V */ {  0,-3,-3,-4,-1,-3,-3,-4,-4, 4, 1,-3, 1,-1,-3,-2, 0,-3,-1, 5 }
            /* A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V */
  };

  public Blosum50()
  { buildscore(residues, residuescores); }
}



// Pairwise sequence alignment

abstract class Align {
  Substitution sub;             // substitution matrix
  int d;                        // gap cost
  String seq1, seq2;            // the sequences
  int n, m;                     // their lengths
  Traceback B0;                 // the starting point of the traceback

  final static int NegInf = Integer.MIN_VALUE/2; // negative infinity

  public Align(Substitution sub, int d, String seq1, String seq2) {
    this.sub = sub;
    this.seq1 = strip(seq1); this.seq2 = strip(seq2);
    this.d = d;
    this.n = this.seq1.length(); this.m = this.seq2.length();
  }

  public String strip(String s) {
    boolean[] valid = new boolean[127];
    String residues = sub.getResidues();
    for (int i=0; i<residues.length(); i++) {
      char c = residues.charAt(i);
      if (c < 96)
	valid[c] = valid[c+32] = true;
      else
	valid[c-32] = valid[c] = true;
    }
    StringBuffer res = new StringBuffer(s.length());
    for (int i=0; i<s.length(); i++)
      if (valid[s.charAt(i)])
	res.append(s.charAt(i));
    return res.toString();
  }

  // Return two-element array containing an alignment with maximal score

  public String[] getMatch() {
    StringBuffer res1 = new StringBuffer();
    StringBuffer res2 = new StringBuffer();
    Traceback tb = B0;
    int i = tb.i, j = tb.j;
    while ((tb = next(tb)) != null) {
      if (i == tb.i)
        res1.append('-');
      else
        res1.append(seq1.charAt(i-1));
      if (j == tb.j)
        res2.append('-');
      else
        res2.append(seq2.charAt(j-1));
      i = tb.i; j = tb.j;
    }
    String[] res = { res1.reverse().toString(), res2.reverse().toString() };
    return res;
  }

  public String fmtscore(int val) {
    if (val < NegInf/2)
      return "-Inf";
    else
      return Integer.toString(val);
  }

  // Print the score, the F matrix, and the alignment
  public void domatch(Output out, String msg, boolean matrix) {
    out.println(msg + ":");
    out.println("Score = " + getScore());
    if (matrix) {
      out.println("The F matrix:");
      printf(out);
    }
    out.println("An optimal alignment:");
    String[] match = getMatch();
    out.println(match[0]);
    out.println(match[1]);
    out.println();
  }

  public void domatch(Output out, String msg)
  { domatch(out, msg, true); }

  // Get the next state in the traceback
  public Traceback next(Traceback tb)
  { return tb; }                // dummy implementation for the `smart' algs.

  // Return the score of the best alignment
  public abstract int getScore();

  // Print the matrix (matrices) used to compute the alignment
  public abstract void printf(Output out);

  // Auxiliary functions
  static int max(int x1, int x2)
  { return (x1 > x2 ? x1 : x2); }

  static int max(int x1, int x2, int x3)
  { return max(x1, max(x2, x3)); }

  static int max(int x1, int x2, int x3, int x4)
  { return max(max(x1, x2), max(x3, x4)); }

  static String padLeft(String s, int width) {
    int filler = width - s.length();
    if (filler > 0) {           // and therefore width > 0
      StringBuffer res = new StringBuffer(width);
      for (int i=0; i<filler; i++)
        res.append(' ');
      return res.append(s).toString();
    } else
      return s;
  }
}


// Alignment with simple gap costs

abstract class AlignSimple extends Align {
  int[][] F;                    // the matrix used to compute the alignment
  Traceback2[][] B;             // the traceback matrix

  public AlignSimple(Substitution sub, int d, String seq1, String seq2) {
    super(sub, d, seq1, seq2);
    F = new int[n+1][m+1];
    B = new Traceback2[n+1][m+1];
  }

  public Traceback next(Traceback tb) {
    Traceback2 tb2 = (Traceback2)tb;
    return B[tb2.i][tb2.j];
  }

  public int getScore()
  { return F[B0.i][B0.j]; }

  public void printf(Output out) {
    for (int j=0; j<=m; j++) {
      for (int i=0; i<F.length; i++)
	out.print(padLeft(fmtscore(F[i][j]), 5));
      out.println();
    }
  }
}


// Traceback objects

abstract class Traceback {
  int i, j;                     // absolute coordinates
}


// Traceback2 objects for simple gap costs

class Traceback2 extends Traceback {
  public Traceback2(int i, int j)
  { this.i = i; this.j = j; }
}


// Auxiliary classes for output

abstract class Output {
  public abstract void print(String s);
  public abstract void println(String s);
  public abstract void println();
}

class SystemOut extends Output {
  public void print(String s)
  { System.out.print(s); }

  public void println(String s)
  { System.out.println(s); }

  public void println()
  { System.out.println(); }
}


// Global alignment with the Needleman-Wunsch algorithm (simple gap costs)

class NW extends AlignSimple {

  public NW(Substitution sub, int d, String sq1, String sq2) {
    super(sub, d, sq1, sq2);
    int n = this.n, m = this.m;
    int[][] score = sub.score;
    for (int i=1; i<=n; i++) {
      F[i][0] = -d * i;
      B[i][0] = new Traceback2(i-1, 0);
    }
    for (int j=1; j<=m; j++) {
      F[0][j] = -d * j;
      B[0][j] = new Traceback2(0, j-1);
    }
    for (int i=1; i<=n; i++)
      for (int j=1; j<=m; j++) {
        int s = score[seq1.charAt(i-1)][seq2.charAt(j-1)];
        int val = max(F[i-1][j-1]+s, F[i-1][j]-d, F[i][j-1]-d);
        F[i][j] = val;
        if (val == F[i-1][j-1]+s)
          B[i][j] = new Traceback2(i-1, j-1);
        else if (val == F[i-1][j]-d)
          B[i][j] = new Traceback2(i-1, j);
        else if (val == F[i][j-1]-d)
          B[i][j] = new Traceback2(i, j-1);
        else
          throw new Error("NW 1");
      }
    B0 = new Traceback2(n, m);
  }
}


// Local alignment with the Smith-Waterman algorithm (simple gap costs)

class SW extends AlignSimple {
  public SW(Substitution sub, int d, String sq1, String sq2) {
    super(sub, d, sq1, sq2);
    int n = this.n, m = this.m;
    int[][] score = sub.score;
    int maxi = n, maxj = m;
    int maxval = NegInf;
    for (int i=1; i<=n; i++)
      for (int j=1; j<=m; j++) {
        int s = score[seq1.charAt(i-1)][seq2.charAt(j-1)];
        int val = max(0, F[i-1][j-1]+s, F[i-1][j]-d, F[i][j-1]-d);
        F[i][j] = val;
        if (val == 0)
          B[i][j] = null;
        else if (val == F[i-1][j-1]+s)
          B[i][j] = new Traceback2(i-1, j-1);
        else if (val == F[i-1][j]-d)
          B[i][j] = new Traceback2(i-1, j);
        else if (val == F[i][j-1]-d)
          B[i][j] = new Traceback2(i, j-1);
        else
          throw new Error("SW 1");
        if (val > maxval) {
          maxval = val;
          maxi = i; maxj = j;
        }
      }
    B0 = new Traceback2(maxi, maxj);
  }
}

seq1 is my text field that i would like the get the input from when the user types in smth..my algorithm is actually alignment techniques (for protein sequences). I'll be putting my algorithm and GUI codes below..

the algorithm takes 2 sequences which i named seq1 and seq2 in my GUI and calculates for their global and local alignment and all. so for the first part, i just need to input seq1 and seq2 into my algorithm file and show the output in my GUI.As for later parts, there will be a radiobutton that consist of an upload button, then the file being uploaded will also be brought into the algorithm file to do the necessary calculations..


GUI codes:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;



class Layout extends JFrame {
   
   
   JFileChooser Querychooser = new JFileChooser();
   JFileChooser Targetchooser = new JFileChooser();
   //String choosertitle;

   
   	Layout() {

    	final JTextField upload1 = new JTextField(15);
    	final JTextField upload2 = new JTextField(15);
    	final JTextField seq1 = new JTextField(15);
    	final JTextField seq2 = new JTextField(15);
   		final JTextField txt1 = new JTextField(15);
   		final JTextField txt2 = new JTextField(15);
   		 	
    	final JRadioButton query1, query2, query3, target1, target2, target3;
    	
    	final JButton uploadQuery = new JButton("Upload");
  			uploadQuery.addActionListener(new ActionListener(){
  			public void actionPerformed(ActionEvent e) {
  	
 				if (e.getSource() == uploadQuery) {
      			int returnVal = Querychooser.showOpenDialog(Layout.this);

      			if (returnVal == JFileChooser.APPROVE_OPTION) {
        		File file = Querychooser.getSelectedFile();
        		//This is where a real application would open the file.
        		String x = file.getName();
        		upload1.setText(x);
        		System.out.println(file);//print out selected file
      			} 
      			else {
        		//log.append("Open command cancelled by user." + newline);
      			}
     			 //log.setCaretPosition(log.getDocument().getLength());
 												  }
  													   }	
  																});
 
    	final JButton uploadTarget= new JButton("Upload");
    	uploadTarget.addActionListener(new ActionListener(){
  			public void actionPerformed(ActionEvent e) {
  	
 				if (e.getSource() == uploadTarget) {
      			int returnVal2 = Targetchooser.showOpenDialog(Layout.this);

      			if (returnVal2 == JFileChooser.APPROVE_OPTION) {
        		File file2 = Targetchooser.getSelectedFile();
        		//This is where a real application would open the file.
        		//log.append("Opening: " + file.getName() + "." + newline);
        		String y = file2.getName();
        		upload2.setText(y);
        		System.out.println(file2);//print out selected file
      			}
      			 else {
      			}
     			 //log.setCaretPosition(log.getDocument().getLength());
 												  }
  													   }	
  																});
    	    	
    	 final JComboBox targetCombo = new JComboBox ();
    	 targetCombo.setEditable(true);
    	 targetCombo.addItem(" Please Select a PDB File ");
    	 targetCombo.setOpaque(true);
    	 
    	 final JComboBox queryCombo = new JComboBox();
    	 queryCombo.setEditable(true);
    	 queryCombo.addItem(" Please Select a PDB File ");
    	
    	query1 = new JRadioButton();
    	query1.setLayout(new FlowLayout());
		query1.add(upload1);
		query1.add(uploadQuery);
		
   
	
    	query2 = new JRadioButton();
    	query2.setLayout(new FlowLayout());
    	query2.add(new JLabel("Select PDB File :"));
    	query2.add(queryCombo);

	File dir = new File("I:\\MP Project\\Pre-processing\\Raw Files");
        FilenameFilter filter = new FilenameFilter()
        {
        public boolean accept(File dir, String name)
            {
                return name.endsWith(".txt");
            }
        };
        String[] var = dir.list(filter);
        
        if (var == null)
        {
       		System.out.println("JCOMBO BOX Directory is INCORRECT or does not exist!");
        }
        else
        {
            for (int i=0; i<var.length; i++) //populate the combo
            {
                String filename = var[i];
				queryCombo.addItem(filename);
				targetCombo.addItem(filename);
				
            }
        }
    	
    	/////////////////////////////////

    	query3 = new JRadioButton();
    	query3.setLayout(new FlowLayout());
    	query3.add(new JLabel("    Enter Sequence :"));
		query3.add(seq1);
		
		
		
		
    	target1 = new JRadioButton();
    	target1.setLayout(new FlowLayout());
    	target1.add(upload2);
		target1.add(uploadTarget);
	
    	target2 = new JRadioButton();
    	target2.setLayout(new FlowLayout());
    	target2.add(new JLabel("Select PDB File :"));
    	target2.add(targetCombo);

    	target3 = new JRadioButton();
		target3.setLayout(new FlowLayout());
    	target3.add(new JLabel("    Enter Sequence :"));		
		target3.add(seq2);
		
///////////////////////////////////////////////////////
    	final ButtonGroup group1 = new ButtonGroup();
    	group1.add(query1);
    	group1.add(query2);
    	group1.add(query3);
    
    	//target group button
    	final ButtonGroup group2 = new ButtonGroup();
    	group2.add(target1);
    	group2.add(target2);
    	group2.add(target3);       
///////////////////////////////////////////////////////   
       
query1.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(query1.isSelected()) {
      query1.setEnabled(true);
      uploadQuery.setEnabled(true);
      upload1.setEnabled(true);
      queryCombo.setEnabled(false);
      seq1.setEnabled(false);
    } 
  }
});
    
query2.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(query2.isSelected()) {
      query2.setEnabled(true);
      upload1.setEnabled(false);
      uploadQuery.setEnabled(false);
      seq1.setEnabled(false);
      queryCombo.setEnabled(true);
  }
  }
});    
    
query3.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(query3.isSelected()) {
      query3.setEnabled(true);
      upload1.setEnabled(false);
      uploadQuery.setEnabled(false);
      queryCombo.setEnabled(false);
      seq1.setEnabled(true);
  }
  }
});      
    
target1.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(target1.isSelected()) {
      upload2.setEnabled(true);
      uploadTarget.setEnabled(true);
      targetCombo.setEnabled(false);
      seq2.setEnabled(false);
  }
  }
});   
 
target2.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(target2.isSelected()) {
      upload2.setEnabled(false);
      uploadTarget.setEnabled(false);
      targetCombo.setEnabled(true);
      seq2.setEnabled(false);
  }
  }
});    

target3.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    if(target3.isSelected()) {
      upload2.setEnabled(false);
      uploadTarget.setEnabled(false);
      targetCombo.setEnabled(false);
      seq2.setEnabled(true);
  }
  }
});
 
   	
    	JPanel querypane = new JPanel();
    	querypane.setLayout(new BoxLayout(querypane, BoxLayout.Y_AXIS));
    	querypane.setSize(10,10);
    	querypane.setBorder(BorderFactory.createTitledBorder("Query Structure"));
    	querypane.add(query1);
    	querypane.add(query2);
    	querypane.add(query3);

		JPanel targetpane = new JPanel();
		targetpane.setLayout(new BoxLayout(targetpane, BoxLayout.Y_AXIS));
		targetpane.setSize(10,10);
		targetpane.setBorder(BorderFactory.createTitledBorder("Target Structure"));
    	targetpane.add(target1);
    	targetpane.add(target2);
    	targetpane.add(target3);
    		
		final JCheckBox GeoHash, SuperPos, DynPro;
		
		GeoHash = new JCheckBox();
		GeoHash.setLayout(new FlowLayout());
		GeoHash.add(new JLabel("    Geometric Hashing"));
		GeoHash.add(new JButton("Results"));
		
		SuperPos = new JCheckBox();
		SuperPos.setLayout(new FlowLayout());
		SuperPos.add(new JLabel("    Superposition"));
		SuperPos.add(new JButton("Results"));
		
		DynPro = new JCheckBox();
		DynPro.setLayout(new FlowLayout());
		DynPro.add(new JLabel("    Dynamic Programming"));
		DynPro.add(new JButton("Results"));

		JPanel algorithmpane = new JPanel();
    	algorithmpane.setLayout(new BoxLayout(algorithmpane, BoxLayout.X_AXIS));
    	algorithmpane.setBorder(BorderFactory.createTitledBorder("Algorithms"));
    	algorithmpane.add(GeoHash);
    	algorithmpane.add(SuperPos);
    	algorithmpane.add(DynPro);	
    	
    	final JTextArea screen = new JTextArea(20,60);
    	JPanel resultpane = new JPanel();
    	resultpane.setLayout(new FlowLayout());
    	resultpane.setLayout(new BoxLayout(resultpane, BoxLayout.X_AXIS));
    	resultpane.add(screen, BorderLayout.CENTER);
    	resultpane.setBorder(BorderFactory.createTitledBorder("Results"));	
		
		
		
		
		
		
		JButton Compute, Print, Save;
		
		Compute = new JButton("Compute");
		Compute.setLayout(new BoxLayout(Compute, BoxLayout.X_AXIS));
		
			Compute.addActionListener(new ActionListener() {
  			public void actionPerformed(ActionEvent e) {
    			if(target3.isSelected() && query3.isSelected() && DynPro.isSelected()) {
    				System.out.println("Sequence 1: "+seq1.getText());
    				System.out.println("Sequence 2: "+seq2.getText());
    				 MatchApplet DPTest = new MatchApplet();
    				 screen.append("Seq1: "+seq1.getText()+"\n");
    				 screen.append("Seq2: "+seq2.getText()+"\n");

  }
  }
});		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		Print = new JButton("Print");
		Print.setLayout(new BoxLayout(Print, BoxLayout.X_AXIS));
		
		Save = new JButton("Save");
		Save.setLayout(new BoxLayout(Save, BoxLayout.X_AXIS));
		
		JPanel bottom = new JPanel();
		bottom.setLayout(new FlowLayout());
		bottom.add(Compute);
		bottom.add(Print);
		bottom.add(Save);
	
		Container contentPane = getContentPane();
		contentPane.add(querypane);
		contentPane.add(targetpane);
		contentPane.add(algorithmpane); 
		contentPane.add(resultpane);
		contentPane.add(bottom);
		//contentPane.add(chooser); 
			  
    		}//end of Layout()

    public static void main(String[] args) {
    	
    	//create frame
    	Layout frame = new Layout() ;
    	frame.setResizable(false);
    	frame.setTitle("Biomolecular Structure Comparison");
    	frame.setSize(700,680);
    	frame.setLayout(new FlowLayout());
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frame.setLocation(100,0);
    	frame.setVisible(true); 
   
		    }//end of main		    	
    }//end of class

Algorithm Codes (Alignment technique) :

import java.io.*;
import java.awt.*;
import javax.swing.*;

class MatchApplet extends JApplet {


//  TextField seq1in = new TextField("HEAGAWGHEE");
//  TextField seq2in = new TextField("PAWHEAE");

	TextArea outputArea;
	JButton button;
	JButton reset;

	JTextField tF1;
	JTextField tF2;

	JLabel l1;
	JLabel l2;

	String s1;
	String s2;


	public static void main(String[] args)
	{
		//Application for program
  		Frame f = new Frame();
  		f.addWindowListener(new java.awt.event.WindowAdapter()
  		{
       	public void windowClosing(java.awt.event.WindowEvent e)
       	{
       	System.exit(0);
      	};
     	});

  		MatchApplet ut = new MatchApplet();
  		ut.setSize(900,900); // same size as defined in the HTML APPLET
  		f.add(ut);
  		f.pack();
  		ut.init();
  		f.setSize(900,900 + 100); // add 20, seems enough for the Frame title,
  		f.show();
		//end of application for program

	}//end of public static void main(String[] args)



  	public void init()
	{

  		String display1="";
  		String display2="";

		try
		{
       	    BufferedReader in1 = new BufferedReader(new FileReader("C:\\Users\\Royston\\Documents\\My Received Files\\1a00(50).txt"));	//reading files in specified directory
  			BufferedReader in2 = new BufferedReader(new FileReader("C:\\Users\\Royston\\Documents\\My Received Files\\1a0a(50).txt"));	//reading files in specified directory

  			String str1;
			while ((str1 = in1.readLine()) != null)	//file reading
			{
  				display1 = str1;
  				System.out.print(display1);
  			}
  			in1.close();

  			System.out.println("");

			String str2;
			while ((str2 = in2.readLine()) != null)	//file reading
			{
  				display2 = str2;
  				System.out.print(display2);
  			}
			in2.close();



		Container c = getContentPane();
		c.setLayout(new FlowLayout());

		outputArea = new TextArea(40,110);
		Font font = new Font("Courier", Font.PLAIN, 12);
		outputArea.setFont(font);
		outputArea.setEditable(false);

		tF1 = new JTextField(display1);
		tF2 = new JTextField(display2);

		l1 = new JLabel("Sequence 1:");
		l2 = new JLabel("Sequence 2:");

		c.add(l1);
		c.add(tF1);
		c.add(l2);
		c.add(tF2);
		c.add(outputArea);


	final Substitution sub = new Blosum50();

		s1 += tF1.getText();
		s2 += tF2.getText();
		Output out = new Output ()
		{
	  		public void print(String s)
	  		{ outputArea.append(s); }

	  		public void println(String s)
	  		{ outputArea.append(s); outputArea.append("\n"); }

	  		public void println()
	  		{ outputArea.append("\n"); }
		};

	outputArea.setText("");
      (new NW      (sub, 8,     s1, s2)).domatch(out, "GLOBAL ALIGNMENT");
      (new SW      (sub, 8,     s1, s2)).domatch(out, "LOCAL ALIGNMENT");


      }catch( IOException ioException ) {}

  }//end of init()

}//end of class




// The class of substitution (scoring) matrices

abstract class Substitution {
  public int[][] score;

  void buildscore(String residues, int[][] residuescores) {
    // Allow lowercase and uppercase residues (ASCII code <= 127):
    score = new int[127][127];
    for (int i=0; i<residues.length(); i++) {
      char res1 = residues.charAt(i);
      for (int j=0; j<=i; j++) {
        char res2 = residues.charAt(j);
        score[res1][res2] = score[res2][res1]
	  = score[res1][res2+32] = score[res2+32][res1]
	  = score[res1+32][res2] = score[res2][res1+32]
	  = score[res1+32][res2+32] = score[res2+32][res1+32]
	  = residuescores[i][j];
      }
    }
  }

  abstract public String getResidues();
}


// The BLOSUM50 substitution matrix for amino acids (Durbin et al, p 16)

class Blosum50 extends Substitution {

  private String residues = "ARNDCQEGHILKMFPSTWYV";

  public String getResidues()
  { return residues; }

  private int[][] residuescores =
            /* A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V */
  { /* A */ {  5                                                          },
    /* R */ { -2, 7                                                       },
    /* N */ { -1,-1, 7                                                    },
    /* D */ { -2,-2, 2, 8                                                 },
    /* C */ { -1,-4,-2,-4,13                                              },
    /* Q */ { -1, 1, 0, 0,-3, 7                                           },
    /* E */ { -1, 0, 0, 2,-3, 2, 6                                        },
    /* G */ {  0,-3, 0,-1,-3,-2,-3, 8                                     },
    /* H */ { -2, 0, 1,-1,-3, 1, 0,-2,10                                  },
    /* I */ { -1,-4,-3,-4,-2,-3,-4,-4,-4, 5                               },
    /* L */ { -2,-3,-4,-4,-2,-2,-3,-4,-3, 2, 5                            },
    /* K */ { -1, 3, 0,-1,-3, 2, 1,-2, 0,-3,-3, 6                         },
    /* M */ { -1,-2,-2,-4,-2, 0,-2,-3,-1, 2, 3,-2, 7                      },
    /* F */ { -3,-3,-4,-5,-2,-4,-3,-4,-1, 0, 1,-4, 0, 8                   },
    /* P */ { -1,-3,-2,-1,-4,-1,-1,-2,-2,-3,-4,-1,-3,-4,10                },
    /* S */ {  1,-1, 1, 0,-1, 0,-1, 0,-1,-3,-3, 0,-2,-3,-1, 5             },
    /* T */ {  0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 2, 5          },
    /* W */ { -3,-3,-4,-5,-5,-1,-3,-3,-3,-3,-2,-3,-1, 1,-4,-4,-3,15       },
    /* Y */ { -2,-1,-2,-3,-3,-1,-2,-3, 2,-1,-1,-2, 0, 4,-3,-2,-2, 2, 8    },
    /* V */ {  0,-3,-3,-4,-1,-3,-3,-4,-4, 4, 1,-3, 1,-1,-3,-2, 0,-3,-1, 5 }
            /* A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V */
  };

  public Blosum50()
  { buildscore(residues, residuescores); }
}



// Pairwise sequence alignment

abstract class Align {
  Substitution sub;             // substitution matrix
  int d;                        // gap cost
  String seq1, seq2;            // the sequences
  int n, m;                     // their lengths
  Traceback B0;                 // the starting point of the traceback

  final static int NegInf = Integer.MIN_VALUE/2; // negative infinity

  public Align(Substitution sub, int d, String seq1, String seq2) {
    this.sub = sub;
    this.seq1 = strip(seq1); this.seq2 = strip(seq2);
    this.d = d;
    this.n = this.seq1.length(); this.m = this.seq2.length();
  }

  public String strip(String s) {
    boolean[] valid = new boolean[127];
    String residues = sub.getResidues();
    for (int i=0; i<residues.length(); i++) {
      char c = residues.charAt(i);
      if (c < 96)
	valid[c] = valid[c+32] = true;
      else
	valid[c-32] = valid[c] = true;
    }
    StringBuffer res = new StringBuffer(s.length());
    for (int i=0; i<s.length(); i++)
      if (valid[s.charAt(i)])
	res.append(s.charAt(i));
    return res.toString();
  }

  // Return two-element array containing an alignment with maximal score

  public String[] getMatch() {
    StringBuffer res1 = new StringBuffer();
    StringBuffer res2 = new StringBuffer();
    Traceback tb = B0;
    int i = tb.i, j = tb.j;
    while ((tb = next(tb)) != null) {
      if (i == tb.i)
        res1.append('-');
      else
        res1.append(seq1.charAt(i-1));
      if (j == tb.j)
        res2.append('-');
      else
        res2.append(seq2.charAt(j-1));
      i = tb.i; j = tb.j;
    }
    String[] res = { res1.reverse().toString(), res2.reverse().toString() };
    return res;
  }

  public String fmtscore(int val) {
    if (val < NegInf/2)
      return "-Inf";
    else
      return Integer.toString(val);
  }

  // Print the score, the F matrix, and the alignment
  public void domatch(Output out, String msg, boolean matrix) {
    out.println(msg + ":");
    out.println("Score = " + getScore());
    if (matrix) {
      out.println("The F matrix:");
      printf(out);
    }
    out.println("An optimal alignment:");
    String[] match = getMatch();
    out.println(match[0]);
    out.println(match[1]);
    out.println();
  }

  public void domatch(Output out, String msg)
  { domatch(out, msg, true); }

  // Get the next state in the traceback
  public Traceback next(Traceback tb)
  { return tb; }                // dummy implementation for the `smart' algs.

  // Return the score of the best alignment
  public abstract int getScore();

  // Print the matrix (matrices) used to compute the alignment
  public abstract void printf(Output out);

  // Auxiliary functions
  static int max(int x1, int x2)
  { return (x1 > x2 ? x1 : x2); }

  static int max(int x1, int x2, int x3)
  { return max(x1, max(x2, x3)); }

  static int max(int x1, int x2, int x3, int x4)
  { return max(max(x1, x2), max(x3, x4)); }

  static String padLeft(String s, int width) {
    int filler = width - s.length();
    if (filler > 0) {           // and therefore width > 0
      StringBuffer res = new StringBuffer(width);
      for (int i=0; i<filler; i++)
        res.append(' ');
      return res.append(s).toString();
    } else
      return s;
  }
}


// Alignment with simple gap costs

abstract class AlignSimple extends Align {
  int[][] F;                    // the matrix used to compute the alignment
  Traceback2[][] B;             // the traceback matrix

  public AlignSimple(Substitution sub, int d, String seq1, String seq2) {
    super(sub, d, seq1, seq2);
    F = new int[n+1][m+1];
    B = new Traceback2[n+1][m+1];
  }

  public Traceback next(Traceback tb) {
    Traceback2 tb2 = (Traceback2)tb;
    return B[tb2.i][tb2.j];
  }

  public int getScore()
  { return F[B0.i][B0.j]; }

  public void printf(Output out) {
    for (int j=0; j<=m; j++) {
      for (int i=0; i<F.length; i++)
	out.print(padLeft(fmtscore(F[i][j]), 5));
      out.println();
    }
  }
}


// Traceback objects

abstract class Traceback {
  int i, j;                     // absolute coordinates
}


// Traceback2 objects for simple gap costs

class Traceback2 extends Traceback {
  public Traceback2(int i, int j)
  { this.i = i; this.j = j; }
}


// Auxiliary classes for output

abstract class Output {
  public abstract void print(String s);
  public abstract void println(String s);
  public abstract void println();
}

class SystemOut extends Output {
  public void print(String s)
  { System.out.print(s); }

  public void println(String s)
  { System.out.println(s); }

  public void println()
  { System.out.println(); }
}


// Global alignment with the Needleman-Wunsch algorithm (simple gap costs)

class NW extends AlignSimple {

  public NW(Substitution sub, int d, String sq1, String sq2) {
    super(sub, d, sq1, sq2);
    int n = this.n, m = this.m;
    int[][] score = sub.score;
    for (int i=1; i<=n; i++) {
      F[i][0] = -d * i;
      B[i][0] = new Traceback2(i-1, 0);
    }
    for (int j=1; j<=m; j++) {
      F[0][j] = -d * j;
      B[0][j] = new Traceback2(0, j-1);
    }
    for (int i=1; i<=n; i++)
      for (int j=1; j<=m; j++) {
        int s = score[seq1.charAt(i-1)][seq2.charAt(j-1)];
        int val = max(F[i-1][j-1]+s, F[i-1][j]-d, F[i][j-1]-d);
        F[i][j] = val;
        if (val == F[i-1][j-1]+s)
          B[i][j] = new Traceback2(i-1, j-1);
        else if (val == F[i-1][j]-d)
          B[i][j] = new Traceback2(i-1, j);
        else if (val == F[i][j-1]-d)
          B[i][j] = new Traceback2(i, j-1);
        else
          throw new Error("NW 1");
      }
    B0 = new Traceback2(n, m);
  }
}


// Local alignment with the Smith-Waterman algorithm (simple gap costs)

class SW extends AlignSimple {
  public SW(Substitution sub, int d, String sq1, String sq2) {
    super(sub, d, sq1, sq2);
    int n = this.n, m = this.m;
    int[][] score = sub.score;
    int maxi = n, maxj = m;
    int maxval = NegInf;
    for (int i=1; i<=n; i++)
      for (int j=1; j<=m; j++) {
        int s = score[seq1.charAt(i-1)][seq2.charAt(j-1)];
        int val = max(0, F[i-1][j-1]+s, F[i-1][j]-d, F[i][j-1]-d);
        F[i][j] = val;
        if (val == 0)
          B[i][j] = null;
        else if (val == F[i-1][j-1]+s)
          B[i][j] = new Traceback2(i-1, j-1);
        else if (val == F[i-1][j]-d)
          B[i][j] = new Traceback2(i-1, j);
        else if (val == F[i][j-1]-d)
          B[i][j] = new Traceback2(i, j-1);
        else
          throw new Error("SW 1");
        if (val > maxval) {
          maxval = val;
          maxi = i; maxj = j;
        }
      }
    B0 = new Traceback2(maxi, maxj);
  }
}

Good gravy. I've sort of scrolled back and forth through that, and I think I could probably spend a while putting it under the microscope and still not understand it very well.

But if seq1 and seq2 are text fields, then getText() will return their contents as a String. So you pass the Strings to your algorithm and it does something with them. Damned if I can figure out what it does - or rather, I don't have time to claw through all of that to figure it out.

Is the BufferedReader for parsing the input? So your algorithm can use next() to get tokens? In that case, use a Scanner instead. A Scanner can scan a String, and it should get your tokens for you.

I hope that answers your question, I'm not sure it does...

so sorry currently there've been some changes to the requirements..what i need now is

when the button is clicked, the algorithm is to be ran in the background and output the the file, the outputting to a file i'll be trying it..but im not sure how to make it run in the background..

i have a result button that is supposed to read the output file from the algorithm.

The SwingWorker class is designed for running long-running tasks in the background with a Swing GUI.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.