JAL-1503 update version in GPL header
[jalview.git] / src / jalview / ws / jws2 / AAConClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3  * Copyright (C) 2014 The Jalview Authors
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  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.ws.jws2;
20
21 import jalview.datamodel.AlignmentAnnotation;
22 import jalview.gui.AlignFrame;
23 import jalview.gui.AlignmentPanel;
24 import jalview.ws.jws2.dm.AAConSettings;
25 import jalview.ws.jws2.jabaws2.Jws2Instance;
26 import jalview.ws.params.WsParamSetI;
27 import jalview.ws.uimodel.AlignAnalysisUIText;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Set;
33 import java.util.TreeSet;
34
35 import compbio.data.sequence.Score;
36 import compbio.metadata.Argument;
37
38 public class AAConClient extends JabawsAlignCalcWorker
39 {
40
41   public AAConClient(Jws2Instance service, AlignFrame alignFrame,
42           WsParamSetI preset, List<Argument> paramset)
43   {
44     super(service, alignFrame, preset, paramset);
45     submitGaps = true;
46     alignedSeqs = true;
47     nucleotidesAllowed = false;
48     proteinAllowed = true;
49     gapMap = new boolean[0];
50     initViewportParams();
51   }
52
53   public String getServiceActionText()
54   {
55     return "calculating Amino acid consensus using AACon service";
56   }
57
58   /**
59    * update the consensus annotation from the sequence profile data using
60    * current visualization settings.
61    */
62
63   public void updateResultAnnotation(boolean immediate)
64   {
65     if (immediate || !calcMan.isWorking(this) && scoremanager != null)
66     {
67       Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
68       int alWidth = alignViewport.getAlignment().getWidth();
69       ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
70       for (String score : scoremap.keySet())
71       {
72         Set<Score> scores = scoremap.get(score);
73         for (Score scr : scores)
74         {
75           if (scr.getRanges() != null && scr.getRanges().size() > 0)
76           {
77             /**
78              * annotation in range annotation = findOrCreate(scr.getMethod(),
79              * true, null, null); Annotation[] elm = new Annotation[alWidth];
80              * Iterator<Float> vals = scr.getScores().iterator(); for (Range rng
81              * : scr.getRanges()) { float val = vals.next().floatValue(); for
82              * (int i = rng.from; i <= rng.to; i++) { elm[i] = new
83              * Annotation("", "", ' ', val); } } annotation.annotations = elm;
84              * annotation.validateRangeAndDisplay();
85              */
86           }
87           else
88           {
89             createAnnotationRowsForScores(ourAnnot, getCalcId(), alWidth,
90                     scr);
91           }
92         }
93       }
94
95       if (ourAnnot.size() > 0)
96       {
97         updateOurAnnots(ourAnnot);
98       }
99     }
100   }
101
102   @Override
103   public String getCalcId()
104   {
105     return CALC_ID;
106   }
107   private static String CALC_ID="jabaws2.AACon";
108
109   public static AlignAnalysisUIText getAlignAnalysisUITest()
110   {
111     return new AlignAnalysisUIText(
112             compbio.ws.client.Services.AAConWS.toString(),
113             jalview.ws.jws2.AAConClient.class, CALC_ID, false, true, true,
114             "AACon Calculations",
115             "When checked, AACon calculations are updated automatically.",
116             "Change AACon Settings...",
117             "Modify settings for AACon calculations.");
118   }
119 }