f0a4b67248981b81e4779a924e62de653ba2bf20
[jalview.git] / src / jalview / ws / jws2 / jabaws2 / AAConClient.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ 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.jabaws2;
22
23 import jalview.api.AlignViewportI;
24 import jalview.datamodel.AlignmentAnnotation;
25 import jalview.util.MessageManager;
26 import jalview.ws.gui.AnnotationWsJob;
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
37 public class AAConClient extends JabawsAnnotationInstance
38 {
39   // configuration for factory
40   public static String getServiceActionText()
41   {
42     return "calculating Amino acid consensus using AACon service";
43   }
44
45
46
47   private static String CALC_ID = "jabaws2.AACon";
48
49   public static AlignAnalysisUIText getAlignAnalysisUIText()
50   {
51     return new AlignAnalysisUIText(
52             compbio.ws.client.Services.AAConWS.toString(),
53             AAConClient.class, CALC_ID, false, true, true, true,
54             true, 2, MessageManager.getString("label.aacon_calculations"),
55             MessageManager.getString("tooltip.aacon_calculations"),
56             MessageManager.getString("label.aacon_settings"),
57             MessageManager.getString("tooltip.aacon_settings"));
58   }
59
60   // instance
61   public AAConClient(Jws2Instance handle)
62   {
63     super(handle);
64   }
65
66   @Override
67   List<AlignmentAnnotation> annotationFromScoreManager(
68           AnnotationWsJob running, AlignViewportI alignViewport,
69           boolean[] gapMap)
70   {
71
72     Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
73     int alWidth = alignViewport.getAlignment().getWidth();
74     ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<>();
75     for (String score : scoremap.keySet())
76     {
77       Set<Score> scores = scoremap.get(score);
78       for (Score scr : scores)
79       {
80         if (scr.getRanges() != null && scr.getRanges().size() > 0)
81         {
82           /**
83            * annotation in range annotation = findOrCreate(scr.getMethod(),
84            * true, null, null); Annotation[] elm = new Annotation[alWidth];
85            * Iterator<Float> vals = scr.getScores().iterator(); for (Range rng :
86            * scr.getRanges()) { float val = vals.next().floatValue(); for (int i
87            * = rng.from; i <= rng.to; i++) { elm[i] = new Annotation("", "", '
88            * ', val); } } annotation.annotations = elm;
89            * annotation.validateRangeAndDisplay();
90            */
91         }
92         else
93         {
94           createAnnotationRowsForScores(alignViewport, gapMap, ourAnnot,
95                   getCalcId(), alWidth, scr);
96         }
97       }
98     }
99     return ourAnnot;
100   }
101
102 }