JAL-1365 use AlignAnalysisUIText class to provide metadata for a service's UI elements
[jalview.git] / src / jalview / ws / jws2 / AAConClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
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 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.ws.jws2;
19
20 import jalview.datamodel.AlignmentAnnotation;
21 import jalview.gui.AlignFrame;
22 import jalview.gui.AlignmentPanel;
23 import jalview.ws.jws2.dm.AAConSettings;
24 import jalview.ws.jws2.jabaws2.Jws2Instance;
25 import jalview.ws.params.WsParamSetI;
26 import jalview.ws.uimodel.AlignAnalysisUIText;
27
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32 import java.util.TreeSet;
33
34 import compbio.data.sequence.Score;
35 import compbio.metadata.Argument;
36
37 public class AAConClient extends JabawsAlignCalcWorker
38 {
39
40   public AAConClient(Jws2Instance service, AlignFrame alignFrame,
41           WsParamSetI preset, List<Argument> paramset)
42   {
43     super(service, alignFrame, preset, paramset);
44     submitGaps = true;
45     alignedSeqs = true;
46     nucleotidesAllowed = false;
47     proteinAllowed = true;
48     gapMap = new boolean[0];
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   @Override
102   public String getCalcId()
103   {
104     return CALC_ID;
105   }
106   private static String CALC_ID="jabaws2.AACon";
107
108   public static AlignAnalysisUIText getAlignAnalysisUITest()
109   {
110     return new AlignAnalysisUIText(
111             compbio.ws.client.Services.AAConWS.toString(),
112             jalview.ws.jws2.AAConClient.class, CALC_ID, false, true, true,
113             "AACon Calculations",
114             "When checked, AACon calculations are updated automatically.",
115             "Change AACon Settings...",
116             "Modify settings for AACon calculations.");
117   }
118 }