- int sSize = sg.getSize();
- if (sSize < 2)
- {
- return;
- }
-
- if (hiddenRepSequences == null)
- {
- hiddenRepSequences = new Hashtable();
- }
-
- hiddenRepSequences.put(repSequence, sg);
-
- //Hide all sequences except the repSequence
- SequenceI[] seqs = new SequenceI[sSize - 1];
- int index = 0;
- for (int i = 0; i < sSize; i++)
- {
- if (sg.getSequenceAt(i) != repSequence)
- {
- if (index == sSize - 1)
- {
- return;
- }
-
- seqs[index++] = sg.getSequenceAt(i);
- }
- }
-
- hideSequence(seqs);
-
- }
-
- public void hideAllSelectedSeqs()
- {
- if (selectionGroup == null || selectionGroup.getSize()<1)
- {
- return;
- }
-
- SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
-
- hideSequence(seqs);
-
- setSelectionGroup(null);
- }
-
- public void hideSequence(SequenceI[] seq)
- {
- if (seq != null)
- {
- for (int i = 0; i < seq.length; i++)
- {
- alignment.getHiddenSequences().hideSequence(seq[i]);
- }
-
- hasHiddenRows = true;
- firePropertyChange("alignment", null, alignment.getSequences());
- }
- }
-
- public void showColumn(int col)
- {
- colSel.revealHiddenColumns(col);
- if (colSel.getHiddenColumns() == null)
- {
- hasHiddenColumns = false;
- }
- }
-
- public void showAllHiddenColumns()
- {
- colSel.revealAllHiddenColumns();
- hasHiddenColumns = false;
- }
-
- public void showAllHiddenSeqs()
- {
- if (alignment.getHiddenSequences().getSize() > 0)
- {
- if (selectionGroup == null)
- {
- selectionGroup = new SequenceGroup();
- selectionGroup.setEndRes(alignment.getWidth() - 1);
- }
- Vector tmp = alignment.getHiddenSequences().showAll(hiddenRepSequences);
- for (int t = 0; t < tmp.size(); t++)
- {
- selectionGroup.addSequence(
- (SequenceI) tmp.elementAt(t), false
- );
- }
- firePropertyChange("alignment", null, alignment.getSequences());
- hasHiddenRows = false;
- hiddenRepSequences = null;
- }
- }
-
- public int adjustForHiddenSeqs(int alignmentIndex)
- {
- return alignment.getHiddenSequences().adjustForHiddenSeqs(alignmentIndex);
- }
-
- /**
- * This method returns the a new SequenceI [] with
- * the selection sequence and start and end points adjusted
- * @return String[]
- */
- public SequenceI[] getSelectionAsNewSequence()
- {
- SequenceI[] sequences;
-
- if (selectionGroup == null)
- {
- sequences = alignment.getSequencesArray();
- }
- else
- {
- sequences = selectionGroup.getSelectionAsNewSequences(alignment);
- }
-
- return sequences;
- }
-
- /**
- * This method returns the visible alignment as text, as
- * seen on the GUI, ie if columns are hidden they will not
- * be returned in the result.
- * Use this for calculating trees, PCA, redundancy etc on views
- * which contain hidden columns.
- * @return String[]
- */
- public jalview.datamodel.CigarArray getViewAsCigars(boolean
- selectedRegionOnly)
- {
- CigarArray selection = null;
- SequenceI[] seqs = null;
- int i, iSize;
- int start = 0, end = 0;
- if (selectedRegionOnly && selectionGroup != null)
- {
- iSize = selectionGroup.getSize();
- seqs = selectionGroup.getSequencesInOrder(alignment);
- start = selectionGroup.getStartRes();
- end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
- }
- else
- {
- iSize = alignment.getHeight();
- seqs = alignment.getSequencesArray();
- end = alignment.getWidth() - 1;
- }
- SeqCigar[] selseqs = new SeqCigar[iSize];
- for (i = 0; i < iSize; i++)
- {
- selseqs[i] = new SeqCigar(seqs[i], start, end);
- }
- selection = new CigarArray(selseqs);
- // now construct the CigarArray operations
- if (hasHiddenColumns)
- {
- Vector regions = colSel.getHiddenColumns();
- int[] region;
- int hideStart, hideEnd;
- int last = start;
- for (int j = 0; last < end & j < regions.size(); j++)
- {
- region = (int[]) regions.elementAt(j);
- hideStart = region[0];
- hideEnd = region[1];
- // edit hidden regions to selection range
- if (hideStart < last)
- {
- if (hideEnd > last)
- {
- hideStart = last;
- }
- else
- {
- continue;
- }
- }
-
- if (hideStart > end)
- {
- break;
- }
-
- if (hideEnd > end)
- {
- hideEnd = end;
- }
-
- if (hideStart > hideEnd)
- {
- break;
- }
- /**
- * form operations...
- */
- if (last < hideStart)
- {
- selection.addOperation(CigarArray.M, hideStart - last);
- }
- selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
- last = hideEnd + 1;
- }
- // Final match if necessary.
- if (last < end)
- {
- selection.addOperation(CigarArray.M, end - last + 1);
- }
- }
- else
- {
- selection.addOperation(CigarArray.M, end - start + 1);
- }
- return selection;
- }
-
- /**
- * return a compact representation of the current alignment selection to
- * pass to an analysis function
- * @param selectedOnly boolean true to just return the selected view
- * @return AlignmentView
- */
- jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
- {
- // JBPNote:
- // this is here because the AlignmentView constructor modifies the CigarArray
- // object. Refactoring of Cigar and alignment view representation should
- // be done to remove redundancy.
- CigarArray aligview = getViewAsCigars(selectedOnly);
- if (aligview != null)
- {
- return new AlignmentView(aligview,
- (selectedOnly && selectionGroup != null) ?
- selectionGroup.getStartRes() : 0);
- }
- return null;
- }
-
- /**
- * This method returns the visible alignment as text, as
- * seen on the GUI, ie if columns are hidden they will not
- * be returned in the result.
- * Use this for calculating trees, PCA, redundancy etc on views
- * which contain hidden columns.
- * @return String[]
- */
- public String[] getViewAsString(boolean selectedRegionOnly)
- {
- String[] selection = null;
- SequenceI[] seqs = null;
- int i, iSize;
- int start = 0, end = 0;
- if (selectedRegionOnly && selectionGroup != null)
- {
- iSize = selectionGroup.getSize();
- seqs = selectionGroup.getSequencesInOrder(alignment);
- start = selectionGroup.getStartRes();
- end = selectionGroup.getEndRes() + 1;
- }
- else
- {
- iSize = alignment.getHeight();
- seqs = alignment.getSequencesArray();
- end = alignment.getWidth();
- }
-
- selection = new String[iSize];
-
- for (i = 0; i < iSize; i++)
- {
- if (hasHiddenColumns)
- {
- StringBuffer visibleSeq = new StringBuffer();
- Vector regions = colSel.getHiddenColumns();
-
- int blockStart = start, blockEnd = end;
- int[] region;
- int hideStart, hideEnd;
-
- for (int j = 0; j < regions.size(); j++)
- {
- region = (int[]) regions.elementAt(j);
- hideStart = region[0];
- hideEnd = region[1];
-
- if (hideStart < start)
- {
- continue;
- }
-
- blockStart = Math.min(blockStart, hideEnd + 1);
- blockEnd = Math.min(blockEnd, hideStart);
-
- if (blockStart > blockEnd)
- {
- break;
- }
-
- visibleSeq.append(seqs[i].getSequence(blockStart, blockEnd));
-
- blockStart = hideEnd + 1;
- blockEnd = end;
- }
-
- if (end > blockStart)
- {
- visibleSeq.append(seqs[i].getSequence(blockStart, end));
- }
-
- selection[i] = visibleSeq.toString();
- }
- else
- {
- selection[i] = seqs[i].getSequenceAsString(start, end);
- }
- }
-
- return selection;
- }
-
- public boolean getShowHiddenMarkers()
- {
- return showHiddenMarkers;
- }
-
- public void setShowHiddenMarkers(boolean show)
- {
- showHiddenMarkers = show;
- }
-
- public Color getSequenceColour(SequenceI seq)
- {
- if (sequenceColours == null || !sequenceColours.containsKey(seq))
- {
- return Color.white;
- }
- else
- {
- return (Color) sequenceColours.get(seq);
- }
- }
-
- public void setSequenceColour(SequenceI seq, Color col)
- {
- if (sequenceColours == null)
- {
- sequenceColours = new Hashtable();
- }
-
- if (col == null)
- {
- sequenceColours.remove(seq);
- }
- else
- {
- sequenceColours.put(seq, col);
- }
- }
-
- public String getSequenceSetId()
- {
- if (sequenceSetID == null)
- {
- sequenceSetID = alignment.hashCode() + "";
- }
-
- return sequenceSetID;
- }
-
- public void alignmentChanged(AlignmentPanel ap)
- {
- alignment.padGaps();
-
- if (hconsensus != null && autocalculateConsensus)
- {
- updateConsensus(ap);
- updateConservation(ap);
- }
-
- //Reset endRes of groups if beyond alignment width
- int alWidth = alignment.getWidth();
- Vector groups = alignment.getGroups();
- if (groups != null)
- {
- for (int i = 0; i < groups.size(); i++)
- {
- SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
- if (sg.getEndRes() > alWidth)
- {
- sg.setEndRes(alWidth - 1);
- }
- }
- }
-
- if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
- {
- selectionGroup.setEndRes(alWidth - 1);
- }
-
- resetAllColourSchemes();
-
- //AW alignment.adjustSequenceAnnotations();
- }
-
- void resetAllColourSchemes()
- {
- ColourSchemeI cs = globalColourScheme;
- if (cs != null)
- {
- if (cs instanceof ClustalxColourScheme)
- {
- ( (ClustalxColourScheme) cs).
- resetClustalX(alignment.getSequences(),
- alignment.getWidth());
- }
-
- cs.setConsensus(hconsensus);
- if (cs.conservationApplied())
- {
- Alignment al = (Alignment) alignment;
- Conservation c = new Conservation("All",
- ResidueProperties.propHash, 3,
- al.getSequences(), 0,
- al.getWidth() - 1);
- c.calculate();
- c.verdict(false, ConsPercGaps);
-
- cs.setConservation(c);
- }
- }
-
- int s, sSize = alignment.getGroups().size();
- for (s = 0; s < sSize; s++)
- {
- SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
- if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
- {
- ( (ClustalxColourScheme) sg.cs).resetClustalX(
- sg.getSequences(hiddenRepSequences), sg.getWidth());
- }
- sg.recalcConservation();
- }