a88a22135275cc2e925f7909f3143c34c1469b37
[jalview.git] / src / jalview / ws / jws2 / AAConClient.java
1 package jalview.ws.jws2;
2
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.AlignmentI;
5 import jalview.gui.AlignFrame;
6 import jalview.gui.AlignmentPanel;
7 import jalview.ws.jws2.dm.AAConSettings;
8 import jalview.ws.jws2.jabaws2.Jws2Instance;
9 import jalview.ws.params.WsParamSetI;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15 import java.util.TreeSet;
16
17 import compbio.data.sequence.Score;
18 import compbio.metadata.Argument;
19
20 public class AAConClient extends JabawsAlignCalcWorker
21 {
22
23   public AAConClient(Jws2Instance service, AlignFrame alignFrame,
24           WsParamSetI preset, List<Argument> paramset)
25   {
26     super(service, alignFrame, preset, paramset);
27     submitGaps = true;
28     alignedSeqs = true;
29     nucleotidesAllowed = false;
30     proteinAllowed = true;
31     gapMap = new boolean[0];
32     initViewportParams();
33   }
34
35   protected void initViewportParams()
36   {
37     ((jalview.gui.AlignViewport) alignViewport).setCalcIdSettingsFor(
38             getCalcId(),
39             new AAConSettings(true, service, this.preset,
40                     (arguments != null) ? JabaParamStore
41                             .getJwsArgsfromJaba(arguments) : null), true);
42   }
43
44   @Override
45   public void updateParameters(WsParamSetI newpreset,
46           java.util.List<Argument> newarguments)
47   {
48     super.updateParameters(newpreset, newarguments);
49     initViewportParams();
50   };
51
52   public String getServiceActionText()
53   {
54     return "calculating Amino acid consensus using AACon service";
55   }
56
57   /**
58    * update the consensus annotation from the sequence profile data using
59    * current visualization settings.
60    */
61
62   public void updateResultAnnotation(boolean immediate)
63   {
64     if (immediate || !calcMan.isWorking(this) && scoremanager != null)
65     {
66       Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
67       int alWidth = alignViewport.getAlignment().getWidth();
68       ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
69       for (String score : scoremap.keySet())
70       {
71         Set<Score> scores = scoremap.get(score);
72         for (Score scr : scores)
73         {
74           if (scr.getRanges() != null && scr.getRanges().size() > 0)
75           {
76             /**
77              * annotation in range annotation = findOrCreate(scr.getMethod(),
78              * true, null, null); Annotation[] elm = new Annotation[alWidth];
79              * Iterator<Float> vals = scr.getScores().iterator(); for (Range rng
80              * : scr.getRanges()) { float val = vals.next().floatValue(); for
81              * (int i = rng.from; i <= rng.to; i++) { elm[i] = new
82              * Annotation("", "", ' ', val); } } annotation.annotations = elm;
83              * annotation.validateRangeAndDisplay();
84              */
85           }
86           else
87           {
88             createAnnotationRowsForScores(ourAnnot, getCalcId(), alWidth,
89                     scr);
90           }
91         }
92       }
93
94       if (ourAnnot.size() > 0)
95       {
96         updateOurAnnots(ourAnnot);
97       }
98     }
99   }
100
101   public String getCalcId()
102   {
103     return SequenceAnnotationWSClient.AAConCalcId;
104   }
105
106   public static void removeAAConsAnnotation(AlignmentPanel alignPanel)
107   {
108     for (AlignmentAnnotation aa : alignPanel.getAlignment().findAnnotation(
109             SequenceAnnotationWSClient.AAConCalcId))
110     {
111       alignPanel.getAlignment().deleteAnnotation(aa);
112     }
113   }
114 }