From: Jim Procter Date: Thu, 1 May 2014 14:29:31 +0000 (+0100) Subject: JAL-1492 JAL-1397 JAL-643 JAL-969 factory method to clone and apply colour scheme... X-Git-Tag: Jalview_2_9~190^2~10 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=50eb1f492f5c64b56594ee49be8183fab8a2f73b;p=jalview.git JAL-1492 JAL-1397 JAL-643 JAL-969 factory method to clone and apply colour scheme to another alignment/group --- diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index c3357ad..f619d07 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -51,7 +51,27 @@ public class AnnotationColourGradient extends FollowerColourScheme private boolean seqAssociated = false; IdentityHashMap seqannot = null; - + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + AnnotationColourGradient acg = new AnnotationColourGradient(annotation, colourScheme, aboveAnnotationThreshold); + acg.thresholdIsMinMax = thresholdIsMinMax; + acg.annotationThreshold = (annotationThreshold==null) ? null : new GraphLine(annotationThreshold); + acg.r1 = r1; + acg.g1 = g1; + acg.b1 = b1; + acg.rr = rr; + acg.gg = gg; + acg.bb = bb; + acg.dr = dr; + acg.dg = dg; + acg.db = db; + acg.predefinedColours = predefinedColours; + acg.seqAssociated = seqAssociated; + + return acg; + } /** * Creates a new AnnotationColourGradient object. */ diff --git a/src/jalview/schemes/Blosum62ColourScheme.java b/src/jalview/schemes/Blosum62ColourScheme.java index ad0e0c0..b43afec 100755 --- a/src/jalview/schemes/Blosum62ColourScheme.java +++ b/src/jalview/schemes/Blosum62ColourScheme.java @@ -21,6 +21,10 @@ package jalview.schemes; import jalview.analysis.AAFrequency; import java.awt.Color; +import java.util.Map; + +import jalview.datamodel.AnnotatedCollectionI; +import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; public class Blosum62ColourScheme extends ResidueColourScheme @@ -88,4 +92,11 @@ public class Blosum62ColourScheme extends ResidueColourScheme return currentColour; } + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences); + return newcs; + } } diff --git a/src/jalview/schemes/ClustalxColourScheme.java b/src/jalview/schemes/ClustalxColourScheme.java index 62c94d8..77d7e5b 100755 --- a/src/jalview/schemes/ClustalxColourScheme.java +++ b/src/jalview/schemes/ClustalxColourScheme.java @@ -327,6 +327,14 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements { this.includeGaps = includeGaps; } + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + ClustalxColourScheme css= new ClustalxColourScheme(sg, hiddenRepSequences); + css.includeGaps = includeGaps; + return css; + } } class ConsensusColour diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java index 3f73fc9..536efe7 100755 --- a/src/jalview/schemes/ColourSchemeI.java +++ b/src/jalview/schemes/ColourSchemeI.java @@ -100,4 +100,13 @@ public interface ColourSchemeI public void alignmentChanged(AnnotatedCollectionI alignment, Map hiddenReps); + /** + * create a new instance of the colourscheme configured to colour the given connection + * @param sg + * @param hiddenRepSequences + * @return copy of current scheme with any inherited settings transfered + */ + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences); + } diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index 424947c..8b3150b 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -311,4 +311,16 @@ public class ResidueColourScheme implements ColourSchemeI { } + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + try { + return getClass().newInstance(); + } + catch (Exception q) + { + throw new Error("Serious implementation error: cannot duplicate colourscheme "+getClass().getName(), q); + } + } } diff --git a/src/jalview/schemes/TCoffeeColourScheme.java b/src/jalview/schemes/TCoffeeColourScheme.java index 6eb48c2..38d1200 100644 --- a/src/jalview/schemes/TCoffeeColourScheme.java +++ b/src/jalview/schemes/TCoffeeColourScheme.java @@ -129,4 +129,11 @@ public class TCoffeeColourScheme extends ResidueColourScheme } return cols[j]; } + + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + return new TCoffeeColourScheme(sg); + } } diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 82a5871..61aed43 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -19,7 +19,11 @@ package jalview.schemes; import java.awt.Color; +import java.util.Map; import java.util.StringTokenizer; + +import jalview.datamodel.AnnotatedCollectionI; +import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; public class UserColourScheme extends ResidueColourScheme @@ -38,7 +42,18 @@ public class UserColourScheme extends ResidueColourScheme super(ResidueProperties.aaIndex); colors = newColors; } - + @Override + public ColourSchemeI applyTo(AnnotatedCollectionI sg, + Map hiddenRepSequences) + { + UserColourScheme usc = new UserColourScheme(colors); + if (lowerCaseColours!=null) { + usc.schemeName = new String(schemeName); + usc.lowerCaseColours = new Color[lowerCaseColours.length]; + System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0, lowerCaseColours.length); + } + return usc; + } public UserColourScheme(String colour) { super(ResidueProperties.aaIndex);