X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=116e172fd28bdf4ef416c6b99cef1b934829ae4e;hb=2a40019eb6a0beb79dc29263a4173e6adb2909a7;hp=4c6420c0082e69f77863da4fdd68465c9c516c5c;hpb=d75ccc3b6f6e8f3e22b8c5732c0553f15e24d4ef;p=jalview.git diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 4c6420c..116e172 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -1,11 +1,33 @@ +/* + * 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.schemes.*; import jalview.analysis.*; + import jalview.datamodel.*; -import java.util.Vector; + +import jalview.schemes.*; + import java.awt.*; +import java.util.Vector; + public class SequenceGroup { String groupName; @@ -14,7 +36,6 @@ public class SequenceGroup boolean displayBoxes; boolean displayText; boolean colourText; - boolean aaFrequencyValid = false; public Vector sequences = new Vector(); int width = -1; public ColourSchemeI cs; @@ -31,13 +52,27 @@ public class SequenceGroup cs = null; } - public SequenceGroup(String groupName, ColourSchemeI scheme, + public SequenceGroup(Vector sequences, String groupName, ColourSchemeI scheme, boolean displayBoxes, boolean displayText, boolean colourText, - int start, - int end) + 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; + recalcConservation(); + } + 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; @@ -47,6 +82,48 @@ public class SequenceGroup 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; @@ -67,26 +144,67 @@ public class SequenceGroup conserve = c; } - public void addSequence(SequenceI s) + public void addSequence(SequenceI s, boolean recalc) { - if(!sequences.contains(s)) + if (!sequences.contains(s)) sequences.addElement(s); + + if(recalc) + recalcConservation(); } - public void addOrRemove(SequenceI s) + + public void recalcConservation() { - if(sequences.contains(s)) - deleteSequence(s); + System.out.println("sg recalc"); + if (cs != null) + { + cs.setConsensus(AAFrequency.calculate(sequences, 0, getWidth())); + } + + if (cs instanceof ClustalxColourScheme) + { + ( (ClustalxColourScheme) cs).resetClustalX(sequences,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; + if (ccs.cs instanceof ClustalxColourScheme) + { + ( (ClustalxColourScheme) ccs.cs).resetClustalX(sequences, getWidth()); + } + + } + } + + public void addOrRemove(SequenceI s, boolean recalc) + { + if (sequences.contains(s)) + { + deleteSequence(s, recalc); + } else - addSequence(s); + { + addSequence(s, recalc); + } } - public void deleteSequence(SequenceI s) + public void deleteSequence(SequenceI s, boolean recalc) { sequences.removeElement(s); + if(recalc) + recalcConservation(); } - public int getStartRes() { return startRes; @@ -147,36 +265,81 @@ public class SequenceGroup return displayBoxes; } - public Vector getAAFrequency() + public int getWidth() { - if (aaFrequency == null || aaFrequencyValid == false) + // MC This needs to get reset when characters are inserted and deleted + if (sequences.size() > 0) { - aaFrequency = AAFrequency.calculate(sequences, 0, getWidth()); - aaFrequencyValid = true; + width = ( (SequenceI) sequences.elementAt(0)).getLength(); } - return aaFrequency; - } - public int getWidth() - { - System.out.println("it is called"); - // MC This needs to get reset when characters are inserted and deleted - for (int i = 0; i < sequences.size(); i++) + 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; + } }