X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FAlignmentAnnotation.java;fp=src%2Fjalview%2Fdatamodel%2FAlignmentAnnotation.java;h=012ecb334d423dba247287d20c3bd5db690fd914;hb=32973e4c3a37dd4485c4190f45bbf43017af40df;hp=601339acc1f84b1af5117b2341465d4636f4944f;hpb=da82f3c35066f27c4632b2f7c5d818dc1b9a6547;p=jalview.git diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 601339a..012ecb3 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -28,6 +28,8 @@ import jalview.analysis.WUSSParseException; import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Map; +import java.util.Map.Entry; import fr.orsay.lri.varna.models.rna.RNA; @@ -105,7 +107,7 @@ public class AlignmentAnnotation // System.out.println("featuregroup " + _rnasecstr[0].getFeatureGroup()); } - public java.util.Hashtable sequenceMapping; + public java.util.Hashtable sequenceMapping; /** DOCUMENT ME!! */ public float graphMin; @@ -947,10 +949,14 @@ public class AlignmentAnnotation { if (sequenceRef != null) { + boolean rIsDs=sequenceRef.getDatasetSequence()==null,tIsDs=sequenceI.getDatasetSequence()==null; if (sequenceRef != sequenceI - && !sequenceRef.equals(sequenceI) - && sequenceRef.getDatasetSequence() != sequenceI + && (rIsDs && !tIsDs && sequenceRef != sequenceI .getDatasetSequence()) + && (!rIsDs && tIsDs && sequenceRef.getDatasetSequence() != sequenceI) + && (!rIsDs && !tIsDs && sequenceRef.getDatasetSequence() != sequenceI + .getDatasetSequence()) + && !sequenceRef.equals(sequenceI)) { // if sequenceRef isn't intersecting with sequenceI // throw away old mapping and reconstruct. @@ -1117,4 +1123,50 @@ public class AlignmentAnnotation { return isrna; } + + /** + * transfer annotation to the given sequence using the given mapping from the + * current positions or an existing sequence mapping + * + * @param sq + * @param sp2sq + * map involving sq as To or From + */ + public void liftOver(SequenceI sq, Mapping sp2sq) + { + if (sp2sq.getMappedWidth() != sp2sq.getWidth()) + { + // TODO: employ getWord/MappedWord to transfer annotation between cDNA and Protein reference frames + throw new Error("liftOver currently not implemented for transfer of annotation between different types of seqeunce"); + } + boolean mapIsTo = (sp2sq != null) ? (sp2sq.getTo() == sq || sp2sq + .getTo() == sq.getDatasetSequence()) : false; + + // TODO build a better annotation element map and get rid of annotations[] + Hashtable mapForsq = new Hashtable(); + if (sequenceMapping != null) + { + if (sp2sq != null) + { + for (Entry ie : sequenceMapping.entrySet()) + { + Integer mpos = Integer.valueOf(mapIsTo ? sp2sq + .getMappedPosition(ie.getKey()) : sp2sq.getPosition(ie + .getKey())); + if (mpos >= sq.getStart() && mpos <= sq.getEnd()) + { + mapForsq.put(mpos, ie.getValue()); + } + } + sequenceMapping = mapForsq; + sequenceRef = sq; + adjustForAlignment(); + } + else + { + // trim positions + } + } + + } }