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;
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();
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);
}
}
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNotSame;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertSame;
import static org.testng.AssertJUnit.assertTrue;
import java.util.List;
import java.util.Vector;
+import junit.extensions.PA;
+
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@Test(groups = { "Functional" })
public void testDeleteChars()
{
+ /*
+ * internal delete
+ */
SequenceI sq = new Sequence("test", "ABCDEF");
+ assertNull(PA.getValue(sq, "datasetSequence"));
assertEquals(1, sq.getStart());
assertEquals(6, sq.getEnd());
sq.deleteChars(2, 3);
assertEquals("ABDEF", sq.getSequenceAsString());
assertEquals(1, sq.getStart());
assertEquals(5, sq.getEnd());
+ assertNull(PA.getValue(sq, "datasetSequence"));
+ /*
+ * delete at start
+ */
sq = new Sequence("test", "ABCDEF");
sq.deleteChars(0, 2);
assertEquals("CDEF", sq.getSequenceAsString());
assertEquals(3, sq.getStart());
assertEquals(6, sq.getEnd());
+ assertNull(PA.getValue(sq, "datasetSequence"));
+
+ /*
+ * delete at end
+ */
+ sq = new Sequence("test", "ABCDEF");
+ sq.deleteChars(4, 6);
+ assertEquals("ABCD", sq.getSequenceAsString());
+ assertEquals(1, sq.getStart());
+ assertEquals(4, sq.getEnd());
+ assertNull(PA.getValue(sq, "datasetSequence"));
+ }
+
+ @Test(groups = { "Functional" })
+ public void testDeleteChars_withDbRefsAndFeatures()
+ {
+ /*
+ * internal delete - new dataset sequence created
+ * gets a copy of any dbrefs
+ */
+ SequenceI sq = new Sequence("test", "ABCDEF");
+ sq.createDatasetSequence();
+ DBRefEntry dbr1 = new DBRefEntry("Uniprot", "0", "a123");
+ sq.addDBRef(dbr1);
+ Object ds = PA.getValue(sq, "datasetSequence");
+ assertNotNull(ds);
+ assertEquals(1, sq.getStart());
+ assertEquals(6, sq.getEnd());
+ sq.deleteChars(2, 3);
+ assertEquals("ABDEF", sq.getSequenceAsString());
+ assertEquals(1, sq.getStart());
+ assertEquals(5, sq.getEnd());
+ Object newDs = PA.getValue(sq, "datasetSequence");
+ assertNotNull(newDs);
+ assertNotSame(ds, newDs);
+ assertNotNull(sq.getDBRefs());
+ assertEquals(1, sq.getDBRefs().length);
+ assertNotSame(dbr1, sq.getDBRefs()[0]);
+ assertEquals(dbr1, sq.getDBRefs()[0]);
+
+ /*
+ * internal delete with sequence features
+ * (failure case for JAL-2541)
+ */
+ sq = new Sequence("test", "ABCDEF");
+ sq.createDatasetSequence();
+ SequenceFeature sf1 = new SequenceFeature("Cath", "desc", 2, 4, 2f,
+ "CathGroup");
+ sq.addSequenceFeature(sf1);
+ ds = PA.getValue(sq, "datasetSequence");
+ assertNotNull(ds);
+ assertEquals(1, sq.getStart());
+ assertEquals(6, sq.getEnd());
+ sq.deleteChars(2, 4);
+ assertEquals("ABEF", sq.getSequenceAsString());
+ assertEquals(1, sq.getStart());
+ assertEquals(4, sq.getEnd());
+ newDs = PA.getValue(sq, "datasetSequence");
+ assertNotNull(newDs);
+ assertNotSame(ds, newDs);
+ SequenceFeature[] sfs = sq.getSequenceFeatures();
+ assertNotNull(sfs);
+ assertEquals(1, sfs.length);
+ assertNotSame(sf1, sfs[0]);
+ assertEquals(sf1, sfs[0]);
+
+ /*
+ * delete at start - no new dataset sequence created
+ * any sequence features remain as before
+ */
+ sq = new Sequence("test", "ABCDEF");
+ sq.createDatasetSequence();
+ ds = PA.getValue(sq, "datasetSequence");
+ sf1 = new SequenceFeature("Cath", "desc", 2, 4, 2f, "CathGroup");
+ sq.addSequenceFeature(sf1);
+ sq.deleteChars(0, 2);
+ assertEquals("CDEF", sq.getSequenceAsString());
+ assertEquals(3, sq.getStart());
+ assertEquals(6, sq.getEnd());
+ assertSame(ds, PA.getValue(sq, "datasetSequence"));
+ sfs = sq.getSequenceFeatures();
+ assertNotNull(sfs);
+ assertEquals(1, sfs.length);
+ assertSame(sf1, sfs[0]);
+
+ /*
+ * delete at end - no new dataset sequence created
+ * any dbrefs remain as before
+ */
+ sq = new Sequence("test", "ABCDEF");
+ sq.createDatasetSequence();
+ ds = PA.getValue(sq, "datasetSequence");
+ dbr1 = new DBRefEntry("Uniprot", "0", "a123");
+ sq.addDBRef(dbr1);
+ sq.deleteChars(4, 6);
+ assertEquals("ABCD", sq.getSequenceAsString());
+ assertEquals(1, sq.getStart());
+ assertEquals(4, sq.getEnd());
+ assertSame(ds, PA.getValue(sq, "datasetSequence"));
+ assertNotNull(sq.getDBRefs());
+ assertEquals(1, sq.getDBRefs().length);
+ assertSame(dbr1, sq.getDBRefs()[0]);
}
@Test(groups = { "Functional" })