/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.datamodel; import jalview.analysis.*; import jalview.datamodel.*; import jalview.schemes.*; import java.awt.*; import java.util.Vector; public class SequenceGroup { String groupName; Conservation conserve; Vector aaFrequency; boolean displayBoxes; boolean displayText; boolean colourText; public Vector sequences = new Vector(); int width = -1; public ColourSchemeI cs; int startRes = 0; int endRes = 0; Color outlineColour = Color.black; public SequenceGroup() { groupName = "Group"; this.displayBoxes = true; this.displayText = true; this.colourText = false; cs = null; } public SequenceGroup(Vector sequences, String groupName, ColourSchemeI scheme, boolean displayBoxes, boolean displayText, boolean colourText, int start, int end) { this.sequences = sequences; this.groupName = groupName; this.displayBoxes = displayBoxes; this.displayText = displayText; this.colourText = colourText; this.cs = scheme; startRes = start; endRes = end; } public SequenceGroup(String groupName, ColourSchemeI scheme, boolean displayBoxes, boolean displayText, boolean colourText, int start, int end) { this.groupName = groupName; this.displayBoxes = displayBoxes; this.displayText = displayText; this.colourText = colourText; this.cs = scheme; startRes = start; endRes = end; } public boolean adjustForRemoveLeft(int col) { // return value is true if the group still exists if (startRes >= col) { startRes = startRes - col; } if (endRes >= col) { endRes = endRes - col; if (startRes > endRes) { startRes = 0; } } else { // must delete this group!! return false; } return true; } public boolean adjustForRemoveRight(int col) { if (startRes > col) { // delete this group return false; } if (endRes >= col) { endRes = col; } return true; } public String getName() { return groupName; } public void setName(String name) { groupName = name; } public Conservation getConservation() { return conserve; } public void setConservation(Conservation c) { conserve = c; } public void addSequence(SequenceI s, boolean recalc) { if (!sequences.contains(s)) sequences.addElement(s); if(recalc) recalcConservation(); } public void recalcConservation() { if (cs != null) { cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); } if ( cs instanceof ConservationColourScheme) { Conservation c = new Conservation(groupName, ResidueProperties.propHash, 3, sequences, 0, getWidth()); c.calculate(); c.verdict(false, 25); ConservationColourScheme ccs = (ConservationColourScheme) cs; ccs.conserve = c; } } public void addOrRemove(SequenceI s, boolean recalc) { if (sequences.contains(s)) { deleteSequence(s, recalc); } else { addSequence(s, recalc); } } public void deleteSequence(SequenceI s, boolean recalc) { sequences.removeElement(s); if(recalc) recalcConservation(); } public int getStartRes() { return startRes; } public int getEndRes() { return endRes; } public void setStartRes(int i) { startRes = i; } public void setEndRes(int i) { endRes = i; } public int getSize() { return sequences.size(); } public SequenceI getSequenceAt(int i) { return (SequenceI) sequences.elementAt(i); } public void setColourText(boolean state) { colourText = state; } public boolean getColourText() { return colourText; } public void setDisplayText(boolean state) { displayText = state; } public boolean getDisplayText() { return displayText; } public void setDisplayBoxes(boolean state) { displayBoxes = state; } public boolean getDisplayBoxes() { return displayBoxes; } public int getWidth() { // MC This needs to get reset when characters are inserted and deleted if (sequences.size() > 0) { width = ( (SequenceI) sequences.elementAt(0)).getLength(); } for (int i = 1; i < sequences.size(); i++) { SequenceI seq = (SequenceI) sequences.elementAt(i); if (seq.getLength() > width) { width = seq.getLength(); } } return width; } public void setOutlineColour(Color c) { outlineColour = c; } public Color getOutlineColour() { return outlineColour; } /** * * returns the sequences in the group ordered by the ordering given by al * * @param al Alignment * @return SequenceI[] */ public SequenceI[] getSequencesInOrder(Alignment al) { int sz; java.util.Hashtable orderedSeqs = new java.util.Hashtable(); SequenceI[] seqs = new SequenceI[sz = sequences.size()]; for (int i = 0; i < sz; i++) { SequenceI seq = (SequenceI) sequences.elementAt(i); int index = al.findIndex(seq); orderedSeqs.put(index + "", seq); } int index = 0; for (int i = 0; i < sz; i++) { SequenceI seq = null; while (seq == null) { if (orderedSeqs.containsKey(index + "")) { seq = (SequenceI) orderedSeqs.get(index + ""); index++; break; } else { index++; } } seqs[index] = seq; } return seqs; } }