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