JAL-1492 JAL-1397 JAL-643 JAL-969 factory method to clone and apply colour scheme...
authorJim Procter <jprocter@dundee.ac.uk>
Thu, 1 May 2014 14:29:31 +0000 (15:29 +0100)
committerJim Procter <jprocter@dundee.ac.uk>
Thu, 1 May 2014 14:31:49 +0000 (15:31 +0100)
src/jalview/schemes/AnnotationColourGradient.java
src/jalview/schemes/Blosum62ColourScheme.java
src/jalview/schemes/ClustalxColourScheme.java
src/jalview/schemes/ColourSchemeI.java
src/jalview/schemes/ResidueColourScheme.java
src/jalview/schemes/TCoffeeColourScheme.java
src/jalview/schemes/UserColourScheme.java

index c3357ad..f619d07 100755 (executable)
@@ -51,7 +51,27 @@ public class AnnotationColourGradient extends FollowerColourScheme
   private boolean seqAssociated = false;
 
   IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
-
+  @Override
+  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+          Map<SequenceI, SequenceCollectionI> 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.
    */
index ad0e0c0..b43afec 100755 (executable)
@@ -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<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  { 
+    ColourSchemeI newcs = super.applyTo(sg, hiddenRepSequences);
+    return newcs;
+  }
 }
index 62c94d8..77d7e5b 100755 (executable)
@@ -327,6 +327,14 @@ public class ClustalxColourScheme extends ResidueColourScheme // implements
   {
     this.includeGaps = includeGaps;
   }
+  @Override
+  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  {
+    ClustalxColourScheme css= new ClustalxColourScheme(sg, hiddenRepSequences);
+    css.includeGaps = includeGaps;
+    return css;
+  }
 }
 
 class ConsensusColour
index 3f73fc9..536efe7 100755 (executable)
@@ -100,4 +100,13 @@ public interface ColourSchemeI
   public void alignmentChanged(AnnotatedCollectionI alignment,
           Map<SequenceI, SequenceCollectionI> 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<SequenceI, SequenceCollectionI> hiddenRepSequences);
+
 }
index 424947c..8b3150b 100755 (executable)
@@ -311,4 +311,16 @@ public class ResidueColourScheme implements ColourSchemeI
   {
   }
 
+  @Override
+  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  {
+    try {
+      return getClass().newInstance();
+    }
+    catch (Exception q)
+    {
+      throw new Error("Serious implementation error: cannot duplicate colourscheme "+getClass().getName(), q);
+    }
+  }
 }
index 6eb48c2..38d1200 100644 (file)
@@ -129,4 +129,11 @@ public class TCoffeeColourScheme extends ResidueColourScheme
     }
     return cols[j];
   }
+  
+  @Override
+  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+          Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
+  {
+    return new TCoffeeColourScheme(sg);
+  }
 }
index 82a5871..61aed43 100755 (executable)
 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<SequenceI, SequenceCollectionI> 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);