import fr.orsay.lri.varna.models.rna.RNA;
import jalview.analysis.AlignSeq;
+import jalview.analysis.AlignmentUtils;
+import jalview.analysis.SeqsetUtils;
import jalview.datamodel.features.SequenceFeatures;
import jalview.datamodel.features.SequenceFeaturesI;
import jalview.util.Comparison;
{
// only copy the given annotation
AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
+ ContactMatrixI cm = seq.getContactMatrixFor(sqann[i]);
+ if (cm!=null)
+ {
+ addContactListFor(newann, cm);
+ }
addAlignmentAnnotation(newann);
}
}
// sequence-column mapping
datasetSequence.addAlignmentAnnotation(_aa);
- // transfer contact matrices
- ContactMatrixI cm = getContactMatrixFor(aa);
- if (cm != null)
- {
- datasetSequence.addContactListFor(_aa, cm);
+ if (_cmholder != null)
+ { // transfer contact matrices
+ ContactMatrixI cm = _cmholder.getContactMatrixFor(aa);
+ if (cm != null)
+ {
+ datasetSequence.addContactListFor(_aa, cm);
+ datasetSequence.addContactListFor(aa, cm);
+ }
}
}
}
+ // all matrices should have been transferred. so we clear the local holder
+ _cmholder=null;
}
return datasetSequence;
}
////
//// Contact Matrix Holder Boilerplate
////
- ContactMapHolderI cmholder = new ContactMapHolder();
+ ContactMapHolderI _cmholder = null;
+ private ContactMapHolderI getContactMapHolder()
+ {
+ if (datasetSequence!=null) {
+ return ((Sequence)datasetSequence).getContactMapHolder();
+ }
+ if (_cmholder==null)
+ {
+ _cmholder=new ContactMapHolder();
+ }
+ return _cmholder;
+ }
@Override
public Collection<ContactMatrixI> getContactMaps()
{
- return cmholder.getContactMaps();
+ return getContactMapHolder().getContactMaps();
}
@Override
public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
{
- return cmholder.getContactMatrixFor(ann);
+ return getContactMapHolder().getContactMatrixFor(ann);
}
@Override
public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
{
- return cmholder.getContactListFor(_aa, column);
+ return getContactMapHolder().getContactListFor(_aa, column);
}
@Override
public AlignmentAnnotation addContactList(ContactMatrixI cm)
{
- AlignmentAnnotation aa = cmholder.addContactList(cm);
+ AlignmentAnnotation aa;
+
+ if (datasetSequence != null)
+ {
+ aa = datasetSequence.addContactList(cm);
+ // clone the annotation for the local sequence
+ aa = new AlignmentAnnotation(aa);
+ aa.restrict(start, end);
+ aa.adjustForAlignment();
+ getContactMapHolder().addContactListFor(aa,cm);
+ addAlignmentAnnotation(aa);
+ return aa;
+ }
+
+ // construct new annotation for matrix on dataset sequence
+ aa = getContactMapHolder().addContactList(cm);
Annotation _aa[] = new Annotation[getLength()];
public void addContactListFor(AlignmentAnnotation annotation,
ContactMatrixI cm)
{
- cmholder.addContactListFor(annotation, cm);
+ getContactMapHolder().addContactListFor(annotation, cm);
}
}
newannot.restrict(startRes, endRes);
newannot.setSequenceRef(seqs[ipos]);
newannot.adjustForAlignment();
+ ContactMatrixI cm = seq.getContactMatrixFor(seq.getAnnotation()[a]);
+ if (cm!=null)
+ {
+ seqs[ipos].addContactListFor(newannot, cm);
+ }
seqipos.addAlignmentAnnotation(newannot);
}
}
/**
* Derive a sequence (using this one's dataset or as the dataset)
*
- * @return duplicate sequence with valid dataset sequence
+ * @return duplicate sequence and any annotation present with valid dataset sequence
*/
public SequenceI deriveSequence();
.intValue();
}
}
- alignment.addAnnotation(sequences[i].getAnnotation()[a]); // annotation
- // was
- // duplicated
- // earlier
+ // annotation was duplicated earlier
+ alignment.addAnnotation(sequences[i].getAnnotation()[a]);
+ // take care of contact matrix too
+ ContactMatrixI cm=sequences[i].getContactMatrixFor(sequences[i].getAnnotation()[a]);
+ if (cm!=null)
+ {
+ alignment.addContactListFor(sequences[i].getAnnotation()[a], cm);
+ }
+
alignment.setAnnotationIndex(sequences[i].getAnnotation()[a],
a);
}
assertEquals("ABCDEF",
derived.getDatasetSequence().getSequenceAsString());
}
+
+ /**
+ * test that creating a copy of an existing sequence with dataset sequence and
+ * associated contact matrix yields annotation associated with the same
+ * contact matrix in the copy
+ */
+ @Test(groups= {"Functional"})
+ public void testCopyPasteStyleDerivesequence_withcontactMatrixAnn()
+ {
+ SequenceI seq1=new Sequence("seq1","ACDACDACD");
+ seq1.createDatasetSequence();
+ ContactMatrixI cm = new SeqDistanceContactMatrix(seq1.getLength());
+ // addContactList needs to return annotation addable to the sequence reference it was called from
+ AlignmentAnnotation aann = seq1.addContactList(cm);
+ assertTrue(aann.sequenceRef==seq1);
+ assertEquals(1,seq1.getAnnotation().length);
+ assertNotNull(seq1.getContactListFor(seq1.getAnnotation()[0], 1));
+
+ SequenceI seq_derived=seq1.deriveSequence();
+ assertEquals(1,seq_derived.getAnnotation().length);
+ assertTrue(cm==seq_derived.getContactMatrixFor(seq_derived.getAnnotation()[0]));
+ assertNotNull(seq_derived.getContactListFor(seq_derived.getAnnotation()[0], 1));
+
+ // copy paste actually uses the copy constructor .. so
+
+ SequenceI seq_copied=new Sequence((Sequence)seq_derived);
+ assertEquals(1,seq_copied.getAnnotation().length);
+ assertTrue(cm==seq_copied.getContactMatrixFor(seq_copied.getAnnotation()[0]));
+ assertNotNull(seq_copied.getContactListFor(seq_copied.getAnnotation()[0], 1));
+
+
+ }
@Test(groups = { "Functional" })
public void testCopyConstructor_noDataset()
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.Annotation;
+import jalview.datamodel.ContactMatrixI;
import jalview.datamodel.SearchResults;
import jalview.datamodel.SearchResultsI;
+import jalview.datamodel.SeqDistanceContactMatrix;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
assertEquals(0, ranges.getStartSeq());
assertEquals(2, ranges.getEndSeq());
}
+ @Test(groups = {"Functional"})
+ public void testGetSelectionAsNewSequences_withContactMatrices()
+ {
+ SequenceI seq = new Sequence("seq","ACADA");
+ ContactMatrixI cmat = new SeqDistanceContactMatrix(5);
+ seq.addContactList(cmat);
+ Alignment al = new Alignment(new SequenceI[] {seq.deriveSequence() });
+ al.addAnnotation(al.getSequenceAt(0).getAnnotation()[0]);
+ AlignFrame af = new AlignFrame(al,500,500);
+
+ SequenceI selseqs[] = af.getViewport().getSelectionAsNewSequence();
+ assertNotNull(selseqs[0].getAnnotation());
+ assertNotNull(selseqs[0].getAnnotation()[0]);
+ assertEquals(cmat,selseqs[0].getContactMatrixFor(selseqs[0].getAnnotation()[0]));
+
+ assertNotNull(selseqs[0].getContactListFor(selseqs[0].getAnnotation()[0], 2));
+
+ // now select everything and test again
+ af.selectAllSequenceMenuItem_actionPerformed(null);
+ selseqs = af.getViewport().getSelectionAsNewSequence();
+ assertNotNull(selseqs[0].getAnnotation());
+ assertNotNull(selseqs[0].getAnnotation()[0]);
+ assertEquals(cmat,selseqs[0].getContactMatrixFor(selseqs[0].getAnnotation()[0]));
+ assertNotNull(selseqs[0].getContactListFor(selseqs[0].getAnnotation()[0], 2));
+ }
}