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