X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fjws2%2FJabawsAlignCalcWorker.java;h=926256d5542376f03600da909a5f2ee1f23be999;hb=51f4e1c750d0de8937e69788f7b14c6120fd310f;hp=b2751c3da77bb8314b9d51db41c04ce276bdfea7;hpb=6e0002b6818844499e7ae944d859fc62d0cc351a;p=jalview.git
diff --git a/src/jalview/ws/jws2/JabawsAlignCalcWorker.java b/src/jalview/ws/jws2/JabawsAlignCalcWorker.java
index b2751c3..926256d 100644
--- a/src/jalview/ws/jws2/JabawsAlignCalcWorker.java
+++ b/src/jalview/ws/jws2/JabawsAlignCalcWorker.java
@@ -1,3 +1,20 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ */
package jalview.ws.jws2;
import jalview.analysis.AlignSeq;
@@ -6,6 +23,8 @@ import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.Annotation;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
import jalview.gui.IProgressIndicator;
@@ -16,11 +35,13 @@ import jalview.ws.params.WsParamSetI;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import compbio.data.msa.SequenceAnnotation;
import compbio.data.sequence.FastaSequence;
+import compbio.data.sequence.Score;
import compbio.data.sequence.ScoreManager;
import compbio.metadata.Argument;
import compbio.metadata.ChunkHolder;
@@ -33,6 +54,7 @@ import compbio.metadata.WrongParameterException;
public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
{
Jws2Instance service;
+
@SuppressWarnings("unchecked")
protected SequenceAnnotation aaservice;
@@ -73,10 +95,10 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
}
/**
- * reconfigure and restart the AAConsClient. This method will spawn a new
+ * reconfigure and restart the AAConClient. This method will spawn a new
* thread that will wait until any current jobs are finished, modify the
* parameters and restart the conservation calculation with the new values.
- *
+ *
* @param newpreset
* @param newarguments
*/
@@ -117,8 +139,10 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
}
long progressId = -1;
- String rslt = "JOB NOT DEFINED";
+ int serverErrorsLeft = 3;
+ String rslt = "JOB NOT DEFINED";
+ StringBuffer msg = new StringBuffer();
try
{
if (checkDone())
@@ -126,7 +150,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
return;
}
List seqs = getInputSequences(alignViewport
- .getAlignment());
+ .getAlignment(), bySequence ? alignViewport.getSelectionGroup() : null);
if (seqs == null)
{
@@ -141,7 +165,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
guiProgress.setProgressBar("JABA " + getServiceActionText(),
progressId = System.currentTimeMillis());
}
- if (preset == null && arguments==null)
+ if (preset == null && arguments == null)
{
rslt = aaservice.analize(seqs);
}
@@ -153,7 +177,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
} catch (WrongParameterException x)
{
throw new JobSubmissionException(
- "Invalid paremeter set. Check Jalview implementation.", x);
+ "Invalid parameter set. Check Jalview implementation.", x);
}
}
@@ -166,7 +190,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
{
finished = true;
}
- if (calcMan.isPending(this) && this instanceof AAConsClient)
+ if (calcMan.isPending(this) && this instanceof AAConClient)
{
finished = true;
// cancel this job and yield to the new job
@@ -178,7 +202,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
}
else
{
- System.err.println("FAILED TO CANCELL AACon job: " + rslt);
+ System.err.println("FAILED TO CANCEL AACon job: " + rslt);
}
} catch (Exception x)
@@ -189,33 +213,52 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
return;
}
long cpos;
- ChunkHolder stats;
+ ChunkHolder stats = null;
do
{
cpos = rpos;
- try
- {
- stats = aaservice.pullExecStatistics(rslt, rpos);
- } catch (Exception x)
+ boolean retry = false;
+ do
{
-
- if (x.getMessage().contains(
- "Position in a file could not be negative!"))
+ try
{
- // squash index out of bounds exception- seems to happen for
- // disorder predictors which don't (apparently) produce any
- // progress information and JABA server throws an exception
- // because progress length is -1.
- stats = null;
- }
- else
+ stats = aaservice.pullExecStatistics(rslt, rpos);
+ } catch (Exception x)
{
- throw x;
+
+ if (x.getMessage().contains(
+ "Position in a file could not be negative!"))
+ {
+ // squash index out of bounds exception- seems to happen for
+ // disorder predictors which don't (apparently) produce any
+ // progress information and JABA server throws an exception
+ // because progress length is -1.
+ stats = null;
+ }
+ else
+ {
+ if (--serverErrorsLeft > 0)
+ {
+ retry = true;
+ try
+ {
+ Thread.sleep(200);
+ } catch (InterruptedException q)
+ {
+ }
+ ;
+ }
+ else
+ {
+ throw x;
+ }
+ }
}
- }
+ } while (retry);
if (stats != null)
{
System.out.print(stats.getChunk());
+ msg.append(stats);
rpos = stats.getNextPosition();
}
} while (stats != null && rpos > cpos);
@@ -230,24 +273,33 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
}
;
}
-
} while (!finished);
- try
- {
- Thread.sleep(200);
- } catch (InterruptedException x)
+ if (serverErrorsLeft > 0)
{
+ try
+ {
+ Thread.sleep(200);
+ } catch (InterruptedException x)
+ {
+ }
+ ;
+ scoremanager = aaservice.getAnnotation(rslt);
+ if (scoremanager != null)
+ {
+ jalview.bin.Cache.log
+ .debug("Updating result annotation from Job " + rslt
+ + " at " + service.getUri());
+ updateResultAnnotation(true);
+ ap.adjustAnnotationHeight();
+ }
}
- ;
- scoremanager = aaservice.getAnnotation(rslt);
- if (scoremanager != null)
- {
- updateResultAnnotation(true);
- }
- } catch (JobSubmissionException x)
+ }
+
+ catch (JobSubmissionException x)
{
- System.err.println("submission error:");
+ System.err.println("submission error with " + getServiceActionText()
+ + " :");
x.printStackTrace();
calcMan.workerCannotRun(this);
} catch (ResultNotAvailableException x)
@@ -279,12 +331,23 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
if (ap != null)
{
calcMan.workerComplete(this);
- if (guiProgress != null && progressId!=-1)
+ if (guiProgress != null && progressId != -1)
{
guiProgress.setProgressBar("", progressId);
}
ap.paintAlignment(true);
}
+ if (msg.length() > 0)
+ {
+ // TODO: stash message somewhere in annotation or alignment view.
+ // code below shows result in a text box popup
+ /*
+ * jalview.gui.CutAndPasteTransfer cap = new
+ * jalview.gui.CutAndPasteTransfer(); cap.setText(msg.toString());
+ * jalview.gui.Desktop.addInternalFrame(cap,
+ * "Job Status for "+getServiceActionText(), 600, 400);
+ */
+ }
}
}
@@ -313,9 +376,14 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
protected boolean bySequence = false;
Map seqNames;
+
boolean[] gapMap;
+
int realw;
- public List getInputSequences(AlignmentI alignment)
+
+ int start,end;
+
+ public List getInputSequences(AlignmentI alignment, AnnotatedCollectionI inputSeqs)
{
if (alignment == null || alignment.getWidth() <= 0
|| alignment.getSequences() == null
@@ -325,6 +393,11 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
{
return null;
}
+ if (inputSeqs==null || inputSeqs.getWidth()<=0 || inputSeqs.getSequences()==null || inputSeqs.getSequences().size()<1)
+ {
+ inputSeqs = alignment;
+ }
+
List seqs = new ArrayList();
int minlen = 10;
@@ -333,10 +406,13 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
{
seqNames = new HashMap();
}
- gapMap=new boolean[0];
- for (SequenceI sq : ((List) alignment.getSequences()))
+ gapMap = new boolean[0];
+ start=inputSeqs.getStartRes();
+ end=inputSeqs.getEndRes();
+
+ for (SequenceI sq : (List) inputSeqs.getSequences())
{
- if (sq.getEnd() - sq.getStart() > minlen - 1)
+ if (sq.findPosition(end+1) -sq.findPosition(start+1) > minlen - 1)
{
String newname = SeqsetUtils.unique_name(seqs.size() + 1);
// make new input sequence with or without gaps
@@ -347,25 +423,28 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
FastaSequence seq;
if (submitGaps)
{
- seqs.add(seq = new compbio.data.sequence.FastaSequence(newname,sq.getSequenceAsString()));
- if (gapMap==null || gapMap.length ln)
{
@@ -376,7 +455,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
if (alignedSeqs && submitGaps)
{
realw = 0;
- for (int i=0;ipp)
+ if (orig.length > pp)
{
- padded[i++]=orig[pp];
- } else {
- padded[i++]='-';
- }
+ padded[i++] = orig[pp];
+ }
+ else
+ {
+ padded[i++] = '-';
+ }
}
}
seqs.set(p, new compbio.data.sequence.FastaSequence(sq.getId(),
- new String(padded)));
+ new String(padded)));
}
}
return seqs;
@@ -413,7 +495,7 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
/**
* notify manager that we have started, and wait for a free calculation slot
- *
+ *
* @return true if slot is obtained and work still valid, false if another
* thread has done our work for us.
*/
@@ -448,4 +530,112 @@ public abstract class JabawsAlignCalcWorker extends AlignCalcWorker
return false;
}
+ protected void createAnnotationRowsForScores(
+ List ourAnnot, String calcId, int alWidth,
+ Score scr)
+ {
+ // simple annotation row
+ AlignmentAnnotation annotation = alignViewport.getAlignment()
+ .findOrCreateAnnotation(scr.getMethod(), calcId, true, null,
+ null);
+ if (alWidth == gapMap.length) // scr.getScores().size())
+ {
+ constructAnnotationFromScore(annotation, 0, alWidth, scr);
+ ourAnnot.add(annotation);
+ }
+ }
+
+ protected AlignmentAnnotation createAnnotationRowsForScores(
+ List ourAnnot, String typeName,
+ String calcId, SequenceI dseq, int base, Score scr)
+ {
+ System.out.println("Creating annotation on dseq:" + dseq.getStart()
+ + " base is " + base + " and length=" + dseq.getLength()
+ + " == " + scr.getScores().size());
+ // AlignmentAnnotation annotation = new AlignmentAnnotation(
+ // scr.getMethod(), typeName, new Annotation[]
+ // {}, 0, -1, AlignmentAnnotation.LINE_GRAPH);
+ // annotation.setCalcId(calcId);
+ AlignmentAnnotation annotation = alignViewport.getAlignment()
+ .findOrCreateAnnotation(typeName, calcId, false, dseq, null);
+ constructAnnotationFromScore(annotation, 0, dseq.getLength(), scr);
+ annotation.createSequenceMapping(dseq, base, false);
+ annotation.adjustForAlignment();
+ dseq.addAlignmentAnnotation(annotation);
+ ourAnnot.add(annotation);
+ return annotation;
+ }
+
+ private void constructAnnotationFromScore(AlignmentAnnotation annotation,
+ int base, int alWidth, Score scr)
+ {
+ Annotation[] elm = new Annotation[alWidth];
+ Iterator vals = scr.getScores().iterator();
+ float m = 0f, x = 0f;
+ for (int i = 0; vals.hasNext(); i++)
+ {
+ float val = vals.next().floatValue();
+ if (i == 0)
+ {
+ m = val;
+ x = val;
+ }
+ else
+ {
+ if (m > val)
+ {
+ m = val;
+ }
+ ;
+ if (x < val)
+ {
+ x = val;
+ }
+ }
+ // if we're at a gapped column then skip to next ungapped position
+ if (gapMap != null && gapMap.length > 0)
+ {
+ while (!gapMap[i])
+ {
+ elm[i++] = new Annotation("", "", ' ', Float.NaN);
+ }
+ }
+ elm[i] = new Annotation("", "" + val, ' ', val);
+ }
+
+ annotation.annotations = elm;
+ annotation.belowAlignment = true;
+ if (x < 0)
+ {
+ x = 0;
+ }
+ x += (x - m) * 0.1;
+ annotation.graphMax = x;
+ annotation.graphMin = m;
+ annotation.validateRangeAndDisplay();
+ }
+
+ protected void updateOurAnnots(List ourAnnot)
+ {
+ List our = ourAnnots;
+ ourAnnots = ourAnnot;
+ AlignmentI alignment = alignViewport.getAlignment();
+ if (our != null)
+ {
+ if (our.size() > 0)
+ {
+ for (AlignmentAnnotation an : our)
+ {
+ if (!ourAnnots.contains(an))
+ {
+ // remove the old annotation
+ alignment.deleteAnnotation(an);
+ }
+ }
+ }
+ our.clear();
+
+ ap.adjustAnnotationHeight();
+ }
+ }
}