+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int replace(char c1, char c2)
+ {
+ if (c1 == c2)
+ {
+ return 0;
+ }
+ int count = 0;
+ synchronized (sequence)
+ {
+ for (int c = 0; c < sequence.length; c++)
+ {
+ if (sequence[c] == c1)
+ {
+ sequence[c] = c2;
+ count++;
+ }
+ }
+ }
+ if (count > 0)
+ {
+ sequenceChanged();
+ }
+
+ return count;
+ }
+
+ @Override
+ public String getSequenceStringFromIterator(Iterator<int[]> it)
+ {
+ StringBuilder newSequence = new StringBuilder();
+ while (it.hasNext())
+ {
+ int[] block = it.next();
+ if (it.hasNext())
+ {
+ newSequence.append(getSequence(block[0], block[1] + 1));
+ }
+ else
+ {
+ newSequence.append(getSequence(block[0], block[1]));
+ }
+ }
+
+ return newSequence.toString();
+ }
+
+ @Override
+ public int firstResidueOutsideIterator(Iterator<int[]> regions)
+ {
+ int start = 0;
+
+ if (!regions.hasNext())
+ {
+ return findIndex(getStart()) - 1;
+ }
+
+ // Simply walk along the sequence whilst watching for region
+ // boundaries
+ int hideStart = getLength();
+ int hideEnd = -1;
+ boolean foundStart = false;
+
+ // step through the non-gapped positions of the sequence
+ for (int i = getStart(); i <= getEnd() && (!foundStart); i++)
+ {
+ // get alignment position of this residue in the sequence
+ int p = findIndex(i) - 1;
+
+ // update region start/end
+ while (hideEnd < p && regions.hasNext())
+ {
+ int[] region = regions.next();
+ hideStart = region[0];
+ hideEnd = region[1];
+ }
+ if (hideEnd < p)
+ {
+ hideStart = getLength();
+ }
+ // update boundary for sequence
+ if (p < hideStart)
+ {
+ start = p;
+ foundStart = true;
+ }
+ }
+
+ if (foundStart)
+ {
+ return start;
+ }
+ // otherwise, sequence was completely hidden
+ return 0;
+ }
+
+ ////
+ //// Contact Matrix Holder Boilerplate
+ ////
+ 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 getContactMapHolder().getContactMaps();
+ }
+
+ @Override
+ public ContactMatrixI getContactMatrixFor(AlignmentAnnotation ann)
+ {
+ return getContactMapHolder().getContactMatrixFor(ann);
+ }
+
+ @Override
+ public ContactListI getContactListFor(AlignmentAnnotation _aa, int column)
+ {
+ return getContactMapHolder().getContactListFor(_aa, column);
+ }
+
+ @Override
+ public AlignmentAnnotation addContactList(ContactMatrixI 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()];
+
+ for (int i = 0; i < _aa.length; _aa[i++] = new Annotation(0.0f))
+ {
+ ;
+ }
+ aa.annotations = _aa;
+ aa.setSequenceRef(this);
+ if (cm instanceof MappableContactMatrix
+ && !((MappableContactMatrix) cm).hasReferenceSeq())
+ {
+ ((MappableContactMatrix) cm).setRefSeq(this);
+ }
+ aa.createSequenceMapping(this, getStart(), false);
+ addAlignmentAnnotation(aa);
+ return aa;
+ }
+
+ @Override
+ public void addContactListFor(AlignmentAnnotation annotation,
+ ContactMatrixI cm)
+ {
+ getContactMapHolder().addContactListFor(annotation, cm);
+ }