+ private int parseColumnNode(BinaryNode bn) throws NumberFormatException
+ {
+ return Integer.parseInt(
+ bn.getName().substring(bn.getName().indexOf("c") + 1));
+ }
+ private boolean isColumnForNodeSelected(BinaryNode bn)
+ {
+ SequenceI rseq = tp.assocAnnotation.sequenceRef;
+ int colm = -1;
+ try
+ {
+ colm = parseColumnNode(bn);
+ } catch (Exception e)
+ {
+ return false;
+ }
+ if (av == null || av.getAlignment() == null)
+ {
+ // alignment is closed
+ return false;
+ }
+ ColumnSelection cs = av.getColumnSelection();
+ HiddenColumns hc = av.getAlignment().getHiddenColumns();
+ AlignmentAnnotation aa = tp.getAssocAnnotation();
+ int offp=-1;
+ if (aa != null)
+ {
+ ContactMatrixI cm = av.getContactMatrix(aa);
+ // generally, we assume cm has 1:1 mapping to annotation row - probably wrong
+ // but.. if
+ if (cm instanceof MappableContactMatrixI)
+ {
+ int[] pos;
+ // use the mappable's mapping - always the case for PAE Matrices so good
+ // for 2.11.3
+ MappableContactMatrixI mcm = (MappableContactMatrixI) cm;
+ pos = mcm.getMappedPositionsFor(rseq, colm + 1);
+ // finally, look up the position of the column
+ if (pos != null)
+ {
+ offp = rseq.findIndex(pos[0]);
+ }
+ } else {
+ offp = colm;
+ }
+ }
+ if (offp<=0)
+ {
+ return false;
+ }
+
+ offp-=2;
+ if (!av.hasHiddenColumns())
+ {
+ return cs.contains(offp);
+ }
+ if (hc.isVisible(offp))
+ {
+ return cs.contains(offp);
+ // return cs.contains(hc.absoluteToVisibleColumn(offp));
+ }
+ return false;
+ }
+ private BitSet createColumnGroupFor(Vector<BinaryNode> l, Color col)
+ {
+ BitSet gp = new BitSet();
+ for (BinaryNode bn : l)
+ {
+ int colm = -1;
+ if (bn.element() != null && bn.element() instanceof Integer)
+ {
+ colm = (Integer) bn.element();
+ }
+ else
+ {
+ // parse out from nodename
+ try
+ {
+ colm = parseColumnNode(bn);
+ } catch (Exception e)
+ {
+ continue;
+ }
+ }
+ gp.set(colm);
+ }
+ return gp;
+ }
+
+ private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
+ Color col, boolean clearSelected)
+ {
+ SequenceI rseq = tp.assocAnnotation.sequenceRef;
+ if (av == null || av.getAlignment() == null)
+ {
+ // alignment is closed
+ return;
+ }
+
+ // TODO - sort indices for faster lookup
+ ColumnSelection cs = av.getColumnSelection();
+ HiddenColumns hc = av.getAlignment().getHiddenColumns();
+ ContactMatrixI cm = av.getContactMatrix(tp.assocAnnotation);
+ MappableContactMatrixI mcm = null;
+ int offp;
+ if (cm instanceof MappableContactMatrixI)
+ {
+ mcm = (MappableContactMatrixI) cm;
+ }
+ for (BinaryNode bn : l)
+ {
+ int colm = -1;
+ try
+ {
+ colm = Integer.parseInt(
+ bn.getName().substring(bn.getName().indexOf("c") + 1));
+ } catch (Exception e)
+ {
+ continue;
+ }
+ if (mcm!=null)
+ {
+ int[] seqpos = mcm.getMappedPositionsFor(
+ rseq, colm);
+ if (seqpos == null)
+ {
+ // no mapping for this column.
+ continue;
+ }
+ // TODO: handle ranges...
+ offp = rseq.findIndex(seqpos[0])-1;
+ }
+ else
+ {
+ offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
+ : colm;
+ }
+ if (!av.hasHiddenColumns() || hc.isVisible(offp))
+ {
+ if (clearSelected || cs.contains(offp))
+ {
+ cs.removeElement(offp);
+ }
+ else
+ {
+ cs.addElement(offp);
+ }
+ }
+ }
+ PaintRefresher.Refresh(tp, av.getSequenceSetId());
+ }
+
+ public void createSeqGroupFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
+ Color col)
+ {
+
+ Vector<SequenceI> sequences = new Vector<>();
+
+ for (int j = 0; j < l.size(); j++)
+ {
+ SequenceI s1 = (SequenceI) l.elementAt(j).element();
+
+ if (!sequences.contains(s1))
+ {
+ sequences.addElement(s1);
+ }
+ }
+
+ ColourSchemeI cs = null;
+ SequenceGroup _sg = new SequenceGroup(sequences, null, cs, true, true,
+ false, 0, av.getAlignment().getWidth() - 1);
+
+ _sg.setName("JTreeGroup:" + _sg.hashCode());
+ _sg.setIdColour(col);
+
+ for (int a = 0; a < aps.length; a++)
+ {
+ SequenceGroup sg = new SequenceGroup(_sg);
+ AlignViewport viewport = aps[a].av;
+
+ // Propagate group colours in each view
+ if (viewport.getGlobalColourScheme() != null)
+ {
+ cs = viewport.getGlobalColourScheme().getInstance(viewport, sg);
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setThreshold(
+ viewport.getResidueShading().getThreshold(),
+ viewport.isIgnoreGapsConsensus());
+
+ if (viewport.getResidueShading().conservationApplied())
+ {
+ Conservation c = new Conservation("Group", sg.getSequences(null),
+ sg.getStartRes(), sg.getEndRes());
+ c.calculate();
+ c.verdict(false, viewport.getConsPercGaps());
+ sg.cs.setConservation(c);
+ }
+ }
+ // indicate that associated structure views will need an update
+ viewport.setUpdateStructures(true);
+ // propagate structure view update and sequence group to complement view
+ viewport.addSequenceGroup(sg);
+ }
+ }