42a7bdba19217bf0a5d88fa56d92145c0b89ba42
[jalview.git] / src / jalview / ws / jws2 / AAConsClient.java
1 package jalview.ws.jws2;
2
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.AlignmentI;
5 import jalview.gui.AlignFrame;
6 import jalview.gui.AlignmentPanel;
7 import jalview.ws.jws2.dm.AAConsSettings;
8 import jalview.ws.jws2.jabaws2.Jws2Instance;
9 import jalview.ws.params.WsParamSetI;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15 import java.util.TreeSet;
16
17 import compbio.data.sequence.Score;
18 import compbio.metadata.Argument;
19
20 public class AAConsClient extends JabawsAlignCalcWorker
21 {
22
23   public AAConsClient(Jws2Instance service, AlignFrame alignFrame,
24           WsParamSetI preset, List<Argument> paramset)
25   {
26     super(service, alignFrame, preset, paramset);
27     submitGaps = true;
28     alignedSeqs = true;
29     nucleotidesAllowed = false;
30     proteinAllowed = true;
31     gapMap=new boolean[0];
32     initViewportParams();
33   }
34
35   protected void initViewportParams()
36   {
37     ((jalview.gui.AlignViewport) alignViewport).setCalcIdSettingsFor(getCalcId(), new AAConsSettings(true, service, this.preset, (arguments!=null) ?  JabaParamStore.getJwsArgsfromJaba(arguments) : null), true);
38   }
39   @Override
40   public void updateParameters(WsParamSetI newpreset, java.util.List<Argument> newarguments) {
41     super.updateParameters(newpreset, newarguments);
42     initViewportParams();
43   };
44   public String getServiceActionText()
45   {
46     return "calculating Amino acid consensus using AACons service";
47   }
48
49   /**
50    * update the consensus annotation from the sequence profile data using
51    * current visualization settings.
52    */
53
54   public void updateResultAnnotation(boolean immediate)
55   {
56     if (immediate || !calcMan.isWorking(this) && scoremanager != null)
57     {
58       Map<String, TreeSet<Score>> scoremap = scoremanager.asMap();
59       int alWidth = alignViewport.getAlignment().getWidth();
60       ArrayList<AlignmentAnnotation> ourAnnot = new ArrayList<AlignmentAnnotation>();
61       for (String score : scoremap.keySet())
62       {
63         Set<Score> scores = scoremap.get(score);
64         for (Score scr : scores)
65         {
66           if (scr.getRanges() != null && scr.getRanges().size() > 0)
67           {
68             /**
69              * annotation in range annotation = findOrCreate(scr.getMethod(),
70              * true, null, null); Annotation[] elm = new Annotation[alWidth];
71              * Iterator<Float> vals = scr.getScores().iterator(); for (Range rng
72              * : scr.getRanges()) { float val = vals.next().floatValue(); for
73              * (int i = rng.from; i <= rng.to; i++) { elm[i] = new
74              * Annotation("", "", ' ', val); } } annotation.annotations = elm;
75              * annotation.validateRangeAndDisplay();
76              */
77           }
78           else
79           {
80             createAnnotationRowsForScores(ourAnnot, getCalcId(), alWidth,
81                     scr);
82           }
83         }
84       }
85
86       if (ourAnnot.size() > 0)
87       {
88         updateOurAnnots(ourAnnot);
89       }
90     }
91   }
92
93   public String getCalcId()
94   {
95     return SequenceAnnotationWSClient.AAConsCalcId;
96   }
97
98   public static void removeAAConsAnnotation(AlignmentPanel alignPanel)
99   {
100     for (AlignmentAnnotation aa: alignPanel.getAlignment().findAnnotation(SequenceAnnotationWSClient.AAConsCalcId))
101     {
102       alignPanel.getAlignment().deleteAnnotation(aa);
103     }
104     // List<AlignmentAnnotation>
105     // ourannots=alignPanel.getAlignment().findAnnotation(Screen3D.)
106     // TODO Auto-generated method stub
107
108   }
109 }