JAL-1432 updated copyright notices
[jalview.git] / src / jalview / ws / jws2 / AAConClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
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
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   protected void initViewportParams()
53   {
54     ((jalview.gui.AlignViewport) alignViewport).setCalcIdSettingsFor(
55             getCalcId(),
56             new AAConSettings(true, service, this.preset,
57                     (arguments != null) ? JabaParamStore
58                             .getJwsArgsfromJaba(arguments) : null), true);
59   }
60
61   @Override
62   public void updateParameters(WsParamSetI newpreset,
63           java.util.List<Argument> newarguments)
64   {
65     super.updateParameters(newpreset, newarguments);
66     initViewportParams();
67   };
68
69   public String getServiceActionText()
70   {
71     return "calculating Amino acid consensus using AACon service";
72   }
73
74   /**
75    * update the consensus annotation from the sequence profile data using
76    * current visualization settings.
77    */
78
79   public void updateResultAnnotation(boolean immediate)
80   {
81     if (immediate || !calcMan.isWorking(this) && scoremanager != null)
82     {
83       Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
84       int alWidth = alignViewport.getAlignment().getWidth();
85       ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
86       for (String score : scoremap.keySet())
87       {
88         Set<Score> scores = scoremap.get(score);
89         for (Score scr : scores)
90         {
91           if (scr.getRanges() != null && scr.getRanges().size() > 0)
92           {
93             /**
94              * annotation in range annotation = findOrCreate(scr.getMethod(),
95              * true, null, null); Annotation[] elm = new Annotation[alWidth];
96              * Iterator<Float> vals = scr.getScores().iterator(); for (Range rng
97              * : scr.getRanges()) { float val = vals.next().floatValue(); for
98              * (int i = rng.from; i <= rng.to; i++) { elm[i] = new
99              * Annotation("", "", ' ', val); } } annotation.annotations = elm;
100              * annotation.validateRangeAndDisplay();
101              */
102           }
103           else
104           {
105             createAnnotationRowsForScores(ourAnnot, getCalcId(), alWidth,
106                     scr);
107           }
108         }
109       }
110
111       if (ourAnnot.size() > 0)
112       {
113         updateOurAnnots(ourAnnot);
114       }
115     }
116   }
117
118   public String getCalcId()
119   {
120     return SequenceAnnotationWSClient.AAConCalcId;
121   }
122
123   public static void removeAAConsAnnotation(AlignmentPanel alignPanel)
124   {
125     for (AlignmentAnnotation aa : alignPanel.getAlignment().findAnnotation(
126             SequenceAnnotationWSClient.AAConCalcId))
127     {
128       alignPanel.getAlignment().deleteAnnotation(aa);
129     }
130   }
131 }