import jalview.analysis.AlignSeq;
import jalview.api.DBRefEntryI;
+import jalview.datamodel.features.SequenceFeatures;
+import jalview.datamodel.features.SequenceFeaturesI;
import jalview.util.Comparison;
import jalview.util.DBRefUtils;
import jalview.util.MapList;
import java.util.List;
import java.util.Vector;
+import com.stevesoft.pat.Regex;
+
import fr.orsay.lri.varna.models.rna.RNA;
/**
*/
public class Sequence extends ASequence implements SequenceI
{
+ private static final Regex limitrx = new Regex(
+ "[/][0-9]{1,}[-][0-9]{1,}$");
+
+ private static final Regex endrx = new Regex("[0-9]{1,}$");
+
SequenceI datasetSequence;
String name;
/** array of sequence features - may not be null for a valid sequence object */
public SequenceFeature[] sequenceFeatures;
+ private SequenceFeatures sequenceFeatureStore;
+
/**
* Creates a new Sequence object.
*
this.sequence = sequence2;
this.start = start2;
this.end = end2;
+ sequenceFeatureStore = new SequenceFeatures();
parseId();
checkValidRange();
}
- com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
- "[/][0-9]{1,}[-][0-9]{1,}$");
-
- com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
-
void parseId()
{
if (name == null)
protected void initSeqFrom(SequenceI seq,
AlignmentAnnotation[] alAnnotation)
{
- {
- char[] oseq = seq.getSequence();
- initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
- seq.getStart(), seq.getEnd());
- }
+ char[] oseq = seq.getSequence();
+ initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
+ seq.getStart(), seq.getEnd());
+
description = seq.getDescription();
if (seq != datasetSequence)
{
setDatasetSequence(seq.getDatasetSequence());
}
- if (datasetSequence == null && seq.getDBRefs() != null)
+
+ /*
+ * only copy DBRefs and seqfeatures if we really are a dataset sequence
+ */
+ if (datasetSequence == null)
{
- // only copy DBRefs and seqfeatures if we really are a dataset sequence
- DBRefEntry[] dbr = seq.getDBRefs();
- for (int i = 0; i < dbr.length; i++)
+ if (seq.getDBRefs() != null)
{
- addDBRef(new DBRefEntry(dbr[i]));
+ DBRefEntry[] dbr = seq.getDBRefs();
+ for (int i = 0; i < dbr.length; i++)
+ {
+ addDBRef(new DBRefEntry(dbr[i]));
+ }
}
if (seq.getSequenceFeatures() != null)
{
}
}
}
+
if (seq.getAnnotation() != null)
{
AlignmentAnnotation[] sqann = seq.getAnnotation();
}
@Override
- public synchronized void addSequenceFeature(SequenceFeature sf)
+ public synchronized boolean addSequenceFeature(SequenceFeature sf)
{
+ if (sf.getType() == null)
+ {
+ System.err.println("SequenceFeature type may not be null: "
+ + sf.toString());
+ return false;
+ }
+
if (sequenceFeatures == null && datasetSequence != null)
{
- datasetSequence.addSequenceFeature(sf);
- return;
+ return datasetSequence.addSequenceFeature(sf);
}
if (sequenceFeatures == null)
{
{
if (sequenceFeatures[i].equals(sf))
{
- return;
+ return false;
}
}
temp[sequenceFeatures.length] = sf;
sequenceFeatures = temp;
+
+ sequenceFeatureStore.add(sf);
+ return true;
}
@Override
return;
}
+ /*
+ * new way
+ */
+ sequenceFeatureStore.delete(sf);
+
+ /*
+ * old way - to be removed
+ */
int index = 0;
for (index = 0; index < sequenceFeatures.length; index++)
{
}
@Override
+ public SequenceFeaturesI getFeatures()
+ {
+ return datasetSequence != null ? datasetSequence.getFeatures()
+ : sequenceFeatureStore;
+ }
+
+ @Override
public boolean addPDBId(PDBEntry entry)
{
if (pdbIds == null)
// move features and database references onto dataset sequence
dsseq.sequenceFeatures = sequenceFeatures;
sequenceFeatures = null;
+ dsseq.sequenceFeatureStore = sequenceFeatureStore;
+ sequenceFeatureStore = null;
dsseq.dbrefs = dbrefs;
dbrefs = null;
// TODO: search and replace any references to this sequence with
return null;
}
- Vector subset = new Vector();
- Enumeration e = annotation.elements();
+ Vector<AlignmentAnnotation> subset = new Vector<AlignmentAnnotation>();
+ Enumeration<AlignmentAnnotation> e = annotation.elements();
while (e.hasMoreElements())
{
- AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
+ AlignmentAnnotation ann = e.nextElement();
if (ann.label != null && ann.label.equals(label))
{
subset.addElement(ann);
e = subset.elements();
while (e.hasMoreElements())
{
- anns[i++] = (AlignmentAnnotation) e.nextElement();
+ anns[i++] = e.nextElement();
}
subset.removeAllElements();
return anns;
// transfer PDB entries
if (entry.getAllPDBEntries() != null)
{
- Enumeration e = entry.getAllPDBEntries().elements();
+ Enumeration<PDBEntry> e = entry.getAllPDBEntries().elements();
while (e.hasMoreElements())
{
- PDBEntry pdb = (PDBEntry) e.nextElement();
+ PDBEntry pdb = e.nextElement();
addPDBId(pdb);
}
}
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<SequenceFeature> findFeatures(int from, int to,
+ String... types)
+ {
+ if (datasetSequence != null)
+ {
+ return datasetSequence.findFeatures(from, to, types);
+ }
+ return sequenceFeatureStore.findFeatures(from, to, types);
+ }
}