6 Replies - 894 Views - Last Post: 20 September 2012 - 01:50 PM Rate Topic: -----

#1 ric1989  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 96
  • Joined: 28-February 12

DNA String segment coding

Posted 18 September 2012 - 09:05 PM

Decode triplets letters string in a DNA java project
Basically it is a program that holds 64 triple letters sets as string
the program needs to search each three letter and display aminoAcid letter that matches the triple letter.

My question to experts and guru is that how to add all my work into a GUI form?
i did a sample of my GUI.

Another question is how can i use a triple letter like "ATG" as a string to be placed as a stop string to end the letter search?

any other tips to make program nicer is helpful too?

example: where user enter string sequence: ATGGCAACG on a textfield, the other textfield display the second static string aminoAcids: MetAlaThr on the second textfield.

when user enter letter: ATG it should return Met.
then user enter next string letter: GCA it should return Ala.



import java.awt.*;      // importing tools for program
import javax.swing.*;
import java.awt.event.*; 
import java.util.Scanner; 

//name of my program
public class ProteinFinder{                            
//Strings are set up as One-dimensional array to be used by user
private static String[] Sequences = {"ATG", "GCA", "ACG", "TGA", "ATT", "TAG", "TAA","TTA", "TTT", "TTC", "TTG", "CTT", "CTC", "ATC", "ATA", "GTT", "GTC", "GTA", "GTG", "TCT", "TCC","TCA","TCG","CCT", "CCC","CCA","CCG","ACT","ACC","ACA","ACG","GCT","GCC","GCG","TAT","TAC","CAT","CAC","CAA", "CAG","AAT","AAC","AAA","AAG","GAT","GAC","GAA","GAG","TGT","TGC","TGG","CGT","CGC","CGA","CGG","AGT","AGC","AGA","AGG","GGT","GGC","GGA","GGG"};   //assign string to variable
//second word that shows after user input three letters
private static String [] aminoAcids = {"Met", "Ala", "Thr", "STOP", "Ile", "STOP", "STOP", "Leu", "Phe", "Phe", "Leu", "Leu", "Leu", "Ile", "Ile", "Val", "Val", "Val", "Ser", "Ser", "Ser", "Ser", "Pro", "Pro", "Pro", "Pro", "Thr", "Thr", "Thr", "Ala", "Ala", "Ala", "Tyr", "His", "Gln", "Gln", "Asn", "Asn", "Lys", "Lys", "Asp", "Asp", "Glu", "Glu", "Cys", "Cys", "Trp", "Arg", "Arg", "Arg", "Ser", "Ser", "Arg", "Arg", "Gly", "Gly", "Gly", "Gly"};
private static String Proteins = "";  
//initiate string as proteins

public static String find(String dna){
    dna.toUpperCase();  //convert the string into uppercase triplet letter
    
   int i = 0;                 //for loop to find triplet letters
    for(i = 0; i<7; i+=3){
     for(int n = 0; n < 3; n++){
    	if(dna.substring(i, i+3).equals( Sequences[n]))
    		 Proteins += aminoAcids[n];
   
     }
     
     
    }

    return Proteins; //give the user the protein letters program finds
}                                                              

                                 
public static void main(String[] args){       //program needs to execute action

String result =  find("ATGGCAACG");
 System.out.println(result);
}
}





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

public class dnaGUI extends JFrame implements ActionListener{
    private JButton button1;
    private JPanel panel;
    private JTextField field1, field2;
    
    public static void main()
    {
        dnaGUI myFrame = new dnaGUI();
        myFrame.setSize(400,310);
        myFrame.dnaGUI();
        myFrame.setTitle("DNA Graphic User Inteface");
        myFrame.setVisible(true);
    }
    
    private void dnaGUI ()
    {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container window = getContentPane();
        window.setLayout(new FlowLayout());
        
        // use one class to handle all of the buttons
        button1 = new JButton("CLICK HERE");
        field1 = new JTextField(10);
        field2 = new JTextField(10);
        button1.addActionListener(this);
        
        // add buttons to the window
        window.add(button1);
        window.add(field1);
        window.add(field2);
        
        // add the panel to the window
        panel = new JPanel();
        panel.setPreferredSize(new Dimension(300,200));
        panel.setBackground(Color.green);
        window.add(panel);
    }
    
                
    public void actionPerformed(ActionEvent event){                                      //initializing the action
     if (event.getSource().equals(field1)){                                 //finding event of the source for field 2
        field1.setText("");
        }else if(event.getSource().equals(field2)){   //finding event of the source for field 3
            field2.setText("");
        } 
}
    }



Is This A Good Question/Topic? 0
  • +

Replies To: DNA String segment coding

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: DNA String segment coding

Posted 19 September 2012 - 07:36 AM

Why 2 JTextField ?
User can aslso enter protein and you will display the sequence ?
Was This Post Helpful? 1
  • +
  • -

#3 ric1989  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 96
  • Joined: 28-February 12

Re: DNA String segment coding

Posted 19 September 2012 - 07:47 AM

i analyze the program and will be using only 1 textfield to enter protein and to display the sequence. i was thinking on adding a linear search and a while do loop to run the program nicer.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: DNA String segment coding

Posted 19 September 2012 - 07:52 AM

Use a JTextField for the DNS sequence and a JLabel for the protein
If all the DNA are 3 letters long this shhould be a piece of cake
Just add and actionLister() to the JTextField
Call your actual code to return the String of proteins and put it into the JLabel
Was This Post Helpful? 0
  • +
  • -

#5 ric1989  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 96
  • Joined: 28-February 12

Re: DNA String segment coding

Posted 19 September 2012 - 12:38 PM

i added my labels and the program GUI looks much nicer. for call to return the String of proteins and put it into the JLabel. can you give me an example of how to add my string to my jlabel gui?.

i know i have two string: one string sequences and another string amino acids that should display on the second box. the idea is the top box user write the string "ATGGCATAC" and second display the aminoacids string such as "MetAlaThr".

i wanted to know how to use a nested while do loop for this type of project?
thanks for the support.

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

public class dnaGUI extends JFrame implements ActionListener{
    private JButton button1;
    private JPanel panel;
    private JTextField textField;
    private JTextArea textArea;
    private JLabel Sequences, AminoAcids;
    
    public static void main()
    {
        dnaGUI myFrame = new dnaGUI();
        myFrame.setSize(310,200);
        myFrame.dnaGUI();
        myFrame.setTitle("DNA Graphic User Inteface");
        myFrame.setVisible(true);
    }
    
    private void dnaGUI()
    {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container window = getContentPane();
        window.setLayout(new FlowLayout());
        //makes a label for DNA sequences
        {Sequences = new JLabel("DNA Sequences");
				add(Sequences);
				add(Sequences);}
        //label = new JLabel("Protein ");
        //add(label);
        
        
        textArea = new JTextArea(2,20);  //create text area in middle of window
        add(textArea);                      //throw the text area in window
        
        // use one class to handle all of the buttons
        button1 = new JButton("CLICK HERE");
        textField = new JTextField(20);
				
        //adding actions to buttons
        textField.addActionListener(this);
        button1.addActionListener(this);
				
        // add buttons to the window
        window.add(button1);
        window.add(textField);
				
         //makes a label for aminoacids results
        //putting this code lower in those code smove the label
       { AminoAcids = new JLabel("Amino Acids result");
				add(AminoAcids);
				add(AminoAcids);}
				
        // add the panel to the window
        panel = new JPanel();
        panel.setPreferredSize(new Dimension(200,200));
        window.add(panel);
    }
    
    private final static String newline = "\n";
    
    public void actionPerformed(ActionEvent e){                                      //initializing the action
        String text = textField.getText();
        textArea.append(text + newline);
        textField.selectAll();
    }       
}


Was This Post Helpful? 0
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8066
  • View blog
  • Posts: 31,310
  • Joined: 06-March 08

Re: DNA String segment coding

Posted 19 September 2012 - 05:12 PM

Should be kind of like that

void actionPerformed(ActionEvent e) {
     String dna = textField.getText();          // get DNA sequence from textField
     String protein = ProteinFinder.find(dna);  // fetch protein String
     label.setText(protein);                    // put in in JLabel
}



You don't really need a JButton. The actionPerformed() will be triggered when you hit "enter" on the JTextField
Was This Post Helpful? 1
  • +
  • -

#7 ric1989  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 96
  • Joined: 28-February 12

Re: DNA String segment coding

Posted 20 September 2012 - 01:50 PM

i added that to my GUI =, it just shows me a blank white screen im guessing ill have to play around with my strings that contain the dna triple letters.

I need your help to learn how to do a do while loop
i wanted the program to go through triple letter such ATG and when it reach the Stop dna which are: TGA, TAG, and TAA to stop looping (stop finding) triple letters. At the end on my second window to display my amino acid triple letters result.

I wanted to know if i need a linear search for this. you are a good tutor and want to figure this out. since its due on sunday.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1