edit jws2 job parameters before running job
[jalview.git] / src / jalview / ws / jws2 / MsaWSThread.java
index c8c49c5..d9f92f9 100644 (file)
@@ -22,8 +22,10 @@ import java.util.*;
 import compbio.data.msa.MsaWS;
 import compbio.data.sequence.AlignmentMetadata;
 import compbio.data.sequence.Program;
+import compbio.metadata.Argument;
 import compbio.metadata.ChunkHolder;
 import compbio.metadata.JobStatus;
+import compbio.metadata.Preset;
 
 import jalview.analysis.*;
 import jalview.bin.*;
@@ -66,7 +68,8 @@ class MsaWSThread extends AWS2Thread implements WSClientI
   class MsaWSJob extends JWs2Job
   {
     long lastChunk=0;
-    
+    Preset preset=null;
+    List<Argument> arguments =  null;
     /**
      * input 
      */
@@ -344,6 +347,12 @@ class MsaWSThread extends AWS2Thread implements WSClientI
     {
       this.lastChunk = lastChunk;
     }
+
+    String alignmentProgram=null;
+    public String getAlignmentProgram()
+    {
+      return alignmentProgram;
+    }
     
   }
 
@@ -389,7 +398,7 @@ class MsaWSThread extends AWS2Thread implements WSClientI
    * @param seqset
    *          Alignment
    */
-  MsaWSThread(MsaWS server2, String wsUrl,
+  MsaWSThread(MsaWS server2, Preset preset, List<Argument> paramset, String wsUrl, 
           WebserviceInfo wsinfo, jalview.gui.AlignFrame alFrame,
           String wsname, String title, AlignmentView _msa, boolean subgaps,
           boolean presorder, Alignment seqset)
@@ -414,6 +423,9 @@ class MsaWSThread extends AWS2Thread implements WSClientI
         {
           jobs[j] = new MsaWSJob(0, conmsa[j]);
         }
+        ((MsaWSJob) jobs[j]).preset = preset;
+        ((MsaWSJob) jobs[j]).arguments = paramset;
+        ((MsaWSJob) jobs[j]).alignmentProgram = wsname;
         if (njobs > 0)
         {
           wsinfo
@@ -493,12 +505,21 @@ class MsaWSThread extends AWS2Thread implements WSClientI
   {
     // TODO: investigate if we still need to cast here in J1.6
     MsaWSJob j=((MsaWSJob) job);
+    // this is standard code, but since the interface doesn't comprise of a basic one that implements (getJobStatus, pullExecStatistics) we have to repeat the code for all jw2s services.
     j.setjobStatus(server.getJobStatus(job.getJobId()));
+    updateJobProgress(j);
+  }
+  protected void updateJobProgress(MsaWSJob j) throws Exception {
     StringBuffer response = j.jobProgress;
-    ChunkHolder chunk = server.pullExecStatistics(job.getJobId(), j.getLastChunk());
-    response.append(chunk.getChunk());
-    j.setLastChunk(chunk.getNextPosition());
-     
+    long lastchunk = j.getLastChunk();
+    do {
+      j.setLastChunk(lastchunk);
+      ChunkHolder chunk = server.pullExecStatistics(j.getJobId(), lastchunk);
+      if (chunk!=null) {
+        response.append(chunk.getChunk());
+        lastchunk = chunk.getNextPosition();
+      };
+    } while (lastchunk>=0 && j.getLastChunk()!=lastchunk);
   }
 
   public void StartJob(AWsJob job)
@@ -530,7 +551,21 @@ class MsaWSThread extends AWS2Thread implements WSClientI
     try
     {
       // TODO: get the parameters (if any) for this job and submit the job
-      j.setJobId(server.align(j.seqs));
+      if (j.arguments!=null && j.arguments.size()>0)
+      {
+        StringBuffer pset = new StringBuffer();
+        for (Argument arg: j.arguments) {
+          pset.append(arg.getName()+" "+arg.getDefaultValue()+"\n");
+        }
+        j.setStatus("Custom Parameters:\n"+pset.toString()+"\nJob Output:\n");
+        j.setJobId(server.customAlign(j.seqs, j.arguments));
+      } else
+        if (j.preset!=null)
+        {
+          j.setJobId(server.presetAlign(j.seqs, j.preset));
+        } else {
+                j.setJobId(server.align(j.seqs));
+        }
 
       if (j.getJobId()!= null)
       {
@@ -553,8 +588,8 @@ class MsaWSThread extends AWS2Thread implements WSClientI
       System.err
               .println(WebServiceName
                       + "Client: Failed to submit the sequences for alignment (probably a server side problem)\n"
-                      + "When contacting Server:" + WsUrl + "\n"
-                      + e.toString() + "\n");
+                      + "When contacting Server:" + WsUrl + "\n");
+      e.printStackTrace(System.err);
       j.setAllowedServerExceptions(0);
       wsInfo.setStatus(WebserviceInfo.STATE_STOPPED_SERVERERROR);
       wsInfo.setStatus(j.getJobnum(), WebserviceInfo.STATE_STOPPED_SERVERERROR);
@@ -582,6 +617,20 @@ class MsaWSThread extends AWS2Thread implements WSClientI
         if (jobs[j].isFinished() && msjob.alignment==null)
         {
           try {
+            updateJobProgress(msjob);
+          } catch (Exception e)
+          {
+            Cache.log.warn("Exception when retrieving remaining Job progress data for job "+msjob.getJobId()+" on server "+WsUrl);
+            e.printStackTrace();
+          }
+          if (Cache.log.isDebugEnabled())
+          {
+            System.out.println("Job Execution file for job: "+msjob.getJobId()+" on server "+WsUrl);
+            System.out.println(msjob.getStatus());
+            System.out.println("*** End of status");
+            
+          }
+          try {
             msjob.alignment = server.getResult(msjob.getJobId());
           }
           catch (Exception e)
@@ -653,7 +702,7 @@ class MsaWSThread extends AWS2Thread implements WSClientI
       {
         msjob = (MsaWSJob)jobs[j];
         Object[] res = msjob.getAlignment();
-        lastProgram = msjob.alignment.getMetadata().getProgram().name();
+        lastProgram = msjob.getAlignmentProgram();
         alorders.add(res[1]);
         results[j] = (SequenceI[]) res[0];
         orders[j] = (AlignmentOrder) res[1];