From 24e842ef4b4fa929644b6ab4f79c7b61575c7b55 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Sat, 6 Jun 2015 17:46:27 +0100 Subject: [PATCH] JAL-653 allow a dummy sequence to take on attributes from a fully instantiated sequence via Sequence copy constructor --- src/jalview/datamodel/Sequence.java | 40 ++++++++++++++++++++++-------- src/jalview/datamodel/SequenceDummy.java | 23 +++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 257c894..7efd4ae 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -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) { diff --git a/src/jalview/datamodel/SequenceDummy.java b/src/jalview/datamodel/SequenceDummy.java index 80b0072..4a8c3ee 100644 --- a/src/jalview/datamodel/SequenceDummy.java +++ b/src/jalview/datamodel/SequenceDummy.java @@ -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; + } } -- 1.7.10.2