X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=e37c55eb8688e50312e58c40142954da324049fd;hb=863529ed7d15dd5812cf280d82bfd53734b424a1;hp=98fd8f26ad57b19977540567a0ed1e1a3a04168a;hpb=1c757dc1e6ee864277825c1ebd9c6a9fbe0da7b2;p=jalview.git diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java index 98fd8f2..e37c55e 100755 --- a/src/jalview/datamodel/SequenceGroup.java +++ b/src/jalview/datamodel/SequenceGroup.java @@ -22,7 +22,8 @@ package jalview.datamodel; import jalview.analysis.AAFrequency; import jalview.analysis.Conservation; -import jalview.analysis.Profile; +import jalview.renderer.ResidueShader; +import jalview.renderer.ResidueShaderI; import jalview.schemes.ColourSchemeI; import java.awt.Color; @@ -70,7 +71,7 @@ public class SequenceGroup implements AnnotatedCollectionI /** * Colourscheme applied to group if any */ - public ColourSchemeI cs; + public ResidueShaderI cs; // start column (base 0) int startRes = 0; @@ -117,6 +118,7 @@ public class SequenceGroup implements AnnotatedCollectionI public SequenceGroup() { groupName = "JGroup:" + this.hashCode(); + cs = new ResidueShader(); } /** @@ -137,12 +139,13 @@ public class SequenceGroup implements AnnotatedCollectionI ColourSchemeI scheme, boolean displayBoxes, boolean displayText, boolean colourText, int start, int end) { + this(); this.sequences = sequences; this.groupName = groupName; this.displayBoxes = displayBoxes; this.displayText = displayText; this.colourText = colourText; - this.cs = scheme; + this.cs = new ResidueShader(scheme); startRes = start; endRes = end; recalcConservation(); @@ -155,6 +158,7 @@ public class SequenceGroup implements AnnotatedCollectionI */ public SequenceGroup(SequenceGroup seqsel) { + this(); if (seqsel != null) { sequences = new ArrayList(); @@ -528,7 +532,7 @@ public class SequenceGroup implements AnnotatedCollectionI boolean upd = false; try { - Profile[] cnsns = AAFrequency.calculate(sequences, startRes, + ProfilesI cnsns = AAFrequency.calculate(sequences, startRes, endRes + 1, showSequenceLogo); if (consensus != null) { @@ -544,8 +548,8 @@ public class SequenceGroup implements AnnotatedCollectionI if ((conservation != null) || (cs != null && cs.conservationApplied())) { - Conservation c = new Conservation(groupName, 3, sequences, - startRes, endRes + 1); + Conservation c = new Conservation(groupName, sequences, startRes, + endRes + 1); c.calculate(); c.verdict(false, consPercGaps); if (conservation != null) @@ -600,9 +604,9 @@ public class SequenceGroup implements AnnotatedCollectionI c.completeAnnotations(conservation, null, startRes, endRes + 1); } - public Profile[] consensusData = null; + public ProfilesI consensusData = null; - private void _updateConsensusRow(Profile[] cnsns, long nseq) + private void _updateConsensusRow(ProfilesI cnsns, long nseq) { if (consensus == null) { @@ -1270,10 +1274,14 @@ public class SequenceGroup implements AnnotatedCollectionI @Override public Iterable findAnnotation(String calcId) { - ArrayList aa = new ArrayList(); + List aa = new ArrayList(); + if (calcId == null) + { + return aa; + } for (AlignmentAnnotation a : getAlignmentAnnotation()) { - if (a.getCalcId() == calcId) + if (calcId.equals(a.getCalcId())) { aa.add(a); } @@ -1339,13 +1347,25 @@ public class SequenceGroup implements AnnotatedCollectionI private AnnotatedCollectionI context; /** - * set the alignment or group context for this group + * Sets the alignment or group context for this group * - * @param context + * @param ctx + * @throws IllegalArgumentException + * if setting the context would result in a circular reference chain */ - public void setContext(AnnotatedCollectionI context) + public void setContext(AnnotatedCollectionI ctx) { - this.context = context; + AnnotatedCollectionI ref = ctx; + while (ref != null) + { + if (ref == this) + { + throw new IllegalArgumentException( + "Circular reference in SequenceGroup.context"); + } + ref = ref.getContext(); + } + this.context = ctx; } /* @@ -1358,4 +1378,57 @@ public class SequenceGroup implements AnnotatedCollectionI { return context; } + + public void setColourScheme(ColourSchemeI scheme) + { + if (cs == null) + { + cs = new ResidueShader(); + } + cs.setColourScheme(scheme); + } + + public void setGroupColourScheme(ResidueShaderI scheme) + { + cs = scheme; + } + + public ColourSchemeI getColourScheme() + { + return cs == null ? null : cs.getColourScheme(); + } + + public ResidueShaderI getGroupColourScheme() + { + return cs; + } + + @Override + public boolean isNucleotide() + { + if (context != null) { + return context.isNucleotide(); + } + return false; + } + + /** + * @param seq + * @return true if seq is a member of the group + */ + + public boolean contains(SequenceI seq1) + { + return sequences.contains(seq1); + } + + /** + * @param seq + * @param apos + * @return true if startRes<=apos and endRes>=apos and seq is in the group + */ + public boolean contains(SequenceI seq, int apos) + { + return (startRes <= apos && endRes >= apos) && sequences.contains(seq); + } }