import jalview.util.StringUtils;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
}
/**
- * Creates a new Sequence object with new features, DBRefEntries,
- * AlignmentAnnotations, and PDBIds but inherits any existing dataset sequence
- * reference.
+ * Creates a new Sequence object with new AlignmentAnnotations but inherits
+ * any existing dataset sequence reference. If non exists, everything is
+ * copied.
*
* @param seq
- * DOCUMENT ME!
+ * if seq is a dataset sequence, behaves like a plain old copy
+ * constructor
*/
public Sequence(SequenceI seq)
{
}
+ /**
+ * does the heavy lifting when cloning a dataset sequence, or coping data from
+ * dataset to a new derived sequence.
+ *
+ * @param seq
+ * - source of attributes.
+ * @param alAnnotation
+ * - alignment annotation present on seq that should be copied onto
+ * this sequence
+ */
protected void initSeqFrom(SequenceI seq,
AlignmentAnnotation[] alAnnotation)
{
- initSeqAndName(seq.getName(), seq.getSequence(), seq.getStart(),
+ {
+ char[] oseq = seq.getSequence();
+ initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
+ seq.getStart(),
seq.getEnd());
+ }
description = seq.getDescription();
sourceDBRef = seq.getSourceDBRef() == null ? null : new DBRefEntry(
seq.getSourceDBRef());
- if (seq.getSequenceFeatures() != null)
+ if (seq != datasetSequence)
{
- SequenceFeature[] sf = seq.getSequenceFeatures();
- for (int i = 0; i < sf.length; i++)
- {
- addSequenceFeature(new SequenceFeature(sf[i]));
- }
+ setDatasetSequence(seq.getDatasetSequence());
}
- setDatasetSequence(seq.getDatasetSequence());
if (datasetSequence == null && seq.getDBRefs() != null)
{
- // only copy DBRefs if we really are a dataset sequence
+ // only copy DBRefs and seqfeatures if we really are a dataset sequence
DBRefEntry[] dbr = seq.getDBRefs();
for (int i = 0; i < dbr.length; i++)
{
addDBRef(new DBRefEntry(dbr[i]));
}
+ if (seq.getSequenceFeatures() != null)
+ {
+ SequenceFeature[] sf = seq.getSequenceFeatures();
+ for (int i = 0; i < sf.length; i++)
+ {
+ addSequenceFeature(new SequenceFeature(sf[i]));
+ }
+ }
}
if (seq.getAnnotation() != null)
{
}
}
- /**
- * DOCUMENT ME!
- *
- * @param v
- * DOCUMENT ME!
- */
+
@Override
public void setSequenceFeatures(SequenceFeature[] features)
{
- sequenceFeatures = features;
+ if (datasetSequence == null)
+ {
+ sequenceFeatures = features;
+ }
+ else
+ {
+ System.err
+ .println("Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment");
+ datasetSequence.setSequenceFeatures(features);
+ }
}
@Override
public synchronized void addSequenceFeature(SequenceFeature sf)
{
- // TODO add to dataset sequence instead if there is one?
+ if (sequenceFeatures==null && datasetSequence != null)
+ {
+ datasetSequence.addSequenceFeature(sf);
+ return;
+ }
if (sequenceFeatures == null)
{
sequenceFeatures = new SequenceFeature[0];
{
if (sequenceFeatures == null)
{
+ if (datasetSequence!=null) {
+ datasetSequence.deleteFeature(sf);
+ }
return;
}
@Override
public SequenceI deriveSequence()
{
- SequenceI seq = new Sequence(this);
- if (datasetSequence != null)
- {
- // duplicate current sequence with same dataset
- seq.setDatasetSequence(datasetSequence);
- }
- else
+ Sequence seq=null;
+ if (datasetSequence == null)
{
if (isValidDatasetSequence())
{
// Use this as dataset sequence
+ seq = new Sequence(getName(), "", 1, -1);
seq.setDatasetSequence(this);
+ seq.initSeqFrom(this, getAnnotation());
+ return seq;
}
else
{
// Create a new, valid dataset sequence
- SequenceI ds = seq;
- ds.setSequence(AlignSeq.extractGaps(
- jalview.util.Comparison.GapChars, new String(sequence)));
- setDatasetSequence(ds);
- ds.setSequenceFeatures(getSequenceFeatures());
- seq = this; // and return this sequence as the derived sequence.
+ createDatasetSequence();
}
}
- return seq;
+ return new Sequence(this);
}
/*