X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2Fdatamodel%2Falphafold%2FMappableContactMatrix.java;h=5f27a2c170e0a0b487453968861d05c240bed25c;hb=cd669a0e8c7b91b379bca8fe6e702cf0fcbd1ce0;hp=dc8e0d3cb3c2adbbec97e3fea07f92625aeb0e5f;hpb=8288438dd58cfc2d1fe18a060afda0d647b85c32;p=jalview.git diff --git a/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java b/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java index dc8e0d3..5f27a2c 100644 --- a/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java +++ b/src/jalview/ws/datamodel/alphafold/MappableContactMatrix.java @@ -7,6 +7,7 @@ import java.util.BitSet; import jalview.datamodel.ContactListI; import jalview.datamodel.ContactListImpl; import jalview.datamodel.ContactListProviderI; +import jalview.datamodel.ContactMatrixI; import jalview.datamodel.GroupSet; import jalview.datamodel.GroupSetI; import jalview.datamodel.Mapping; @@ -14,9 +15,63 @@ import jalview.datamodel.SequenceI; import jalview.util.MapList; import jalview.ws.datamodel.MappableContactMatrixI; -public abstract class MappableContactMatrix> implements MappableContactMatrixI +public abstract class MappableContactMatrix> + implements MappableContactMatrixI { + /** + * the matrix that is being mapped to + */ + protected ContactMatrixI mappedMatrix=null; + + public ContactListI getContactList(int column) + { + return mappedMatrix.getContactList(column); + } + + public float getMin() + { + return mappedMatrix.getMin(); + } + + public float getMax() + { + return mappedMatrix.getMax(); + } + + public int getWidth() + { + return mappedMatrix.getWidth(); + } + + public int getHeight() + { + return mappedMatrix.getHeight(); + } + + @Override + public ContactMatrixI getMappedMatrix() + { + return mappedMatrix; + } + + @Override + public GroupSetI getGroupSet() + { + return mappedMatrix.getGroupSet(); + }; + + @Override + public void setGroupSet(GroupSet makeGroups) + { + mappedMatrix.setGroupSet(makeGroups); + } + + /** + * the sequence and how it is mapped to the matrix + */ + SequenceI refSeq = null; + MapList toSeq = null; /** @@ -24,7 +79,6 @@ public abstract class MappableContactMatrix> */ int length; - @Override public boolean hasReferenceSeq() { @@ -36,46 +90,37 @@ public abstract class MappableContactMatrix> { return refSeq; } - /** - * container for groups - defined on matrix columns - */ - GroupSet grps=new GroupSet(); - @Override - public GroupSetI getGroupSet() - { - return grps; - }; - @Override - public void setGroupSet(GroupSet makeGroups) - { - grps = makeGroups; - } @Override public MapList getMapFor(SequenceI mapSeq) { - if (refSeq!=null) + if (refSeq != null) { - while (mapSeq!=refSeq && mapSeq.getDatasetSequence()!=null) + while (mapSeq != refSeq && mapSeq.getDatasetSequence() != null) { mapSeq = mapSeq.getDatasetSequence(); } - if (mapSeq!=refSeq) + if (mapSeq != refSeq) { return null; } - } else { - if (mapSeq!=null) { + } + else + { + if (mapSeq != null) + { // our MapList does not concern this seq return null; } } - + return toSeq; } /** - * set the reference sequence and construct the mapping between the start-end positions of given sequence and row/columns of contact matrix + * set the reference sequence and construct the mapping between the start-end + * positions of given sequence and row/columns of contact matrix + * * @param _refSeq */ public void setRefSeq(SequenceI _refSeq) @@ -86,9 +131,13 @@ public abstract class MappableContactMatrix> refSeq = refSeq.getDatasetSequence(); } length = _refSeq.getEnd() - _refSeq.getStart() + 1; -// if (length!=refSeq.getLength() || _refSeq.getStart()!=1) + // if (length!=refSeq.getLength() || _refSeq.getStart()!=1) { - toSeq = new MapList(new int[] { _refSeq.getStart(), _refSeq.getEnd()}, new int[] { 0,length-1}, 1,1); + toSeq = new MapList( + new int[] + { _refSeq.getStart(), _refSeq.getEnd() }, + new int[] + { 0, length - 1 }, 1, 1); } } @@ -163,35 +212,27 @@ public abstract class MappableContactMatrix> return newCM; } - protected abstract T newMappableContactMatrix(SequenceI newRefSeq, + protected abstract T newMappableContactMatrix(SequenceI newRefSeq, MapList newFromMapList); + @Override public int[] getMappedPositionsFor(final SequenceI localFrame, final int column) { - return getMappedPositionsFor(localFrame,column,column); + return getMappedPositionsFor(localFrame, column, column); } - public int[] getMappedPositionsFor(final SequenceI localFrame, - int from,int to) + + @Override + public int[] getMappedPositionsFor(final SequenceI localFrame, int from, + int to) { - if (localFrame==null) + if (localFrame == null) { throw new Error("Unimplemented when no local sequence given."); } - // return a ContactListI for column - // column is index into localFrame - // 1. map column to corresponding column in matrix - - final int _lcolumn=localFrame.findPosition(from); - final int _rcolumn=(from==to) ? _lcolumn:localFrame.findPosition(to); - if (toSeq == null) - { - // no mapping - return new int[] { _lcolumn,_rcolumn}; - } - SequenceI lf = localFrame, uf = refSeq; + // check that localFrame is derived from refSeq // just look for dataset sequences and check they are the same. // in future we could use DBRefMappings/whatever. while (lf.getDatasetSequence() != null @@ -214,25 +255,44 @@ public abstract class MappableContactMatrix> + localFrame.getName() + ")"); } - int[] mappedPositions = toSeq.locateInFrom(_lcolumn,_rcolumn); - // TODO - trim to localFrame ? -// if (mappedPositions!=null) { -// int s=-1,e=-1; -// for (int p=0;p= localFrame.getStart()) // { -// if (s==-1 && mappedPositions[p]>=localFrame.getStart()) -// { -// s=p; // remember first position within local frame -// } -// if (e==-1 || mappedPositions[p]<=localFrame.getEnd()) -// { -// // update end pointer -// e=p; -// // compute local map -// mappedPositions[p] = localFrame.findIndex(mappedPositions[p]); -// } +// s = p; // remember first position within local frame +// } +// if (e == -1 || mappedPositions[p] <= localFrame.getEnd()) +// { +// // update end pointer +// e = p; +// // compute local map +// mappedPositions[p] = localFrame.findIndex(mappedPositions[p]); // } // } +// int[] _trimmed = new int[e - s + 1]; +// return _trimmed; return mappedPositions; } @@ -242,16 +302,16 @@ public abstract class MappableContactMatrix> { final int _column; final int _lcolumn; - if (localFrame==null) + if (localFrame == null) { throw new Error("Unimplemented when no local sequence given."); } // return a ContactListI for column // column is index into localFrame // 1. map column to corresponding column in matrix - final MappableContactMatrix us=this; - _lcolumn=localFrame.findPosition(column); - + final MappableContactMatrix us = this; + _lcolumn = localFrame.findPosition(column); + if (toSeq != null) { SequenceI lf = localFrame, uf = refSeq; @@ -287,11 +347,11 @@ public abstract class MappableContactMatrix> } else { - // no mapping + // no mapping _column = _lcolumn; } - // TODO - remove ? this may be a redundant check + // TODO - remove ? this may be a redundant check if (_column < 0 || ((toSeq != null && _column > toSeq.getToHighest()) || (toSeq == null && getHeight() <= _column))) { @@ -307,11 +367,11 @@ public abstract class MappableContactMatrix> int h = 0; for (int p = 0; p < matrixRange.length; p += 2) { - h += 1+Math.abs(matrixRange[p + 1] - matrixRange[p]); + h += 1 + Math.abs(matrixRange[p + 1] - matrixRange[p]); } final int rangeHeight = h; // 3. Construct ContactListImpl instance for just those segments. - + return new ContactListImpl(new ContactListProviderI() { @@ -403,6 +463,7 @@ public abstract class MappableContactMatrix> } return matrixRange[p] + mcolumn - h; } + @Override public Color getColourForGroup() { @@ -414,13 +475,37 @@ public abstract class MappableContactMatrix> } /** - * get a specific element of the contact matrix in its data-local coordinates - * rather than the mapped frame. Implementations are allowed to throw RunTimeExceptions if _column/i are out of bounds + * get a specific element of the underlying contact matrix in its data-local coordinates + * rather than the mapped frame. Implementations are allowed to throw + * RunTimeExceptions if _column/i are out of bounds * * @param _column * @param i * @return */ - protected abstract double getElementAt(int _column, int i); - + public double getElementAt(int _column, int i) { + return mappedMatrix.getElementAt(_column, i); + } + + @Override + public int hashCode() + { + return 7 * (refSeq != null ? refSeq.hashCode() : 0) + + 11 * (toSeq != null ? toSeq.hashCode() : 0) + + 13 * (mappedMatrix != null ? mappedMatrix.hashCode() : 0) + + length * 3; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null || !(obj.getClass().equals(getClass()))) + { + return false; + } + T them = (T) obj; + return mappedMatrix == them.mappedMatrix && length == them.length + && refSeq == them.refSeq && toSeq.equals(them.toSeq); + + } }