Team:Freiburg software/Code/BlastRobotServlet.java

From 2009.igem.org

(Difference between revisions)
(New page: <div style="display: none;"><html><style> #tabs a.code_active { background-position:0% -42px; } #tabs a.code_active span { background-position:100% -42px; color:#213340; } #toc { display:n...)
(BlastRobotServlet)
 
Line 18: Line 18:
  <nowiki>
  <nowiki>
 +
/*
 +
*    Copyright: synbiowave
 +
*   
 +
*    License: GPL
 +
*   
 +
*    Authors: Paul Staab
 +
*   
 +
*    Version: 0.1
 +
*   
 +
*    DESCRIPTION:
 +
*    This is the main class of a SynBioWave-Robot doing a blast-search
 +
*/
 +
 +
package blastRobot;
 +
 +
import java.util.LinkedHashMap;
 +
 +
import org.biojava.bio.seq.DNATools;
 +
import org.synbiowave.menu.MenuItem;
 +
import org.synbiowave.servlet.AbstractSbwRobotServlet;
 +
import org.xml.sax.SAXException;
 +
 +
import com.google.wave.api.Event;
 +
import com.google.wave.api.RobotMessageBundle;
 +
import com.google.wave.api.TextView;
 +
 +
public class BlastRobotServlet extends AbstractSbwRobotServlet
 +
{
 +
 +
  private static final long serialVersionUID = 3125104904376445527L;
 +
 +
  @Override
 +
  public void createMenu(MenuItem menu)
 +
  {
 +
  MenuItem blast_prog = new MenuItem("textfield","Program",generateKey() );
 +
  blast_prog.setOption("value", "blastn");
 +
  MenuItem blast_db = new MenuItem("textfield","Database",generateKey() );
 +
  blast_db.setOption("value", "nr");
 +
  MenuItem blast_seq = new MenuItem("textarea","Sequence",generateKey() );
 +
  blast_seq.setOption("value", "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGGCC");
 +
 +
  menu.createSubItem("menu", "Sequence", this.generateKey())
 +
  .createSubItem("button", "BLAST", this.generateKey() )
 +
 
 +
  .createSubItem("form", "BLASTform", this.generateKey() )
 +
  .appendSubItem(blast_prog)
 +
  .appendSubItem(blast_db)
 +
  .appendSubItem(blast_seq);
 +
  }
 +
 +
  @Override
 +
  public String myName() {
 +
  return "blastrobot@appspot.com";
 +
  }
 +
 +
  @Override
 +
  public void processSbwMenuEvents(String buttonLabel, LinkedHashMap<String, String> formValues , Event event)
 +
  {
 +
  if (buttonLabel.contains("BLASTform"))
 +
  {  
 +
  try
 +
  {
 +
  TextView tv = event.getWavelet().getRootBlip().getDocument();
 +
 
 +
  //Do the search
 +
  BlastSearch blast = new BlastSearch();
 +
  blast.setSequence(DNATools.createDNA(formValues.get(this.generateKey() + "Sequence")));
 +
  blast.setDatabase(formValues.get(this.generateKey() + "Database"));
 +
  blast.setProgram(formValues.get(this.generateKey() + "Program"));
 +
  blast.search();
 +
   
 +
  MenuItem blastbutton = new MenuItem("chron","Blasting...",this.generateKey());
 +
  blastbutton.setOption("value", "3000");
 +
  this.directMenuInsert(event.getWavelet(), blastbutton);
 +
 
 +
  tv.setAnnotation("rid", blast.getRID() );
 +
  tv.setAnnotation("blastresult", "0"); 
 +
  }
 +
  catch (Exception error)
 +
  {
 +
  TextView tv = event.getBlip().getDocument();
 +
  tv.append("ERROR:" + error.getMessage() + " \n " );
 +
  }
 +
  }
 +
  if (buttonLabel.contains("Blasting..."))
 +
  {  
 +
 
 +
  TextView tv2 = event.getWavelet().getRootBlip().getDocument();
 +
  try
 +
  {
 +
  if ( (!tv2.getAnnotations("blastresult").isEmpty()) && tv2.getAnnotations("blastresult").get(0).getValue().contentEquals("0") )
 +
  {
 +
tv2.setAnnotation("blastresult", "1"); 
 +
 +
BlastSearch blast = new BlastSearch();
 +
  blast.setRID( tv2.getAnnotations("rid").get(0).getValue() );
 +
  blast.parseResult();
 +
 
 +
  TextView tv = event.getWavelet().appendBlip().getDocument();
 +
  tv.append(blast.waveOutput());
 +
  }
 +
  }
 +
  catch (SAXException error)
 +
  {
 +
  tv2.setAnnotation("blastresult", "0");
 +
  MenuItem blastbutton = new MenuItem("chron","Blasting...",this.generateKey());
 +
  blastbutton.setOption("value", "3000");
 +
  this.directMenuInsert(event.getWavelet(), blastbutton);
 +
  }
 +
  catch (Exception error)
 +
  {
 +
  event.getWavelet().appendBlip().getDocument().append("ERROR:" + error.getMessage() + error.getClass().getCanonicalName() + " \n ");
 +
  }  
 +
  }
 +
  }
   
   
 +
  @Override
 +
  public void processSbwEvents(RobotMessageBundle bundle)
 +
  {           
 +
 +
  }
 +
}
  </nowiki>
  </nowiki>

Latest revision as of 22:27, 20 October 2009


BlastRobotServlet

 /*
*    Copyright: synbiowave
*     
*    License: GPL
*     
*    Authors: Paul Staab
*     
*    Version: 0.1 
*    
*    DESCRIPTION:
*    	This is the main class of a SynBioWave-Robot doing a blast-search
*/

package blastRobot;

import java.util.LinkedHashMap;

import org.biojava.bio.seq.DNATools;
import org.synbiowave.menu.MenuItem;
import org.synbiowave.servlet.AbstractSbwRobotServlet;
import org.xml.sax.SAXException;

import com.google.wave.api.Event;
import com.google.wave.api.RobotMessageBundle;
import com.google.wave.api.TextView;

public class BlastRobotServlet extends AbstractSbwRobotServlet 
{

  private static final long serialVersionUID = 3125104904376445527L;

  @Override
  public void createMenu(MenuItem menu) 
  {
	  MenuItem blast_prog = new MenuItem("textfield","Program",generateKey() );
	  blast_prog.setOption("value", "blastn");
	  MenuItem blast_db = new MenuItem("textfield","Database",generateKey() );
	  blast_db.setOption("value", "nr");
	  MenuItem blast_seq = new MenuItem("textarea","Sequence",generateKey() );
	  blast_seq.setOption("value", "ACAAGATGCCATTGTCCCCCGGCCTCCTGCTGCTGCTGCTCTCCGGGGCC");
	
	  menu.createSubItem("menu", "Sequence", this.generateKey())
	  	.createSubItem("button", "BLAST", this.generateKey() )
	  	
  		.createSubItem("form", "BLASTform", this.generateKey() )
  		.appendSubItem(blast_prog)
  		.appendSubItem(blast_db)
  		.appendSubItem(blast_seq);
  }

  @Override
  public String myName() {
  	return "blastrobot@appspot.com";
  }

  @Override
  public void processSbwMenuEvents(String buttonLabel, LinkedHashMap<String, String> formValues , Event event)
  {
	  if (buttonLabel.contains("BLASTform"))
	  {	  
		  try 
		  {
			  TextView tv = event.getWavelet().getRootBlip().getDocument();
			  
			  //Do the search
			  BlastSearch blast = new BlastSearch();
			  blast.setSequence(DNATools.createDNA(formValues.get(this.generateKey() + "Sequence")));
			  blast.setDatabase(formValues.get(this.generateKey() + "Database"));
			  blast.setProgram(formValues.get(this.generateKey() + "Program"));
			  blast.search();
			  			  
			  MenuItem blastbutton = new MenuItem("chron","Blasting...",this.generateKey());
			  blastbutton.setOption("value", "3000");
			  this.directMenuInsert(event.getWavelet(), blastbutton);
			  
			  tv.setAnnotation("rid", blast.getRID() );
			  tv.setAnnotation("blastresult", "0");   
		  }
		  catch (Exception error)
		  {
			  TextView tv = event.getBlip().getDocument();
			  tv.append("ERROR:" + error.getMessage() + " \n " );
		  }
	  }
	  if (buttonLabel.contains("Blasting..."))
	  {	  
		  
		  TextView tv2 = event.getWavelet().getRootBlip().getDocument();
		  try 
		  {
			  if ( (!tv2.getAnnotations("blastresult").isEmpty()) && tv2.getAnnotations("blastresult").get(0).getValue().contentEquals("0") )
			  {	
				tv2.setAnnotation("blastresult", "1");  
				 
				BlastSearch blast = new BlastSearch();
			  	blast.setRID( tv2.getAnnotations("rid").get(0).getValue() );
			  	blast.parseResult();
			  	
			  	TextView tv = event.getWavelet().appendBlip().getDocument();
			  	tv.append(blast.waveOutput());
			  }
		  }
		  catch (SAXException error)
		  {
			  tv2.setAnnotation("blastresult", "0");
			  MenuItem blastbutton = new MenuItem("chron","Blasting...",this.generateKey());
			  blastbutton.setOption("value", "3000");
			  this.directMenuInsert(event.getWavelet(), blastbutton);
		  }
		  catch (Exception error)
		  {
			  event.getWavelet().appendBlip().getDocument().append("ERROR:" + error.getMessage() + error.getClass().getCanonicalName() + " \n ");
		  }			  
	  }
  }
 
  @Override
  public void processSbwEvents(RobotMessageBundle bundle) 
  {             

  }
}