From: jprocter Date: Tue, 28 Aug 2012 13:14:19 +0000 (+0100) Subject: JAL-974 refactored creation of Annotation rows from JABAWS2 services for use by disor... X-Git-Tag: Jalview_2_9~388 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9d2dcf98b8a7a97f9f57afe8e93a484bb4205824;p=jalview.git JAL-974 refactored creation of Annotation rows from JABAWS2 services for use by disorder client --- diff --git a/src/jalview/ws/jws2/AAConsClient.java b/src/jalview/ws/jws2/AAConsClient.java index d1bf303..42a7bdb 100644 --- a/src/jalview/ws/jws2/AAConsClient.java +++ b/src/jalview/ws/jws2/AAConsClient.java @@ -2,7 +2,6 @@ package jalview.ws.jws2; 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; @@ -10,9 +9,9 @@ import jalview.ws.jws2.jabaws2.Jws2Instance; 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; @@ -56,16 +55,12 @@ public class AAConsClient extends JabawsAlignCalcWorker { if (immediate || !calcMan.isWorking(this) && scoremanager != null) { - AlignmentAnnotation annotation; Map> scoremap = scoremanager.asMap(); int alWidth = alignViewport.getAlignment().getWidth(); - AlignmentI alignment; - int ann = (alignment = alignViewport.getAlignment()) - .getAlignmentAnnotation().length; ArrayList ourAnnot = new ArrayList(); for (String score : scoremap.keySet()) { - TreeSet scores = scoremap.get(score); + Set scores = scoremap.get(score); for (Score scr : scores) { if (scr.getRanges() != null && scr.getRanges().size() > 0) @@ -82,90 +77,16 @@ public class AAConsClient extends JabawsAlignCalcWorker } 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 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 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); } - */ } } diff --git a/src/jalview/ws/jws2/JabawsAlignCalcWorker.java b/src/jalview/ws/jws2/JabawsAlignCalcWorker.java index 1d23ec0..d8807e7 100644 --- a/src/jalview/ws/jws2/JabawsAlignCalcWorker.java +++ b/src/jalview/ws/jws2/JabawsAlignCalcWorker.java @@ -487,4 +487,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, 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 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 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(); + } + } }