From b2bbc1f7306b6b292d77cc40bcc840cac64e13e9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 14 Dec 2018 17:44:25 +0000 Subject: [PATCH] =?utf8?q?JAL-3171=20record=20mapping=20between=20unmarshall?= =?utf8?q?ed=20sequence=E2=80=99s=20dataset=20sequence=20ID=20and=20material?= =?utf8?q?ised=20dataset=20to=20allow=20belt-and-braces=20discovery=20of=20e?= =?utf8?q?xisting=20dataset=20-=20test=20now=20passes?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/project/Jalview2XML.java | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 4cc43d3..90c09d7 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -5220,6 +5220,20 @@ public class Jalview2XML { jalview.datamodel.AlignmentI ds = getDatasetFor( vamsasSet.getDatasetId()); + AlignmentI xtant_ds = ds; + if (xtant_ds == null) + { + // good chance we are about to create a new dataset, but check if we've + // seen some of the dataset sequence IDs before. + // TODO: skip this check if we are working with project generated by + // version 2.11 or later + xtant_ds = checkIfHasDataset(vamsasSet.getSequence()); + if (xtant_ds != null) + { + ds = xtant_ds; + addDatasetRef(vamsasSet.getDatasetId(), ds); + } + } Vector dseqs = null; if (!ignoreUnrefed) { @@ -5231,6 +5245,13 @@ public class Jalview2XML { warn("JAL-3171 regression: Overwriting a dataset reference for an alignment" + " - CDS/Protein crossreference data may be lost"); + if (xtant_ds != null) + { + // This can only happen if the unique sequence set ID was bound to a + // dataset that did not contain any of the sequences in the view + // currently being restored. + warn("JAL-3171 SERIOUS! TOTAL CONFUSION - please consider contacting the Jalview Development team so they can investigate why your project caused this message to be displayed."); + } } ds = seqSetDS; addDatasetRef(vamsasSet.getDatasetId(), ds); @@ -5238,6 +5259,8 @@ public class Jalview2XML } if (ds == null) { + // try even harder to restore dataset + AlignmentI xtantDS = checkIfHasDataset(vamsasSet.getSequence()); // create a list of new dataset sequences dseqs = new Vector(); } @@ -5263,9 +5286,55 @@ public class Jalview2XML // register dataset for the alignment's uniqueSeqSetId for legacy projects addDatasetRef(UNIQSEQSETID + uniqueSeqSetId, ds); } + updateSeqDatasetBinding(vamsasSet.getSequence(), ds); + } + + /** + * XML dataset sequence ID to materialised dataset reference + */ + HashMap seqToDataset = new HashMap<>(); + + /** + * @return the first materialised dataset reference containing a dataset + * sequence referenced in the given view + * @param list + * - sequences from the view + */ + AlignmentI checkIfHasDataset(List list) + { + for (Sequence restoredSeq : list) + { + AlignmentI datasetFor = seqToDataset.get(restoredSeq.getDsseqid()); + if (datasetFor != null) + { + return datasetFor; + } + } + return null; } /** + * Register ds as the containing dataset for the dataset sequences referenced + * by sequences in list + * + * @param list + * - sequences in a view + * @param ds + */ + void updateSeqDatasetBinding(List list, AlignmentI ds) + { + for (Sequence restoredSeq : list) + { + AlignmentI prevDS = seqToDataset.put(restoredSeq.getDsseqid(), ds); + if (prevDS != null && prevDS != ds) + { + warn("Dataset sequence appears in many datasets: " + + restoredSeq.getDsseqid()); + // TODO: try to merge! + } + } + } + /** * * @param vamsasSeq * sequence definition to create/merge dataset sequence for -- 1.7.10.2