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;
39 public class AlignViewController implements AlignViewControllerI
41 AlignViewportI viewport = null;
43 AlignmentViewPanel alignPanel = null;
46 * the GUI container that is handling interactions with the user
48 private AlignViewControllerGuiI avcg;
51 protected void finalize() throws Throwable
58 public AlignViewController(AlignViewControllerGuiI alignFrame,
59 AlignViewportI viewport, AlignmentViewPanel alignPanel)
61 this.avcg = alignFrame;
62 this.viewport = viewport;
63 this.alignPanel = alignPanel;
67 public void setViewportAndAlignmentPanel(AlignViewportI viewport,
68 AlignmentViewPanel alignPanel)
70 this.alignPanel = alignPanel;
71 this.viewport = viewport;
76 public boolean makeGroupsFromSelection()
79 if (viewport.getSelectionGroup() != null)
81 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
82 viewport.getSequenceSelection(),
83 viewport.getAlignmentView(true).getSequenceStrings(
84 viewport.getGapCharacter()), viewport.getAlignment()
86 viewport.getAlignment().deleteAllGroups();
87 viewport.clearSequenceColours();
88 viewport.setSelectionGroup(null);
89 // set view properties for each group
90 for (int g = 0; g < gps.length; g++)
92 // gps[g].setShowunconserved(viewport.getShowUnconserved());
93 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
94 viewport.getAlignment().addGroup(gps[g]);
95 Color col = new Color((int) (Math.random() * 255),
96 (int) (Math.random() * 255), (int) (Math.random() * 255));
98 for (SequenceI sq : gps[g].getSequences(null))
99 viewport.setSequenceColour(sq, col);
107 public boolean createGroup()
110 SequenceGroup sg = viewport.getSelectionGroup();
113 viewport.getAlignment().addGroup(sg);
120 public boolean unGroup()
122 SequenceGroup sg = viewport.getSelectionGroup();
125 viewport.getAlignment().deleteGroup(sg);
132 public boolean deleteGroups()
134 if (viewport.getAlignment().getGroups() != null
135 && viewport.getAlignment().getGroups().size() > 0)
137 viewport.getAlignment().deleteAllGroups();
138 viewport.clearSequenceColours();
139 viewport.setSelectionGroup(null);
146 public boolean markColumnsContainingFeatures(boolean invert,
147 boolean extendCurrent, boolean toggle, String featureType)
149 // JBPNote this routine could also mark rows, not just columns.
150 // need a decent query structure to allow all types of feature searches
151 BitSet bs = new BitSet();
153 SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null ? viewport
154 .getAlignment() : viewport.getSelectionGroup());
155 alStart = sqcol.getStartRes();
156 alw = sqcol.getEndRes() + 1;
157 List<SequenceI> seqs = sqcol.getSequences();
159 for (SequenceI sq : seqs)
164 SequenceI dsq = sq.getDatasetSequence();
165 while (dsq.getDatasetSequence() != null)
167 dsq = dsq.getDatasetSequence();
170 SequenceFeature[] sf = dsq.getSequenceFeatures();
173 int ist = sq.findIndex(sq.getStart());
174 int iend = sq.findIndex(sq.getEnd());
175 if (iend < alStart || ist > alw)
177 // sequence not in region
180 for (SequenceFeature sfpos : sf)
182 // future functionalty - featureType == null means mark columns
183 // containing all displayed features
184 if (sfpos != null && (featureType.equals(sfpos.getType())))
187 // optimisation - could consider 'spos,apos' like cursor argument
188 // - findIndex wastes time by starting from first character and
191 int i = sq.findIndex(sfpos.getBegin());
192 int j = sq.findIndex(sfpos.getEnd());
193 if (j < alStart || i > alw)
195 // feature is outside selected region
224 ColumnSelection cs = viewport.getColumnSelection();
225 if (bs.cardinality() > 0 || invert)
229 cs = new ColumnSelection();
240 // invert only in the currently selected sequence region
241 for (int i = bs.nextClearBit(alStart), ibs = bs.nextSetBit(alStart); i >= alStart
244 if (ibs < 0 || i < ibs)
246 if (toggle && cs.contains(i))
248 cs.removeElement(i++);
257 i = bs.nextClearBit(ibs);
258 ibs = bs.nextSetBit(i);
264 for (int i = bs.nextSetBit(alStart); i >= alStart; i = bs
267 if (toggle && cs.contains(i))
277 viewport.setColumnSelection(cs);
278 alignPanel.paintAlignment(true);
279 avcg.setStatus((toggle ? "Toggled " : "Marked ")
280 + (invert ? (alw - alStart) - bs.cardinality() : bs
281 .cardinality()) + " columns "
282 + (invert ? "not " : "") + "containing features of type "
283 + featureType + " across " + nseq + " sequence(s)");
288 avcg.setStatus("No features of type " + featureType + " found.");
289 if (!extendCurrent && cs != null)
292 alignPanel.paintAlignment(true);