66338b12655814d15b4dc7fa8c0924a69bf37f2e
[jalview.git] / src / jalview / ws / jws2 / AAConClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.ws.jws2;
22
23 import jalview.datamodel.AlignmentAnnotation;
24 import jalview.gui.AlignFrame;
25 import jalview.gui.AlignmentPanel;
26 import jalview.ws.jws2.dm.AAConSettings;
27 import jalview.ws.jws2.jabaws2.Jws2Instance;
28 import jalview.ws.params.WsParamSetI;
29 import jalview.ws.uimodel.AlignAnalysisUIText;
30
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Set;
35 import java.util.TreeSet;
36
37 import compbio.data.sequence.FastaSequence;
38 import compbio.data.sequence.Score;
39 import compbio.metadata.Argument;
40
41 public class AAConClient extends JabawsCalcWorker
42 {
43
44   public AAConClient(Jws2Instance service, AlignFrame alignFrame,
45           WsParamSetI preset, List<Argument> paramset)
46   {
47     super(service, alignFrame, preset, paramset);
48     submitGaps = true;
49     alignedSeqs = true;
50     nucleotidesAllowed = false;
51     proteinAllowed = true;
52     gapMap = new boolean[0];
53     initViewportParams();
54   }
55
56   public String getServiceActionText()
57   {
58     return "calculating Amino acid consensus using AACon service";
59   }
60
61   /**
62    * update the consensus annotation from the sequence profile data using
63    * current visualization settings.
64    */
65
66   public void updateResultAnnotation(boolean immediate)
67   {
68     if (immediate || !calcMan.isWorking(this) && scoremanager != null)
69     {
70       Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
71       int alWidth = alignViewport.getAlignment().getWidth();
72       ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
73       for (String score : scoremap.keySet())
74       {
75         Set<Score> scores = scoremap.get(score);
76         for (Score scr : scores)
77         {
78           if (scr.getRanges() != null && scr.getRanges().size() > 0)
79           {
80             /**
81              * annotation in range annotation = findOrCreate(scr.getMethod(),
82              * true, null, null); Annotation[] elm = new Annotation[alWidth];
83              * Iterator<Float> vals = scr.getScores().iterator(); for (Range rng
84              * : scr.getRanges()) { float val = vals.next().floatValue(); for
85              * (int i = rng.from; i <= rng.to; i++) { elm[i] = new
86              * Annotation("", "", ' ', val); } } annotation.annotations = elm;
87              * annotation.validateRangeAndDisplay();
88              */
89           }
90           else
91           {
92             createAnnotationRowsForScores(ourAnnot, getCalcId(), alWidth,
93                     scr);
94           }
95         }
96       }
97
98       if (ourAnnot.size() > 0)
99       {
100         updateOurAnnots(ourAnnot);
101       }
102     }
103   }
104
105   @Override
106   boolean checkValidInputSeqs(boolean dynamic, List<FastaSequence> seqs)
107   {
108     return (seqs.size() > 1);
109   }
110
111   @Override
112   public String getCalcId()
113   {
114     return CALC_ID;
115   }
116
117   private static String CALC_ID = "jabaws2.AACon";
118
119   public static AlignAnalysisUIText getAlignAnalysisUITest()
120   {
121     return new AlignAnalysisUIText(
122             compbio.ws.client.Services.AAConWS.toString(),
123             jalview.ws.jws2.AAConClient.class, CALC_ID, false, true, true,
124             "AACon Calculations",
125             "When checked, AACon calculations are updated automatically.",
126             "Change AACon Settings...",
127             "Modify settings for AACon calculations.");
128   }
129 }