package jalview.io; import org.apache.axis.client.*; import javax.xml.namespace.QName; import java.util.*; import jalview.datamodel.*; import jalview.gui.*; import javax.swing.*; import java.util.*; import java.awt.*; import jalview.analysis.AlignSeq; import ext.vamsas.*; public class JPredClient { JInternalFrame outputFrame = new JInternalFrame(); CutAndPasteTransfer output = new CutAndPasteTransfer(false); int jobsRunning = 0; ext.vamsas.JpredSoapBindingStub server; public JPredClient(SequenceI seq) { output.formatForOutput(); outputFrame.setContentPane(output); output.setText("Job details for prediction on sequence :\nName : " + seq.getName() + "\nSequence : " + seq.getSequence() + "\n"); Desktop.addInternalFrame(outputFrame, "JNet secondary structure prediction job", 800, 300); JPredWSServiceLocator loc = new JPredWSServiceLocator(); // Default try { this.server = (JpredSoapBindingStub) loc.getjpred(); // JBPNote will be set from properties } catch (Exception ex) { output.setText("Serious! JPred Service location failed\nfor URL :" +loc.getjpredAddress()+"\n"+ex.getMessage()); } JPredThread jthread = new JPredThread(seq); jthread.start(); ImageTwirler thread = new ImageTwirler(); thread.start(); } class ImageTwirler extends Thread { ImageIcon[] imageIcon; int imageIndex = 0; public ImageTwirler() { imageIcon = new ImageIcon[9]; for (int i = 0; i < 9; i++) { java.net.URL url = getClass().getResource("/images/dna" + (i + 1) + ".gif"); if (url != null) imageIcon[i] = new ImageIcon(url); } } public void run() { while (jobsRunning > 0) { try { Thread.sleep(100); imageIndex++; imageIndex %= 9; outputFrame.setFrameIcon(imageIcon[imageIndex]); outputFrame.setTitle("JNet Secondary Structure Prediction : " + jobsRunning + " jobs running."); } catch (Exception ex) {} } } } class JPredThread extends Thread { String OutputHeader; ext.vamsas.Secstructpred result; ext.vamsas.Sequence sequence; String jobId; boolean jobComplete = false; int allowedServerExceptions = 3; // thread dies if too many exceptions. JPredThread(SequenceI seq) { OutputHeader = output.getText(); this.sequence = new ext.vamsas.Sequence(); this.sequence.setId(seq.getName()); this.sequence.setSeq(AlignSeq.extractGaps("-. ",seq.getSequence())); } public void run() { StartJob(); while (!jobComplete && (allowedServerExceptions > 0)) { try { result = server.getpredict(jobId); if (result.getOutput().indexOf("Job") != 0) { parseResult(); jobComplete = true; jobsRunning--; } else { output.setText(OutputHeader + "\n" + result.getOutput()); } Thread.sleep(5000); // System.out.println("I'm alive "+seqid+" "+jobid); } catch (Exception ex) { allowedServerExceptions--; String msg = output.getText(); output.setText(msg + "\nJPredWS Server exception!\n" + ex.getMessage()); } } } void StartJob() { try { jobId = server.predict(sequence); System.out.println(jobId); } catch (Exception e) { System.out.println("JPredWS Client: Failed to submit the prediction\n" + e.toString() + "\n"); e.printStackTrace(); } } void parseResult() { output.setText(OutputHeader + result.getOutput()); try { JPredFile prediction=new JPredFile(result.getOutput(), "Paste"); SequenceI[] preds = prediction.getSeqsAsArray(); int i=0; // Rename the query sequence while (i