Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.util.*;
item1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
buscaFicherosPsiBlast(); // lo busca y si lo encuentra lo lee y pasa datos al hashtable <misDatos>.
} //cierro actionPerformed(ActionEvent e)
}); // cierra item1.addActionListener
item2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
leerPlantilla(); // lo busca y si lo encuentra lo lee y pasa datos al hashtable <misDatos>.
} //cierro actionPerformed(ActionEvent e)
}); // cierra item1.addActionListener
item3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
} //cierro actionPerformed(ActionEvent e)
}); // cierra item3.addActionListener
item4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
encontrado.setVisible(false);
repaint();
if(codigos.size()==0){//no se han cargado los códigos de la plantilla..
titul="¡ ATENCION !";
misatge="Primero debe leer el fichero plantilla.\n";
misatge=misatge+"Vaya al menú <Leer ficheros> opción <Fichero plantilla>";
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
return;
}else if(misDatos.size()==0){//no se han cargado ficheros psiblast...
titul="¡ ATENCION !";
misatge="Primero debe cargar los ficheros psiblast.\n";
misatge=misatge+"Vaya al menú <Leer ficheros> opción <Ficheros psi-blast>";
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
return;
}else{
seleccionarCodigo();
}
} //cierro actionPerformed(ActionEvent e)
}); // cierra item4.addActionListener
eligeCodigo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String cod=(String) eligeCodigo.getSelectedItem();
//textoEtiqueta="Código seleccionado: "+cod;
eligeCodigo.setVisible(false);
//encontrado.setText(textoEtiqueta);
// encontrado.setVisible(true);
repaint();
procesa(cod); //operaciones una vez elegido un código...
//lire();
} //cierro actionPerformed(ActionEvent e)
}); // cierra item5.addActionListener
men1.add(item1);
men1.add(item2);
men1.add(item3);
men2.add(item4);
mbar.add(men1);
mbar.add(men2);
setJMenuBar(mbar);
}// fin de ponMenu()
}// if (!llegeix(f))
}else{
titul="¡ ATENCION !";
detalle="No existe el directorio indicado";
JOptionPane.showMessageDialog(null,detalle,titul,JOptionPane.INFORMATION_MESSAGE);
return;
} // cierro if (arch.exists()) con su else...
}// fin de BuscaFicherosPsiBlast()
//______________________________________________________________________________________________
_____________
boolean llegeix(File fit) { // lee el fichero <fit> y pasa parte de sus datos al hashtable <misDatos>
int fase=0; //fase=0 significa que aun no hemos llegado a la linea que contiene <Sequences producing significant
alignments>
//fase=1 significará que ya hemos llegado a la linea que contiene <sequences producing significant
alignments>
//fase=2 significará que hemos llegado a una línea donde aparece <Alignments>, luego FIN
int k,k1,k3;
int cont=0; //para ver si se añaden datos al hashtable.
String tipo,clave,nom,restos,score,evalue;
DataInputStream dis = null;
String record = null;
if (fit.canRead())
{
try
{
FileInputStream fis = new FileInputStream(fit);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while ( (record=dis.readLine()) != null )
{
switch (fase) {
case 0: //estamos al principio del recorrido
if (record.indexOf("Sequences")>-1){
if (record.indexOf("alignments")>-1){
fase=1;
}
}
break;//salir del switch
case 1: //ya pasamos la línea que contiene <Sequences producing significant alignments>
//empieza la toma de datos.
if (record.indexOf("Alignments")>-1){ //hemos llegado al final de nuestra zona de lectura, luego fin...
fase=2;
if(cont==0){//la etiqueta no indica el nombre de ningún fichero.
titul="¡ ATENCION !";
misatge="No se han recogido datos del fichero: "+fit.getName();
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
}// fin de if(cont==0)
return true;
} else {
if (record.length()<1){ //línea sin información
break;
}else{
}
}
break;
case 2: //hemos llegado al final de nuestra zona de lectura, luego fin...
if(cont==0){//la etiqueta no indica el nombre de ningún fichero.
titul="¡ ATENCION !";
misatge="No se han recogido datos del fichero: "+fit.getName();
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
}// fin de if(cont==0)
return true;
} //cierro while
}
catch (IOException e)
{
misatge="Excepció IOException!" + e.getMessage();
return false;
}
finally
{
if (dis != null)
{
try
{
dis.close();
}
catch (IOException ioe)
{
misatge="Excepció IOException! al cierre " + ioe.getMessage();
return false;
}
}
}
} // del canRead
if(cont==0){//la etiqueta no indica el nombre de ningún fichero.
titul="¡ ATENCION !";
misatge="No se han recogido datos del fichero: "+fit.getName();
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
}// fin de if(cont==0)
return true;
}// fin de llegeix
//________________________________________________________________________
private void leerPlantilla (){
String detalle=" ";
int n=0;
int k1,k2,k3;
String mcodi,mf1,mf2;
textoEtiqueta=" ";
encontrado.setVisible(false);
repaint();
String nomArchiu=JOptionPane.showInputDialog("Indica el nombre y extension del fichero plantilla.");
if(nomArchiu==null||nomArchiu.length()<2){
titul="¡ ATENCION !";
detalle="Debe indicar un Archivo";
JOptionPane.showMessageDialog(null,detalle,titul,JOptionPane.INFORMATION_MESSAGE);
return;
}//cierra if(nomArchiu==null||nomArchiu.length()<2)
f=new File(nomArchiu);
textoEtiqueta="Leyendo el archivo "+nomArchiu;
detalle=" ";
DataInputStream dis = null;
String record = null;
if (f.canRead())
{
try
{
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
while ( (record=dis.readLine()) != null ) {
k1=record.indexOf('\t'); // busco el primer tabulador
if(k1>0){
mcodi=record.substring(0,k1);
mcodi=mcodi.trim();
}else{
continue;
}//fin de if(k1>0)
k2=record.indexOf('\t',k1+1); // busco el siguiente tabulador
if(k2>0){
mf1=record.substring(k1+1,k2);
mf1=mf1.trim();
}else{
continue;
}//fin de if(k2>0)
k3=record.lastIndexOf('\t'); //busco posición del último tabulador
if(k3>0){
mf2=record.substring(k3+1);
mf2=mf2.trim();
}else{
continue;
}//fin de if(k3>0)
miPlantilla.put(mcodi, new Plantilla(mf1,mf2));
codigos.add(mcodi); //los códigos de la plantilla se añaden al ArrayList <codigos> para luego poder
seleccionar uno.
n++; //cuenta numero de codigos añadidos al hashtable miPlantilla
textoEtiqueta=textoEtiqueta+"\n Encontrados: "+mcodi+"..."+mf1+"..."+mf2;
}
finally
{
if (dis != null)
{
try
{
dis.close();
}
catch (IOException ioe)
{
misatge="Excepció IOException! al cierre " + ioe.getMessage();
}
}
}
}
}//fin de LeerPlantilla()
//_________________________________
if(f.equals(ficher)){//el objeto guardado es del mismo fichero donde estaba el código buscado.
String fun=in.nom; //la función indicada en ese objeto.
if(fun==null){
titul="¡ ATENCION !";
misatge=" No consta función en el hashtable psiblast.";
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
return;
}// cierra if(fun==null)
int pos=fun.indexOf(f1);
if(pos>0){ //encuentra la función <f1> correspondiente al código buscado.
if(in.score==null){
titul="¡ ATENCION !";
misatge=" No consta score en el hashtable psiblast.";
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
return;
}// cierra if(in.score==null)
int p=Integer.parseInt(in.score);
if(p>scorf1){
scorf1=p;
evalf1=in.evalue;
}//cierra if(p>scorf1)
}//cierra if(pos>0)
pos=fun.indexOf(f2);
if(pos>0){ //encuentra la función <f2> correspondiente al código buscado.
if(in.score==null){
titul="¡ ATENCION !";
misatge=" No consta score en el hashtable psiblast.";
JOptionPane.showMessageDialog(null,misatge,titul,JOptionPane.INFORMATION_MESSAGE);
return;
}// cierra if(in.score==null)
int p=Integer.parseInt(in.score);
if(p>scorf2){
scorf2=p;
evalf2=in.evalue;
}//cierra if(p>scorf2)
}//cierra if(pos>0)
}//cierra if(f.equals(ficher))
}//cierra while (lista.hasMoreElements()
textoEtiqueta="\nEn la plantilla se seleccionó el código: "+codi+", con sus funciones: "+f1+" y "+f2+"\n\n";
textoEtiqueta=textoEtiqueta+"En los ficheros PSIBLAST el código seleccionado: "+codi+" se localizó en el fichero:
"+ficher+"\n\n";
if(scorf1>0)
textoEtiqueta=textoEtiqueta+"donde la función: "+f1+" consta con SCORE="+scorf1+ " y EVALUE="+evalf1+"\n\n";
else
textoEtiqueta=textoEtiqueta+"pero no consta la función: "+f1+"\n\n";
if(scorf2>0)
textoEtiqueta=textoEtiqueta+"y la función: "+f2+" consta con SCORE="+scorf2+ " y EVALUE="+evalf2;
else
textoEtiqueta=textoEtiqueta+"pero no consta la función: "+f2;
encontrado.setText(textoEtiqueta);
encontrado.setVisible(true);
repaint();
}//fin de private void buscar(String codi, String f1, String f2)
}// fin de public class moon extends JFrame