From f4c035478a53b34b67fabf4729751e546254976e Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 12 Jun 2009 15:57:44 +0000 Subject: [PATCH] synching of all db references and sequence features --- src/jalview/io/vamsas/Datasetsequence.java | 94 +++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 15 deletions(-) diff --git a/src/jalview/io/vamsas/Datasetsequence.java b/src/jalview/io/vamsas/Datasetsequence.java index 39ff94d..1412007 100644 --- a/src/jalview/io/vamsas/Datasetsequence.java +++ b/src/jalview/io/vamsas/Datasetsequence.java @@ -23,6 +23,7 @@ import jalview.datamodel.DBRefEntry; import jalview.datamodel.SequenceI; import jalview.io.VamsasAppDatastore; import uk.ac.vamsas.objects.core.DataSet; +import uk.ac.vamsas.objects.core.DbRef; import uk.ac.vamsas.objects.core.Sequence; /** @@ -102,9 +103,47 @@ public class Datasetsequence extends DatastoreItem sequence.setName(sq.getName()); modified = true; } + modified |= updateJvDbRefs(); + // updateJvFeatures(); } } +/* + private void updateJvFeatures() + { + Sequence vsq = (Sequence) vobj; + + // add or update any new features/references on dataset sequence + if (vsq.getgetSequenceFeatures() != null) + { + int sfSize = sq.getSequenceFeatures().length; + + for (int sf = 0; sf < sfSize; sf++) + { + new jalview.io.vamsas.Sequencefeature(datastore, (jalview.datamodel.SequenceFeature) sq + .getSequenceFeatures()[sf], dataset, (Sequence) vobj); + } + } + } +*/ + private boolean updateSqFeatures() + { + boolean modified=false; + SequenceI sq = (SequenceI) jvobj; + + // add or update any new features/references on dataset sequence + if (sq.getSequenceFeatures() != null) + { + int sfSize = sq.getSequenceFeatures().length; + + for (int sf = 0; sf < sfSize; sf++) + { + modified|=new jalview.io.vamsas.Sequencefeature(datastore, (jalview.datamodel.SequenceFeature) sq + .getSequenceFeatures()[sf], dataset, (Sequence) vobj).docWasUpdated(); + } + } + return modified; + } public void addToDocument() { @@ -120,30 +159,53 @@ public class Datasetsequence extends DatastoreItem sequence.setDescription(sq.getDescription()); dataset.addSequence(sequence); vobj = sequence; - // add or update any new features/references on dataset sequence - if (sq.getSequenceFeatures() != null) - { - int sfSize = sq.getSequenceFeatures().length; - - for (int sf = 0; sf < sfSize; sf++) - { - new jalview.io.vamsas.Sequencefeature(datastore, (jalview.datamodel.SequenceFeature) sq - .getSequenceFeatures()[sf], dataset, (Sequence) vobj); - } - } + updateSqFeatures(); + updateDbRefs();//sq,(Sequence) vobj, dataset); + } + /** + * sync database references from jv to document + * @return true if document was modified + */ + private boolean updateDbRefs() { + boolean modifiedthedoc=false; + SequenceI sq = (SequenceI) jvobj; + if (sq.getDatasetSequence() == null && sq.getDBRef() != null) { // only sync database references for dataset sequences DBRefEntry[] entries = sq.getDBRef(); - jalview.datamodel.DBRefEntry dbentry; + //jalview.datamodel.DBRefEntry dbentry; for (int db = 0; db < entries.length; db++) { - Rangetype dbr = new jalview.io.vamsas.Dbref(datastore, - dbentry = entries[db], sq, (Sequence) vobj, dataset); + modifiedthedoc|= new jalview.io.vamsas.Dbref(datastore, + //dbentry = + entries[db], sq, (Sequence) vobj, dataset).docWasUpdated(); + } } - + return modifiedthedoc; + } + /** + * sync database references from document to jv sequence + * @return true if local sequence refs were modified + */ + private boolean updateJvDbRefs() { + boolean modifiedtheseq=false; + SequenceI sq = (SequenceI) jvobj; + Sequence vsq = (Sequence) vobj; + if (vsq.getDbRefCount()>0) { + // only sync database references for dataset sequences + DbRef[] entries = vsq.getDbRef(); + //DbRef dbentry; + for (int db = 0; db < entries.length; db++) + { + modifiedtheseq|= new jalview.io.vamsas.Dbref(datastore, + //dbentry = + entries[db], vsq, sq).jvWasUpdated(); + } + } + return modifiedtheseq; } public void conflict() @@ -189,6 +251,8 @@ public class Datasetsequence extends DatastoreItem sequence.setName(sq.getName()); modified = true; } + modified |= updateDbRefs(); + modified |= updateSqFeatures(); } /** -- 1.7.10.2