import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
-import jalview.datamodel.Annotation;
import jalview.gui.AlignFrame;
import jalview.gui.AlignmentPanel;
import jalview.ws.jws2.dm.AAConsSettings;
import jalview.ws.params.WsParamSetI;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeSet;
import compbio.data.sequence.Score;
{
if (immediate || !calcMan.isWorking(this) && scoremanager != null)
{
- AlignmentAnnotation annotation;
Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
int alWidth = alignViewport.getAlignment().getWidth();
- AlignmentI alignment;
- int ann = (alignment = alignViewport.getAlignment())
- .getAlignmentAnnotation().length;
ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
for (String score : scoremap.keySet())
{
- TreeSet<Score> scores = scoremap.get(score);
+ Set<Score> scores = scoremap.get(score);
for (Score scr : scores)
{
if (scr.getRanges() != null && scr.getRanges().size() > 0)
}
else
{
- // simple annotation row
- annotation = alignViewport.getAlignment()
- .findOrCreateAnnotation(scr.getMethod(), getCalcId(), true,
- null, null);
-
- Annotation[] elm = new Annotation[alWidth];
- if (alWidth == gapMap.length) // scr.getScores().size())
- {
- Iterator<Float> 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();
- ourAnnot.add(annotation);
- }
+ createAnnotationRowsForScores(ourAnnot, getCalcId(), alWidth,
+ scr);
}
}
}
+
if (ourAnnot.size() > 0)
{
- List<AlignmentAnnotation> our = ourAnnots;
- ourAnnots = ourAnnot;
- if (our != null)
- {
- if (our.size() > 0)
- {
- for (AlignmentAnnotation an : our)
- {
- if (!ourAnnots.contains(an))
- {
- // remove the old annotation
- alignment.deleteAnnotation(an);
- }
- }
- }
- our.clear();
- }
- }
- // if (ann !=
- // alignViewport.getAlignment().getAlignmentAnnotation().length)
- {
- ap.adjustAnnotationHeight();
+ updateOurAnnots(ourAnnot);
}
- /*
- * else { ap.paintAlignment(true); }
- */
}
}
return false;
}
+ protected void createAnnotationRowsForScores(
+ List<AlignmentAnnotation> 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<AlignmentAnnotation> 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, base, dseq.getLength(), scr);
+ annotation.createSequenceMapping(dseq, dseq.findPosition(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<Float> vals = scr.getScores().iterator();
+ float m = 0f, x = 0f;
+ for (int i = base; 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<AlignmentAnnotation> ourAnnot)
+ {
+ List<AlignmentAnnotation> 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();
+ }
+ }
}