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;
42 AlignmentViewPanel alignPanel=null;
44 * the GUI container that is handling interactions with the user
46 private AlignViewControllerGuiI avcg;
48 protected void finalize() throws Throwable {
54 public AlignViewController(AlignViewControllerGuiI alignFrame, AlignViewportI viewport,
55 AlignmentViewPanel alignPanel)
57 this.avcg = alignFrame;
58 this.viewport=viewport;
59 this.alignPanel = alignPanel;
62 public void setViewportAndAlignmentPanel(AlignViewportI viewport,AlignmentViewPanel alignPanel)
64 this.alignPanel = alignPanel;
65 this.viewport = viewport;
69 public boolean makeGroupsFromSelection()
72 if (viewport.getSelectionGroup() != null)
74 SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
75 viewport.getSequenceSelection(),
76 viewport.getAlignmentView(true).getSequenceStrings(
77 viewport.getGapCharacter()), viewport.getAlignment()
79 viewport.getAlignment().deleteAllGroups();
80 viewport.clearSequenceColours();
81 viewport.setSelectionGroup(null);
82 // set view properties for each group
83 for (int g = 0; g < gps.length; g++)
85 // gps[g].setShowunconserved(viewport.getShowUnconserved());
86 gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo());
87 viewport.getAlignment().addGroup(gps[g]);
88 Color col = new Color((int) (Math.random() * 255),
89 (int) (Math.random() * 255), (int) (Math.random() * 255));
91 for (SequenceI sq : gps[g].getSequences(null))
92 viewport.setSequenceColour(sq, col);
99 public boolean createGroup()
102 SequenceGroup sg = viewport.getSelectionGroup();
105 viewport.getAlignment().addGroup(sg);
111 public boolean unGroup()
113 SequenceGroup sg = viewport.getSelectionGroup();
116 viewport.getAlignment().deleteGroup(sg);
122 public boolean deleteGroups()
124 if (viewport.getAlignment().getGroups()!=null && viewport.getAlignment().getGroups().size()>0)
126 viewport.getAlignment().deleteAllGroups();
127 viewport.clearSequenceColours();
128 viewport.setSelectionGroup(null);
135 public boolean markColumnsContainingFeatures(boolean invert, boolean extendCurrent, boolean toggle, String featureType)
137 // JBPNote this routine could also mark rows, not just columns.
138 // need a decent query structure to allow all types of feature searches
139 BitSet bs = new BitSet();
141 SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null ? viewport.getAlignment() : viewport.getSelectionGroup());
142 alStart = sqcol.getStartRes();
143 alw = sqcol.getEndRes()+1;
144 List<SequenceI> seqs = sqcol.getSequences();
146 for (SequenceI sq : seqs)
151 SequenceI dsq = sq.getDatasetSequence();
152 while (dsq.getDatasetSequence() != null)
154 dsq = dsq.getDatasetSequence();
157 SequenceFeature[] sf = dsq.getSequenceFeatures();
160 int ist = sq.findIndex(sq.getStart());
161 int iend = sq.findIndex(sq.getEnd());
162 if (iend < alStart || ist> alw)
164 // sequence not in region
167 for (SequenceFeature sfpos : sf)
169 // future functionalty - featureType == null means mark columns
170 // containing all displayed features
171 if (sfpos != null && (featureType.equals(sfpos.getType())))
174 // optimisation - could consider 'spos,apos' like cursor argument
175 // - findIndex wastes time by starting from first character and
178 int i = sq.findIndex(sfpos.getBegin());
179 int j = sq.findIndex(sfpos.getEnd());
180 if (j<alStart || i>alw)
182 // feature is outside selected region
210 ColumnSelection cs = viewport.getColumnSelection();
211 if (bs.cardinality() > 0 || invert)
215 cs = new ColumnSelection();
224 // invert only in the currently selected sequence region
225 for (int i = bs.nextClearBit(alStart), ibs = bs.nextSetBit(alStart); i >= alStart
228 if (ibs < 0 || i < ibs)
230 if (toggle && cs.contains(i))
232 cs.removeElement(i++);
240 i = bs.nextClearBit(ibs);
241 ibs = bs.nextSetBit(i);
247 for (int i = bs.nextSetBit(alStart); i >= alStart; i = bs.nextSetBit(i + 1))
249 if (toggle && cs.contains(i))
258 viewport.setColumnSelection(cs);
259 alignPanel.paintAlignment(true);
260 avcg.setStatus((toggle ? "Toggled ": "Marked ")
261 + (invert ? (alw-alStart) - bs.cardinality() : bs.cardinality())
262 + " columns "+(invert ? "not " : "") + "containing features of type " + featureType
263 + " across " + nseq + " sequence(s)");
268 avcg.setStatus("No features of type " + featureType + " found.");
269 if (!extendCurrent && cs!=null)
272 alignPanel.paintAlignment(true);