2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.rest;
23 import java.util.Locale;
25 import jalview.bin.Cache;
26 import jalview.datamodel.Alignment;
27 import jalview.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.AlignmentOrder;
30 import jalview.datamodel.Annotation;
31 import jalview.datamodel.HiddenColumns;
32 import jalview.datamodel.SequenceGroup;
33 import jalview.datamodel.SequenceI;
34 import jalview.gui.AlignFrame;
35 import jalview.gui.Desktop;
36 import jalview.gui.PaintRefresher;
37 import jalview.gui.WebserviceInfo;
38 import jalview.io.NewickFile;
39 import jalview.io.packed.JalviewDataset;
40 import jalview.io.packed.JalviewDataset.AlignmentSet;
41 import jalview.util.MessageManager;
42 import jalview.ws.AWSThread;
43 import jalview.ws.AWsJob;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.io.IOException;
48 import java.util.ArrayList;
49 import java.util.Hashtable;
50 import java.util.List;
51 import java.util.Map.Entry;
53 import org.apache.axis.transport.http.HTTPConstants;
54 import org.apache.http.Header;
55 import org.apache.http.HttpEntity;
56 import org.apache.http.HttpResponse;
57 import org.apache.http.client.ClientProtocolException;
58 import org.apache.http.client.methods.HttpGet;
59 import org.apache.http.client.methods.HttpPost;
60 import org.apache.http.client.methods.HttpRequestBase;
61 import org.apache.http.entity.mime.HttpMultipartMode;
62 import org.apache.http.entity.mime.MultipartEntity;
63 import org.apache.http.impl.client.DefaultHttpClient;
64 import org.apache.http.protocol.BasicHttpContext;
65 import org.apache.http.protocol.HttpContext;
66 import org.apache.http.util.EntityUtils;
68 public class RestJobThread extends AWSThread
75 protected RestClient restClient;
77 public RestJobThread(RestClient restClient)
79 super(restClient.af, null, restClient._input,
80 restClient.service.postUrl);
81 this.restClient = restClient; // may not be needed
83 // minimal job - submit given input and parse result onto alignment as
84 // annotation/whatever
86 // look for tree data, etc.
88 // for moment do following job type only
89 // input=visiblealignment,groupsindex
90 // ie one subjob using groups defined on alignment.
91 if (!restClient.service.isHseparable())
93 jobs = new RestJob[1];
94 jobs[0] = new RestJob(0, this,
95 restClient._input.getVisibleAlignment(
96 restClient.service.getGapCharacter()),
97 restClient._input.getVisibleContigs());
98 // need a function to get a range on a view/alignment and return both
99 // annotation, groups and selection subsetted to just that region.
104 int[] viscontig = restClient._input.getVisibleContigs();
105 AlignmentI[] viscontigals = restClient._input
106 .getVisibleContigAlignments(
107 restClient.service.getGapCharacter());
108 if (viscontigals != null && viscontigals.length > 0)
110 jobs = new RestJob[viscontigals.length];
111 for (int j = 0; j < jobs.length; j++)
113 int[] visc = new int[] { viscontig[j * 2], viscontig[j * 2 + 1] };
116 jobs[j] = new RestJob(j, this, viscontigals[j], visc);
120 jobs[j] = new RestJob(0, this, viscontigals[j], visc);
127 * subjob types row based: per sequence in alignment/selected region { input
128 * is one sequence or sequence ID } per alignment/selected region { input is
129 * set of sequences, alignment, one or more sets of sequence IDs,
132 if (!restClient.service.isHseparable())
135 // create a bunch of subjobs per visible contig to ensure result honours
137 // TODO: determine if a 'soft' hSeperable property is needed - e.g. if
138 // user does SS-pred on sequence with big hidden regions, its going to be
143 // create a single subjob for the visible/selected input
146 // TODO: decide if vSeperable exists: eg. column wide analysis where hidden
147 // rows do not affect output - generally no analysis that generates
148 // alignment annotation is vSeparable -
152 * create gui components for monitoring jobs
154 * @param webserviceInfo
156 public void setWebServiceInfo(WebserviceInfo webserviceInfo)
158 wsInfo = webserviceInfo;
159 for (int j = 0; j < jobs.length; j++)
162 // Copy over any per job params
165 wsInfo.setProgressName("region " + jobs[j].getJobnum(),
166 jobs[j].getJobnum());
170 wsInfo.setProgressText(jobs[j].getJobnum(), OutputHeader);
175 private String getStage(Stage stg)
177 if (stg == Stage.SUBMIT)
179 return "submitting ";
181 if (stg == Stage.POLL)
183 return "checking status of ";
186 return (" being confused about ");
189 private void doPoll(RestJob rj) throws Exception
191 String postUrl = rj.getPollUrl();
192 doHttpReq(Stage.POLL, rj, postUrl);
196 * construct the post and handle the response.
200 public void doPost(RestJob rj) throws Exception
202 String postUrl = rj.getPostUrl();
203 doHttpReq(Stage.SUBMIT, rj, postUrl);
208 * do the HTTP request - and respond/set statuses appropriate to the current
213 * - provides any data needed for posting and used to record state
215 * - actual URL to post/get from
218 protected void doHttpReq(Stage stg, RestJob rj, String postUrl)
221 StringBuffer respText = new StringBuffer();
222 // con.setContentHandlerFactory(new
223 // jalview.ws.io.mime.HttpContentHandler());
224 HttpRequestBase request = null;
225 String messages = "";
226 if (stg == Stage.SUBMIT)
229 // http://evgenyg.wordpress.com/2010/05/01/uploading-files-multipart-post-apache/
231 HttpPost htpost = new HttpPost(postUrl);
232 MultipartEntity postentity = new MultipartEntity(
233 HttpMultipartMode.STRICT);
234 for (Entry<String, InputType> input : rj.getInputParams())
236 if (input.getValue().validFor(rj))
238 postentity.addPart(input.getKey(),
239 input.getValue().formatForInput(rj));
243 messages += "Skipped an input (" + input.getKey()
244 + ") - Couldn't generate it from available data.";
247 htpost.setEntity(postentity);
252 request = new HttpGet(postUrl);
256 DefaultHttpClient httpclient = new DefaultHttpClient();
258 HttpContext localContext = new BasicHttpContext();
259 HttpResponse response = null;
262 response = httpclient.execute(request);
263 } catch (ClientProtocolException he)
265 rj.statMessage = "Web Protocol Exception when " + getStage(stg)
266 + "Job. <br>Problematic url was <a href=\""
267 + request.getURI() + "\">" + request.getURI()
268 + "</a><br>See Console output for details.";
269 rj.setAllowedServerExceptions(0);// unrecoverable;
271 Cache.log.fatal("Unexpected REST Job " + getStage(stg)
272 + "exception for URL " + rj.rsd.postUrl);
274 } catch (IOException e)
276 rj.statMessage = "IO Exception when " + getStage(stg)
277 + "Job. <br>Problematic url was <a href=\""
278 + request.getURI() + "\">" + request.getURI()
279 + "</a><br>See Console output for details.";
280 Cache.log.warn("IO Exception for REST Job " + getStage(stg)
281 + "exception for URL " + rj.rsd.postUrl);
285 switch (response.getStatusLine().getStatusCode())
289 Cache.log.debug("Processing result set.");
290 processResultSet(rj, response, request);
293 rj.statMessage = "<br>Job submitted successfully. Results available at this URL:\n"
294 + "<a href=" + rj.getJobId() + "\">" + rj.getJobId()
300 if (!rj.isSubmitted()
302 .getHeaders(HTTPConstants.HEADER_LOCATION)) != null
307 Cache.log.warn("Ignoring additional " + (loc.length - 1)
308 + " location(s) provided in response header ( next one is '"
309 + loc[1].getValue() + "' )");
311 rj.setJobId(loc[0].getValue());
312 rj.setSubmitted(true);
314 completeStatus(rj, response);
318 rj.setSubmitted(true);
319 rj.setAllowedServerExceptions(0);
320 rj.setSubjobComplete(true);
323 completeStatus(rj, response,
324 "" + getStage(stg) + "failed. Reason below:\n");
327 // Some other response. Probably need to pop up the content in a window.
328 // TODO: deal with all other HTTP response codes from server.
329 Cache.log.warn("Unhandled response status when " + getStage(stg)
330 + "for " + postUrl + ": " + response.getStatusLine());
332 rj.setAllowedServerExceptions(0);
333 rj.setSubjobComplete(true);
334 rj.setSubmitted(true);
337 completeStatus(rj, response, "" + getStage(stg)
338 + " resulted in an unexpected server response.<br/>Url concerned was <a href=\""
339 + request.getURI() + "\">" + request.getURI()
340 + "</a><br/>Filtered response content below:<br/>");
341 } catch (IOException e)
343 Cache.log.debug("IOException when consuming unhandled response",
352 * job has completed. Something valid should be available from con
357 * is a stateless request - expected to return the same data
358 * regardless of how many times its called.
360 private void processResultSet(RestJob rj, HttpResponse con,
363 if (rj.statMessage == null)
367 rj.statMessage += "Job Complete.\n";
370 rj.resSet = new HttpResultSet(rj, con, req);
372 } catch (IOException e)
374 rj.statMessage += "Couldn't parse results. Failed.";
376 rj.gotresult = false;
380 private void completeStatus(RestJob rj, HttpResponse con)
383 completeStatus(rj, con, null);
387 private void completeStatus(RestJob rj, HttpResponse con, String prefix)
390 StringBuffer sb = new StringBuffer();
396 if (rj.statMessage != null && rj.statMessage.length() > 0)
398 sb.append(rj.statMessage);
400 HttpEntity en = con.getEntity();
402 * Just append the content as a string.
405 StringBuffer content = new StringBuffer(f = EntityUtils.toString(en));
406 f = f.toLowerCase(Locale.ROOT);
407 int body = f.indexOf("<body");
410 content.delete(0, f.indexOf(">", body) + 1);
412 if (body > -1 && sb.length() > 0)
415 content.insert(0, sb);
419 rj.statMessage = content.toString();
423 public void pollJob(AWsJob job) throws Exception
425 assert (job instanceof RestJob);
426 System.err.println("Debug RestJob: Polling Job");
427 doPoll((RestJob) job);
431 public void StartJob(AWsJob job)
433 assert (job instanceof RestJob);
436 System.err.println("Debug RestJob: Posting Job");
437 doPost((RestJob) job);
438 } catch (NoValidInputDataException erex)
440 job.setSubjobComplete(true);
441 job.setSubmitted(true);
442 ((RestJob) job).statMessage = "<br>It looks like there was a problem with the data sent to the service :<br>"
443 + erex.getMessage() + "\n";
444 ((RestJob) job).error = true;
446 } catch (Exception ex)
448 job.setSubjobComplete(true);
449 job.setAllowedServerExceptions(-1);
450 Cache.log.error("Exception when trying to start Rest Job.", ex);
455 public void parseResult()
457 // crazy users will see this message
458 // TODO: finish this! and remove the message below!
459 Cache.log.warn("Rest job result parser is currently INCOMPLETE!");
461 for (RestJob rj : (RestJob[]) jobs)
463 if (rj.hasResponse() && rj.resSet != null && rj.resSet.isValid())
468 Cache.log.debug("Parsing data for job " + rj.getJobId());
474 Cache.log.debug("Finished parsing data for job " + rj.getJobId());
479 "Failed to finish parsing data for job " + rj.getJobId());
480 ex.printStackTrace();
481 } catch (Exception ex)
484 "Failed to finish parsing data for job " + rj.getJobId());
485 ex.printStackTrace();
489 rj.statMessage = "Error whilst parsing data for this job.<br>URL for job response is :<a href=\""
490 + rj.resSet.getUrl() + "\">" + rj.resSet.getUrl()
497 // add listeners and activate result display gui elements
499 * decisions based on job result content + state of alignFrame that
500 * originated the job:
503 * 1. Can/Should this job automatically open a new window for results
507 // preserver current jalview behaviour
508 wsInfo.setViewResultsImmediatly(true);
512 // realiseResults(true, true);
514 // otherwise, should automatically view results
516 // TODO: check if at least one or more contexts are valid - if so, enable
518 wsInfo.showResultsNewFrame.addActionListener(new ActionListener()
522 public void actionPerformed(ActionEvent e)
524 realiseResults(false);
528 wsInfo.mergeResults.addActionListener(new ActionListener()
532 public void actionPerformed(ActionEvent e)
534 realiseResults(true);
539 wsInfo.setResultsReady();
543 // tell the user nothing was returned.
544 wsInfo.setStatus(wsInfo.STATE_STOPPED_ERROR);
545 wsInfo.setFinishedNoResults();
550 * instructions for whether to create new alignment view on current alignment
551 * set, add to current set, or create new alignFrame
553 private enum AddDataTo
556 * add annotation, trees etc to current view
560 * create a new view derived from current view and add data to that
564 * create a new alignment frame for the result set and add annotation to
570 public void realiseResults(boolean merge)
573 * 2. Should the job modify the parent alignment frame/view(s) (if they
574 * still exist and the alignment hasn't been edited) in order to display new
575 * annotation/features.
578 * alignment panels derived from each alignment set returned by service.
580 ArrayList<jalview.gui.AlignmentPanel> destPanels = new ArrayList<jalview.gui.AlignmentPanel>();
582 * list of instructions for how to process each distinct alignment set
583 * returned by the job set
585 ArrayList<AddDataTo> resultDest = new ArrayList<AddDataTo>();
587 * when false, zeroth pane is panel derived from input deta.
589 boolean newAlignment = false;
591 * gap character to be used for alignment reconstruction
593 char gapCharacter = restClient.av.getGapCharacter();
594 // Now, iterate over all alignment sets returned from all jobs:
595 // first inspect jobs and collate results data in order to count alignments
597 // then assemble results from decomposed (v followed by h-separated) jobs
598 // finally, new views and alignments will be created and displayed as
600 boolean hsepjobs = restClient.service.isHseparable();
601 boolean vsepjobs = restClient.service.isVseparable();
602 // total number of distinct alignment sets generated by job set.
603 int numAlSets = 0, als = 0;
604 List<AlignmentI> destAls = new ArrayList<AlignmentI>();
605 List<jalview.datamodel.HiddenColumns> destColsel = new ArrayList<jalview.datamodel.HiddenColumns>();
606 List<List<NewickFile>> trees = new ArrayList<List<NewickFile>>();
611 // iterate over each alignment set returned from each subjob. Treating
612 // each one returned in parallel with others.
613 // Result collation arrays
616 * mapping between index of sequence in alignment that was submitted to
617 * server and index of sequence in the input alignment
619 int[][] ordermap = new int[jobs.length][];
620 SequenceI[][] rseqs = new SequenceI[jobs.length][];
621 AlignmentOrder[] orders = new AlignmentOrder[jobs.length];
622 AlignmentAnnotation[][] alan = new AlignmentAnnotation[jobs.length][];
623 SequenceGroup[][] sgrp = new SequenceGroup[jobs.length][];
624 // Now collect all data for alignment Set als from job array
625 for (int j = 0; j < jobs.length; j++)
627 RestJob rj = (RestJob) jobs[j];
630 JalviewDataset rset = rj.context;
631 if (rset.hasAlignments())
633 if (numAlSets < rset.getAl().size())
635 numAlSets = rset.getAl().size();
637 if (als < rset.getAl().size()
638 && rset.getAl().get(als).isModified())
640 // Collate result data
641 // TODO: decide if all alignmentI should be collected rather than
642 // specific alignment data containers
643 // for moment, we just extract content, but this means any
644 // alignment properties may be lost.
645 AlignmentSet alset = rset.getAl().get(als);
646 alan[j] = alset.al.getAlignmentAnnotation();
647 if (alset.al.getGroups() != null)
649 sgrp[j] = new SequenceGroup[alset.al.getGroups().size()];
650 alset.al.getGroups().toArray(sgrp[j]);
656 orders[j] = new AlignmentOrder(alset.al);
657 rseqs[j] = alset.al.getSequencesArray();
658 ordermap[j] = rj.getOrderMap();
659 // if (rj.isInputUniquified()) {
660 // jalview.analysis.AlignmentSorter.recoverOrder(rseqs[als]);
663 if (alset.trees != null)
665 trees.add(new ArrayList<NewickFile>(alset.trees));
669 trees.add(new ArrayList<NewickFile>());
675 // Now aggregate and present results from this frame of alignment data.
676 int nvertsep = 0, nvertseps = 1;
679 // Jobs relate to different rows of input alignment.
680 // Jobs are subdivided by rows before columns,
681 // so there will now be a number of subjobs according tohsep for each
683 // TODO: get vertical separation intervals for each job and set
685 // TODO: merge data from each group/sequence onto whole
689 * index into rest jobs subdivided vertically
692 // Destination alignments for all result data.
693 ArrayList<SequenceGroup> visgrps = new ArrayList<SequenceGroup>();
694 Hashtable<String, SequenceGroup> groupNames = new Hashtable<String, SequenceGroup>();
695 ArrayList<AlignmentAnnotation> visAlAn = null;
696 for (nvertsep = 0; nvertsep < nvertseps; nvertsep++)
698 // TODO: set scope w.r.t. original alignment view for vertical
701 // results for a job exclude hidden columns of input data, so map
702 // back on to all visible regions
704 * rest job result we are working with
708 RestJob rj = (RestJob) jobs[nrj];
709 int contigs[] = input.getVisibleContigs();
710 AlignmentI destAl = null;
711 jalview.datamodel.HiddenColumns destHCs = null;
712 // Resolve destAl for this data.
713 if (als == 0 && rj.isInputContextModified())
715 // special case: transfer features, annotation, groups, etc,
717 // context to align panel derived from input data
718 if (destAls.size() > als)
720 destAl = destAls.get(als);
724 if (!restClient.isAlignmentModified() && merge)
726 destAl = restClient.av.getAlignment();
727 destHCs = restClient.av.getAlignment().getHiddenColumns();
728 resultDest.add(restClient.isShowResultsInNewView()
730 : AddDataTo.currentView);
731 destPanels.add(restClient.recoverAlignPanelForView());
736 // recreate the input alignment data
737 Object[] idat = input
738 .getAlignmentAndHiddenColumns(gapCharacter);
739 destAl = new Alignment((SequenceI[]) idat[0]);
740 destHCs = (HiddenColumns) idat[1];
741 resultDest.add(AddDataTo.newAlignment);
742 // but do not add to the alignment panel list - since we need to
743 // create a whole new alignFrame set.
746 destColsel.add(destHCs);
751 // alignment(s) returned by service is to be re-integrated and
753 if (destAls.size() > als)
757 // TODO: decide if multiple multiple alignments returned by
758 // non-vseparable services are allowed.
760 "dealing with multiple alignment products returned by non-vertically separable service.");
762 // recover reference to last alignment created for this rest frame
763 // ready for extension
764 destAl = destAls.get(als);
765 destHCs = destColsel.get(als);
773 // single alignment for any job that gets mapped back on to
774 // input data. Reconstruct by interleaving parts of returned
775 // alignment with hidden parts of input data.
776 SequenceI[][] nsq = splitSeqsOnVisibleContigs(rseqs[nrj],
777 contigs, gapCharacter);
778 AlignmentOrder alo[] = new AlignmentOrder[nsq.length];
779 for (int no = 0; no < alo.length; no++)
781 alo[no] = new AlignmentOrder(orders[nrj].getOrder());
783 newview = input.getUpdatedView(nsq, orders, gapCharacter);
787 // each job maps to a single visible contig, and all need to be
788 // stitched back together.
789 // reconstruct using sub-region based MSA alignment construction
791 newview = input.getUpdatedView(rseqs, orders, gapCharacter);
793 destAl = new Alignment((SequenceI[]) newview[0]);
794 destHCs = (HiddenColumns) newview[1];
796 // TODO create alignment from result data with propagated
799 destColsel.add(destHCs);
800 resultDest.add(AddDataTo.newAlignment);
802 MessageManager.getString("error.implementation_error")
807 * save initial job in this set in case alignment is h-separable
811 for (int ncnt = 0; ncnt < contigs.length; ncnt += 2)
815 // single alignment for any job that gets mapped back on to input
820 // each job maps to a single visible contig, and all need to be
821 // stitched back together.
826 // TODO: apply options for group merging and annotation merging.
827 // If merging not supported, then either clear hashtables now or
828 // use them to rename the new annotation/groups for each contig if
829 // a conflict occurs.
831 if (sgrp[nrj] != null)
833 for (SequenceGroup sg : sgrp[nrj])
835 boolean recovered = false;
836 SequenceGroup exsg = null;
837 if (sg.getName() != null)
839 exsg = groupNames.get(sg.getName());
843 exsg = new SequenceGroup(sg);
844 groupNames.put(exsg.getName(), exsg);
846 exsg.setStartRes(sg.getStartRes() + contigs[ncnt]);
847 exsg.setEndRes(sg.getEndRes() + contigs[ncnt]);
853 // now replace any references from the result set with
854 // corresponding refs from alignment input set.
856 // TODO: cope with recovering hidden sequences from
859 for (SequenceI oseq : sg.getSequences(null))
861 SequenceI nseq = getNewSeq(oseq, rseqs[nrj],
862 ordermap[nrj], destAl);
867 exsg.deleteSequence(oseq, false);
869 exsg.addSequence(nseq, false);
874 "Couldn't resolve original sequence for new sequence.");
879 if (exsg.getSeqrep() == sg.getSeqrep())
881 // lift over sequence rep reference too
882 SequenceI oseq = sg.getSeqrep();
883 SequenceI nseq = getNewSeq(oseq, rseqs[nrj],
884 ordermap[nrj], destAl);
887 exsg.setSeqrep(nseq);
894 // adjust boundaries of recovered group w.r.t. new group being
895 // merged on to original alignment.
896 int start = sg.getStartRes() + contigs[ncnt],
897 end = sg.getEndRes() + contigs[ncnt];
898 if (start < exsg.getStartRes())
900 exsg.setStartRes(start);
902 if (end > exsg.getEndRes())
912 // and finally add in annotation and any trees for each job
913 for (int ncnt = 0; ncnt < contigs.length; ncnt += 2)
917 // single alignment for any job that gets mapped back on to input
922 // each job maps to a single visible contig, and all need to be
923 // stitched back together.
930 // merge alignmentAnnotation into one row
931 if (alan[nrj] != null)
933 for (int an = 0; an < alan[nrj].length; an++)
935 SequenceI sqass = null;
936 SequenceGroup grass = null;
937 if (alan[nrj][an].sequenceRef != null)
939 // TODO: ensure this relocates sequence reference to local
941 sqass = getNewSeq(alan[nrj][an].sequenceRef, rseqs[nrj],
942 ordermap[nrj], destAl);
944 if (alan[nrj][an].groupRef != null)
946 // TODO: verify relocate group reference to local context
948 grass = groupNames.get(alan[nrj][an].groupRef.getName());
952 "Couldn't relocate group referemce for group "
953 + alan[nrj][an].groupRef.getName());
958 visAlAn = new ArrayList<AlignmentAnnotation>();
960 AlignmentAnnotation visan = null;
961 for (AlignmentAnnotation v : visAlAn)
964 && v.label.equals(alan[nrj][an].label))
971 visan = new AlignmentAnnotation(alan[nrj][an]);
972 // copy annotations, and wipe out/update refs.
973 visan.annotations = new Annotation[input.getWidth()];
974 visan.groupRef = grass;
975 visan.sequenceRef = sqass;
979 + alan[nrj][an].annotations.length > visan.annotations.length)
981 // increase width of annotation row
982 Annotation[] newannv = new Annotation[contigs[ncnt]
983 + alan[nrj][an].annotations.length];
984 System.arraycopy(visan.annotations, 0, newannv, 0,
985 visan.annotations.length);
986 visan.annotations = newannv;
988 // now copy local annotation data into correct position
989 System.arraycopy(alan[nrj][an].annotations, 0,
990 visan.annotations, contigs[ncnt],
991 alan[nrj][an].annotations.length);
996 if (trees.get(nrj).size() > 0)
998 for (NewickFile nf : trees.get(nrj))
1000 // TODO: process each newick file, lifting over sequence refs to
1001 // current alignment, if necessary.
1003 "Tree recovery from restjob not yet implemented.");
1008 } // end of vseps loops.
1009 if (visAlAn != null)
1011 for (AlignmentAnnotation v : visAlAn)
1013 destAls.get(als).addAnnotation(v);
1016 if (visgrps != null)
1018 for (SequenceGroup sg : visgrps)
1020 destAls.get(als).addGroup(sg);
1023 } while (++als < numAlSets);
1024 // Finally, assemble each new alignment, and create new gui components to
1027 * current AlignFrame where results will go.
1029 AlignFrame destaf = restClient.recoverAlignFrameForView();
1031 * current pane being worked with
1033 jalview.gui.AlignmentPanel destPanel = restClient
1034 .recoverAlignPanelForView();
1036 for (AddDataTo action : resultDest)
1039 HiddenColumns destcs;
1040 String alTitle = MessageManager
1041 .formatMessage("label.webservice_job_title_on", new String[]
1042 { restClient.service.details.Action,
1043 restClient.service.details.Name, restClient.viewTitle });
1047 destal = destAls.get(als);
1048 destcs = destColsel.get(als);
1049 destaf = new AlignFrame(destal, destcs, AlignFrame.DEFAULT_WIDTH,
1050 AlignFrame.DEFAULT_HEIGHT);
1051 PaintRefresher.Refresh(destaf,
1052 destaf.getViewport().getSequenceSetId());
1053 // todo transfer any feature settings and colouring
1055 * destaf.getFeatureRenderer().transferSettings(this.featureSettings);
1056 * // update orders if (alorders.size() > 0) { if (alorders.size() == 1)
1057 * { af.addSortByOrderMenuItem(WebServiceName + " Ordering",
1058 * (AlignmentOrder) alorders.get(0)); } else { // construct a
1059 * non-redundant ordering set Vector names = new Vector(); for (int i =
1060 * 0, l = alorders.size(); i < l; i++) { String orderName = new
1061 * String(" Region " + i); int j = i + 1;
1063 * while (j < l) { if (((AlignmentOrder) alorders.get(i))
1064 * .equals(((AlignmentOrder) alorders.get(j)))) { alorders.remove(j);
1065 * l--; orderName += "," + j; } else { j++; } }
1067 * if (i == 0 && j == 1) { names.add(new String("")); } else {
1068 * names.add(orderName); } } for (int i = 0, l = alorders.size(); i < l;
1069 * i++) { af.addSortByOrderMenuItem( WebServiceName + ((String)
1070 * names.get(i)) + " Ordering", (AlignmentOrder) alorders.get(i)); } } }
1072 // TODO: modify this and previous alignment's title if many alignments
1073 // have been returned.
1074 Desktop.addInternalFrame(destaf, alTitle, AlignFrame.DEFAULT_WIDTH,
1075 AlignFrame.DEFAULT_HEIGHT);
1079 // TODO: determine title for view
1087 if (restClient.isShowResultsInNewView())
1089 // destPanel = destPanel.alignFrame.newView(false);
1097 * if (als) // add the destination panel to frame zero of result panel set }
1098 * } if (destPanels.size()==0) { AlignFrame af = new AlignFrame((AlignmentI)
1099 * idat[0], (ColumnSelection) idat[1], AlignFrame.DEFAULT_WIDTH,
1100 * AlignFrame.DEFAULT_HEIGHT);
1102 * jalview.gui.Desktop.addInternalFrame(af, "Results for " +
1103 * restClient.service.details.Name + " " + restClient.service.details.Action
1104 * + " on " + restClient.af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1105 * AlignFrame.DEFAULT_HEIGHT); destPanel = af.alignPanel; // create totally
1106 * new alignment from stashed data/results
1113 * alignments. New alignments are added to dataset, and subsequently
1114 * annotated/visualised accordingly. 1. New alignment frame created for new
1115 * alignment. Decide if any vis settings should be inherited from old
1116 * alignment frame (e.g. sequence ordering ?). 2. Subsequent data added to
1117 * alignment as below:
1120 * annotation update to original/newly created context alignment: 1.
1121 * identify alignment where annotation is to be loaded onto. 2. Add
1122 * annotation, excluding any duplicates. 3. Ensure annotation is visible on
1123 * alignment - honouring ordering given by file.
1126 * features updated to original or newly created context alignment: 1.
1127 * Features are(or were already) added to dataset. 2. Feature settings
1128 * modified to ensure all features are displayed - honouring any ordering
1129 * given by result file. Consider merging action with the code used by the
1130 * DAS fetcher to update alignment views with new info.
1133 * Seq associated data files (PDB files). 1. locate seq association in
1134 * current dataset/alignment context and add file as normal - keep handle of
1135 * any created ref objects. 2. decide if new data should be displayed : PDB
1136 * display: if alignment has PDB display already, should new pdb files be
1140 // destPanel.adjustAnnotationHeight();
1145 * split the given array of sequences into blocks of subsequences
1146 * corresponding to each visible contig
1151 * padding character for ragged ends of visible contig region.
1154 private SequenceI[][] splitSeqsOnVisibleContigs(SequenceI[] sequenceIs,
1155 int[] contigs, char gapChar)
1157 int nvc = contigs == null ? 1 : contigs.length / 2;
1158 SequenceI[][] blocks = new SequenceI[nvc][];
1159 if (contigs == null)
1161 blocks[0] = new SequenceI[sequenceIs.length];
1162 System.arraycopy(sequenceIs, 0, blocks[0], 0, sequenceIs.length);
1166 // deja vu - have I written this before ?? propagateGaps does this in a
1168 char[] gapset = null;
1169 int start = 0, width = 0;
1170 for (int c = 0; c < nvc; c++)
1172 width = contigs[c * 2 + 1] - contigs[c * 2] + 1;
1173 for (int s = 0; s < sequenceIs.length; s++)
1175 int end = sequenceIs[s].getLength();
1178 if (start + width < end)
1180 blocks[c][s] = sequenceIs[s].getSubSequence(start,
1185 blocks[c][s] = sequenceIs[s].getSubSequence(start, end);
1186 String sq = blocks[c][s].getSequenceAsString();
1187 for (int n = start + width; n > end; n--)
1195 if (gapset == null || gapset.length < width)
1197 char ng[] = new char[width];
1201 System.arraycopy(gapset, 0, ng, 0, gs = gapset.length);
1203 while (gs < ng.length)
1208 blocks[c][s] = sequenceIs[s].getSubSequence(end, end);
1209 blocks[c][s].setSequence(gapset.toString().substring(0, width));
1214 // adjust window for next visible segnment
1215 start += contigs[c * 2 + 1] - contigs[c * 2];
1223 * recover corresponding sequence from original input data corresponding to
1224 * sequence in a specific job's input data.
1232 private SequenceI getNewSeq(SequenceI oseq, SequenceI[] sequenceIs,
1233 int[] is, AlignmentI destAl)
1236 while (p < sequenceIs.length && sequenceIs[p] != oseq)
1240 if (p < sequenceIs.length && p < destAl.getHeight())
1242 return destAl.getSequenceAt(is[p]);
1249 * @return true if the run method is safe to call
1251 public boolean isValid()
1253 ArrayList<String> _warnings = new ArrayList<String>();
1254 boolean validt = true;
1257 for (RestJob rj : (RestJob[]) jobs)
1259 if (!rj.hasValidInput())
1261 // invalid input for this job
1262 System.err.println("Job " + rj.getJobnum()
1263 + " has invalid input. ( " + rj.getStatus() + ")");
1264 if (rj.hasStatus() && !_warnings.contains(rj.getStatus()))
1266 _warnings.add(rj.getStatus());
1275 for (String st : _warnings)
1277 if (warnings.length() > 0)
1288 protected String warnings;
1290 public boolean hasWarnings()
1292 // TODO Auto-generated method stub
1293 return warnings != null && warnings.length() > 0;
1297 * get any informative messages about why the job thread couldn't start.
1301 public String getWarnings()
1303 return isValid() ? "Job can be started. No warnings."
1304 : hasWarnings() ? warnings : "";