2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.controller;
23 import java.awt.Color;
24 import java.util.BitSet;
25 import java.util.List;
27 import jalview.api.AlignViewControllerGuiI;
28 import jalview.api.AlignViewControllerI;
29 import jalview.api.AlignViewportI;
30 import jalview.api.AlignmentViewPanel;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.AnnotatedCollectionI;
33 import jalview.datamodel.ColumnSelection;
34 import jalview.datamodel.SequenceCollectionI;
35 import jalview.datamodel.SequenceFeature;
36 import jalview.datamodel.SequenceGroup;
37 import jalview.datamodel.SequenceI;
38 import jalview.util.MessageManager;
40 public class AlignViewController implements AlignViewControllerI
42 AlignViewportI viewport = null;
44 AlignmentViewPanel alignPanel = null;
47 * the GUI container that is handling interactions with the user
49 private AlignViewControllerGuiI avcg;
52 protected void finalize() throws Throwable
59 public AlignViewController(AlignViewControllerGuiI alignFrame,
60 AlignViewportI viewport, AlignmentViewPanel alignPanel)
62 this.avcg = alignFrame;
63 this.viewport = viewport;
64 this.alignPanel = alignPanel;
68 public void setViewportAndAlignmentPanel(AlignViewportI viewport,
69 AlignmentViewPanel alignPanel)
71 this.alignPanel = alignPanel;
72 this.viewport = viewport;
77 public boolean makeGroupsFromSelection()
80 if (viewport.getSelectionGroup() != null)
82 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
83 viewport.getSequenceSelection(),
84 viewport.getAlignmentView(true).getSequenceStrings(
85 viewport.getGapCharacter()), viewport.getAlignment()
87 viewport.getAlignment().deleteAllGroups();
88 viewport.clearSequenceColours();
89 viewport.setSelectionGroup(null);
90 // set view properties for each group
91 for (int g = 0; g < gps.length; g++)
93 // gps[g].setShowunconserved(viewport.getShowUnconserved());
94 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
95 viewport.getAlignment().addGroup(gps[g]);
96 Color col = new Color((int) (Math.random() * 255),
97 (int) (Math.random() * 255), (int) (Math.random() * 255));
99 for (SequenceI sq : gps[g].getSequences(null))
100 viewport.setSequenceColour(sq, col);
108 public boolean createGroup()
111 SequenceGroup sg = viewport.getSelectionGroup();
114 viewport.getAlignment().addGroup(sg);
121 public boolean unGroup()
123 SequenceGroup sg = viewport.getSelectionGroup();
126 viewport.getAlignment().deleteGroup(sg);
133 public boolean deleteGroups()
135 if (viewport.getAlignment().getGroups() != null
136 && viewport.getAlignment().getGroups().size() > 0)
138 viewport.getAlignment().deleteAllGroups();
139 viewport.clearSequenceColours();
140 viewport.setSelectionGroup(null);
147 public boolean markColumnsContainingFeatures(boolean invert,
148 boolean extendCurrent, boolean toggle, String featureType)
150 // JBPNote this routine could also mark rows, not just columns.
151 // need a decent query structure to allow all types of feature searches
152 BitSet bs = new BitSet();
154 SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null ? viewport
155 .getAlignment() : viewport.getSelectionGroup());
156 alStart = sqcol.getStartRes();
157 alw = sqcol.getEndRes() + 1;
158 List<SequenceI> seqs = sqcol.getSequences();
160 for (SequenceI sq : seqs)
165 SequenceI dsq = sq.getDatasetSequence();
166 while (dsq.getDatasetSequence() != null)
168 dsq = dsq.getDatasetSequence();
171 SequenceFeature[] sf = dsq.getSequenceFeatures();
174 int ist = sq.findIndex(sq.getStart());
175 int iend = sq.findIndex(sq.getEnd());
176 if (iend < alStart || ist > alw)
178 // sequence not in region
181 for (SequenceFeature sfpos : sf)
183 // future functionalty - featureType == null means mark columns
184 // containing all displayed features
185 if (sfpos != null && (featureType.equals(sfpos.getType())))
188 // optimisation - could consider 'spos,apos' like cursor argument
189 // - findIndex wastes time by starting from first character and
192 int i = sq.findIndex(sfpos.getBegin());
193 int j = sq.findIndex(sfpos.getEnd());
194 if (j < alStart || i > alw)
196 // feature is outside selected region
225 ColumnSelection cs = viewport.getColumnSelection();
226 if (bs.cardinality() > 0 || invert)
230 cs = new ColumnSelection();
241 // invert only in the currently selected sequence region
242 for (int i = bs.nextClearBit(alStart), ibs = bs.nextSetBit(alStart); i >= alStart
245 if (ibs < 0 || i < ibs)
247 if (toggle && cs.contains(i))
249 cs.removeElement(i++);
258 i = bs.nextClearBit(ibs);
259 ibs = bs.nextSetBit(i);
265 for (int i = bs.nextSetBit(alStart); i >= alStart; i = bs
268 if (toggle && cs.contains(i))
278 viewport.setColumnSelection(cs);
279 alignPanel.paintAlignment(true);
280 avcg.setStatus(MessageManager.formatMessage("label.view_controller_toggled_marked",
282 (toggle ? MessageManager.getString("label.toggled") : MessageManager.getString("label.marked")),
283 (invert ? (Integer.valueOf((alw - alStart) - bs.cardinality()).toString()):(Integer.valueOf(bs.cardinality()).toString())),
284 featureType, Integer.valueOf(nseq).toString()
290 avcg.setStatus(MessageManager.formatMessage("label.no_feature_of_type_found", new String[]{featureType}));
291 if (!extendCurrent && cs != null)
294 alignPanel.paintAlignment(true);