+
+ @Override
+ public boolean markColumnsContainingFeatures(boolean invert,
+ boolean extendCurrent, boolean toggle, String featureType)
+ {
+ // JBPNote this routine could also mark rows, not just columns.
+ // need a decent query structure to allow all types of feature searches
+ BitSet bs = new BitSet();
+ SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null
+ || extendCurrent) ? viewport.getAlignment()
+ : viewport.getSelectionGroup();
+
+ int nseq = findColumnsWithFeature(featureType, sqcol, bs);
+
+ ColumnSelection cs = viewport.getColumnSelection();
+ if (cs == null)
+ {
+ cs = new ColumnSelection();
+ }
+
+ if (bs.cardinality() > 0 || invert)
+ {
+ boolean changed = cs.markColumns(bs, sqcol.getStartRes(),
+ sqcol.getEndRes(), invert, extendCurrent, toggle);
+ if (changed)
+ {
+ viewport.setColumnSelection(cs);
+ alignPanel.paintAlignment(false, false);
+ int columnCount = invert
+ ? (sqcol.getEndRes() - sqcol.getStartRes() + 1)
+ - bs.cardinality()
+ : bs.cardinality();
+ avcg.setStatus(MessageManager.formatMessage(
+ "label.view_controller_toggled_marked", new String[]
+ { toggle ? MessageManager.getString("label.toggled")
+ : MessageManager.getString("label.marked"),
+ String.valueOf(columnCount),
+ invert ? MessageManager
+ .getString("label.not_containing")
+ : MessageManager.getString("label.containing"),
+ featureType, Integer.valueOf(nseq).toString() }));
+ return true;
+ }
+ }
+ else
+ {
+ avcg.setStatus(MessageManager
+ .formatMessage("label.no_feature_of_type_found", new String[]
+ { featureType }));
+ if (!extendCurrent)
+ {
+ cs.clear();
+ alignPanel.paintAlignment(false, false);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Sets a bit in the BitSet for each column (base 0) in the sequence
+ * collection which includes the specified feature type. Returns the number of
+ * sequences which have the feature in the selected range.
+ *
+ * @param featureType
+ * @param sqcol
+ * @param bs
+ * @return
+ */
+ static int findColumnsWithFeature(String featureType,
+ SequenceCollectionI sqcol, BitSet bs)
+ {
+ final int startColumn = sqcol.getStartRes() + 1; // converted to base 1
+ final int endColumn = sqcol.getEndRes() + 1;
+ List<SequenceI> seqs = sqcol.getSequences();
+ int nseq = 0;
+ for (SequenceI sq : seqs)
+ {
+ if (sq != null)
+ {
+ // int ist = sq.findPosition(sqcol.getStartRes());
+ List<SequenceFeature> sfs = sq.findFeatures(startColumn,
+ endColumn, featureType);
+
+ if (!sfs.isEmpty())
+ {
+ nseq++;
+ }
+
+ for (SequenceFeature sf : sfs)
+ {
+ int sfStartCol = sq.findIndex(sf.getBegin());
+ int sfEndCol = sq.findIndex(sf.getEnd());
+
+ if (sf.isContactFeature())
+ {
+ /*
+ * 'contact' feature - check for 'start' or 'end'
+ * position within the selected region
+ */
+ if (sfStartCol >= startColumn && sfStartCol <= endColumn)
+ {
+ bs.set(sfStartCol - 1);
+ }
+ if (sfEndCol >= startColumn && sfEndCol <= endColumn)
+ {
+ bs.set(sfEndCol - 1);
+ }
+ continue;
+ }
+
+ /*
+ * contiguous feature - select feature positions (if any)
+ * within the selected region
+ */
+ if (sfStartCol < startColumn)
+ {
+ sfStartCol = startColumn;
+ }
+ // not sure what the point of this is
+ // if (sfStartCol < ist)
+ // {
+ // sfStartCol = ist;
+ // }
+ if (sfEndCol > endColumn)
+ {
+ sfEndCol = endColumn;
+ }
+ for (; sfStartCol <= sfEndCol; sfStartCol++)
+ {
+ bs.set(sfStartCol - 1); // convert to base 0
+ }
+ }
+ }
+ }
+ return nseq;
+ }
+
+ @Override
+ public void sortAlignmentByFeatureDensity(List<String> typ)
+ {
+ sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
+ }
+
+ protected void sortBy(List<String> typ, String methodText,
+ final String method)
+ {
+ FeatureRenderer fr = alignPanel.getFeatureRenderer();
+ if (typ == null && fr != null)
+ {
+ typ = fr.getDisplayedFeatureTypes();
+ }
+ List<String> gps = null;
+ if (fr != null)
+ {
+ gps = fr.getDisplayedFeatureGroups();
+ }
+ AlignmentI al = viewport.getAlignment();
+
+ int start, stop;
+ SequenceGroup sg = viewport.getSelectionGroup();
+ if (sg != null)
+ {
+ start = sg.getStartRes();
+ stop = sg.getEndRes();
+ }
+ else
+ {
+ start = 0;
+ stop = al.getWidth();
+ }
+ SequenceI[] oldOrder = al.getSequencesArray();
+ AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method);
+ avcg.addHistoryItem(new OrderCommand(methodText, oldOrder,
+ viewport.getAlignment()));
+ alignPanel.paintAlignment(true, false);
+
+ }
+
+ @Override
+ public void sortAlignmentByFeatureScore(List<String> typ)
+ {
+ sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);