Nano'nun Günlüğü…

Ideallerimi gerceklestirmek icin arastiriyorum, Unutmamak icin yaziyorum!

  • Bulundugunuz Sayfa: 
  • Ana Sayfa
  • Java Desktop App ile Local Sequence Alignment

Java Desktop App ile Local Sequence Alignment

Gönderim Temmuz 7th, 2014

Bu makalemde size biyo informatik alaninda cok sik kullanilan bir hizalama yontemi olan Local Sequence Alignment ‘in Java Desktop Application ile kodlanmasi hakkinda basit bir uygulama paylasiyor olucam.

Yine ayni zamanda java uzerinde string kontrollerini ve java desktop application orneklerini iyi bir sekilde pekistirmis olabileceksiniz. Yazinin sonunda kullanabileceginiz birden fazla dizilim ornekleride bulunmaktadir.

LAS.Java Komutlari

import java.util.Stack;

public class LAS {

private String seq1, seq2;
public int matrix[][];
private int gap;
private int match;
private int mismatch;

public LAS(){}

public LAS(String sequence1, String sequence2, int m, int mm, int g)
{
this.seq1 = “-” + sequence1.toUpperCase();
this.seq2 = “-” + sequence2.toUpperCase();
this.match = m;
this.gap = g;
this.mismatch = mm;

matrix = new int[sequence1.length() + 1][sequence2.length() + 1];

for (int i = 0; i < sequence1.length(); i++)
for (int j = 0; j < sequence2.length(); j++)
matrix[i][j] = 0;
}

public void matrixOlustur()
{
for (int i = 0; i < seq1.length(); i++) {
for (int j = 0; j < seq2.length(); j++) {
if (i != 0 && j != 0) {
if (seq1.charAt(i) == seq2.charAt(j)) {  //match
matrix[i][j] = Math.max(0, Math.max(
matrix[i – 1][j – 1] + match, Math.max(
matrix[i – 1][j] + gap,
matrix[i][j – 1] + gap)));
}
else {   //gap ve mismatch
matrix[i][j] = Math.max(0, Math.max(
matrix[i – 1][j – 1] + mismatch, Math.max(
matrix[i – 1][j] + gap,
matrix[i][j – 1] + gap)));
}
}
}
}
}

public int enYuksekBul()
{
int enYuksek = 0, iEnYuksek = 0, jEnYuksek = 0;
for (int i = 0; i < seq1.length(); i++) {
for (int j = 0; j < seq2.length(); j++) {
if (matrix[i][j] > enYuksek) {
enYuksek = matrix[i][j];
iEnYuksek = i;
jEnYuksek = j;
}
}
}
return enYuksek;
}

public void matrixEkranaBas()
{
for (int i = 0; i < seq1.length(); i++) {
if (i == 0) {
for (int z = 0; z < seq2.length(); z++) {
if (z == 0)
System.out.println(”   “);
System.out.print(seq2.charAt(z) + ”  “);

if (z == seq2.length() – 1)
System.out.println();
}
}
for (int j = 1; j < seq2.length(); j++) {
if (j == 1) {
System.out.print(seq1.charAt(i) + ”  “);
}
System.out.print(matrix[i][j] + ”  “);
}
System.out.println();
}
System.out.println(); }
}

LocalAlignment.Java Komutlari

import javax.swing.table.DefaultTableModel;

public class LocalAlignment extends javax.swing.JFrame {

public String seq1,seq2;
public int match, mismatch, gap;

public LocalAlignment() {
initComponents();
}
@SuppressWarnings(“unchecked
private void initComponents() {

jTextField2 = new javax.swing.JTextField();
jTextField1 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“DNA – Local Alignment”);

jTextField2.setText(“GCAGAGCACG”);

jTextField1.setText(“GCTGGAAGGCAT”);

jLabel1.setFont(new java.awt.Font(“Tahoma”, 1, 14));
jLabel1.setText(“Sequence 1”);

jButton1.setFont(new java.awt.Font(“Tahoma”, 1, 12));
jButton1.setText(“Local Alignment”);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jLabel2.setFont(new java.awt.Font(“Tahoma”, 1, 14));
jLabel2.setText(“Sequence 2”);

jLabel3.setFont(new java.awt.Font(“Tahoma”, 1, 14));
jLabel3.setText(“Match”);

jLabel4.setFont(new java.awt.Font(“Tahoma”, 1, 14));
jLabel4.setText(“Mismatch”);

jLabel5.setFont(new java.awt.Font(“Tahoma”, 1, 14));
jLabel5.setText(“Gap”);

jTextField3.setText(“5”);

jTextField4.setText(“-4”);

jTextField5.setText(“-4”);

jScrollPane2.setViewportView(jTable1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel1)
.addGap(4, 4, 4)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(16, 16, 16)
.addComponent(jLabel3)
.addGap(38, 38, 38)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(92, 92, 92)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel5)
.addGap(53, 53, 53)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel2)
.addGap(4, 4, 4)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4)
.addGap(15, 15, 15)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(19, 19, 19))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 720, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(1, 1, 1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(1, 1, 1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)))
.addGap(18, 18, 18)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36))
);

pack();
}
public LAS localAli;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
seq1 = “-” + jTextField1.getText();
seq2 = jTextField2.getText();
match = Integer.valueOf(jTextField3.getText());
mismatch = Integer.valueOf(jTextField4.getText());
gap = Integer.valueOf(jTextField5.getText());

localAli = new LAS(seq2, seq1, match, mismatch, gap);
localAli.matrixOlustur();
System.out.println(“Dizi en yuksek score: ” + localAli.enYuksekBul());
localAli.matrixEkranaBas();
tabloDoldur();
}

public void tabloDoldur()
{
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();

model.addColumn(” “);
model.addColumn(“-“);
for(int i = 0; i < jTextField1.getText().length(); i++)
model.addColumn(jTextField1.getText().charAt(i));

model.addRow(new Object[]{“-“});
for(int i = 0; i < seq2.length(); i++)
model.addRow(new Object[]{seq2.charAt(i)});

for (int i = 0; i < model.getColumnCount(); i++)
for (int j = 0; j < model.getRowCount()+2; j++)
model.setValueAt(localAli.matrix[i][j+1], i, j+1);
}

public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“Nimbus”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(LocalAlignment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(LocalAlignment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(LocalAlignment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(LocalAlignment.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LocalAlignment().setVisible(true);
}
});
}

private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
}

Ekran Goruntusu

dnaLocal1

 

 

 

 

 

 

Keyifli Calismalar Dilerim.

Etiketler: , , , , ,
Bulundugu Konu Etiketleri Akademik, BioInformatic, Java, Yazilim |

Lutfen Yorumlarinizi Burdan Ulastiriniz!...

You must be Kullanici Adiniz : to post a comment.

Istatistik

  • 1 Uye
  • 334 Yazi
  • 16 Yorum Var