From 8db3f3a84e294b362760a66b2f05d127dd76dd3c Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 29 Oct 2014 10:41:32 +0000 Subject: [PATCH] JAL-674 JAL-1264 remap method to allow annotation positions to be updated from simple int-pair arrays (like those used in the StructureManager mappings) --- src/jalview/datamodel/AlignmentAnnotation.java | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index c0d911e..603efe0 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -1182,6 +1182,74 @@ public class AlignmentAnnotation // trim positions } } + } + /** + * like liftOver but more general. + * + * Takes an array of int pairs that will be used to update the internal + * sequenceMapping and so shuffle the annotated positions + * + * @param newref + * - new sequence reference for the annotation row - if null, + * sequenceRef is left unchanged + * @param mapping + * array of ints containing corresponding positions + * @param from + * - column for current coordinate system (-1 for index+1) + * @param to + * - column for destination coordinate system (-1 for index+1) + * @param idxoffset + * - offset added to index when referencing either coordinate system + * @note no checks are made as to whether from and/or to are sensible + */ + public void remap(SequenceI newref, int[][] mapping, int from, int to, + int idxoffset) + { + if (mapping != null) + { + Hashtable old = sequenceMapping, remap = new Hashtable(); + int index = -1; + for (int mp[] : mapping) + { + if (index++ < 0) + { + continue; + } + Annotation ann = null; + if (from == -1) + { + ann = sequenceMapping.get(Integer.valueOf(idxoffset + index)); + } + else + { + if (mp != null && mp.length > from) + { + ann = sequenceMapping.get(Integer.valueOf(mp[from])); + } + } + if (ann != null) + { + if (to == -1) + { + remap.put(Integer.valueOf(idxoffset + index), ann); + } + else + { + if (to > -1 && to < mp.length) + { + remap.put(Integer.valueOf(mp[to]), ann); + } + } + } + } + sequenceMapping = remap; + old.clear(); + if (newref != null) + { + sequenceRef = newref; + } + adjustForAlignment(); + } } } -- 1.7.10.2