JAL-653 allow a dummy sequence to take on attributes from a fully instantiated sequen...
authorJim Procter <jprocter@issues.jalview.org>
Sat, 6 Jun 2015 16:46:27 +0000 (17:46 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Sat, 6 Jun 2015 16:53:49 +0000 (17:53 +0100)
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceDummy.java

index 257c894..7efd4ae 100755 (executable)
@@ -90,20 +90,30 @@ public class Sequence extends ASequence implements SequenceI
    */
   public Sequence(String name, String sequence, int start, int end)
   {
-    this.name = name;
-    this.sequence = sequence.toCharArray();
-    this.start = start;
-    this.end = end;
-    parseId();
-    checkValidRange();
+    initSeqAndName(name, sequence.toCharArray(), start, end);
   }
 
   public Sequence(String name, char[] sequence, int start, int end)
   {
-    this.name = name;
-    this.sequence = sequence;
-    this.start = start;
-    this.end = end;
+    initSeqAndName(name, sequence, start, end);
+  }
+
+  /**
+   * Stage 1 constructor - assign name, sequence, and set start and end fields.
+   * start and end are updated values from name2 if it ends with /start-end
+   * 
+   * @param name2
+   * @param sequence2
+   * @param start2
+   * @param end2
+   */
+  protected void initSeqAndName(String name2, char[] sequence2, int start2,
+          int end2)
+  {
+    this.name = name2;
+    this.sequence = sequence2;
+    this.start = start2;
+    this.end = end2;
     parseId();
     checkValidRange();
   }
@@ -196,7 +206,15 @@ public class Sequence extends ASequence implements SequenceI
    */
   public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
   {
-    this(seq.getName(), seq.getSequence(), seq.getStart(), seq.getEnd());
+    initSeqFrom(seq, alAnnotation);
+
+  }
+
+  protected void initSeqFrom(SequenceI seq,
+          AlignmentAnnotation[] alAnnotation)
+  {
+    initSeqAndName(seq.getName(), seq.getSequence(), seq.getStart(),
+            seq.getEnd());
     description = seq.getDescription();
     if (seq.getSequenceFeatures() != null)
     {
index 80b0072..4a8c3ee 100644 (file)
@@ -6,4 +6,27 @@ public class SequenceDummy extends Sequence implements SequenceI
   {
     super(sequenceId, "THISAPLACEHOLDER");
   }
+
+  private boolean dummy = true;
+  /**
+   * become a proxy for mseq, merging any existing annotation on this sequence
+   * 
+   * @param mseq
+   */
+  public void become(SequenceI mseq)
+  {
+    initSeqFrom(mseq, null);
+    dummy=false;
+  }
+
+  /**
+   * Test if the SequenceDummy has been promoted to a real sequence via
+   * SequenceDummy.become
+   * 
+   * @return true if this is a placeholder and contains no actual sequence data
+   */
+  public boolean isDummy()
+  {
+    return dummy;
+  }
 }