From: gmungoc Date: Mon, 22 Aug 2016 08:26:41 +0000 (+0100) Subject: JAL-2011 adjust method to fix failing unit test X-Git-Tag: Release_2_10_0~98 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=a28124515bde191d11c05fe0f2bda8d2b2b66d61;p=jalview.git JAL-2011 adjust method to fix failing unit test --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 9aaaed2..d93f42f 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -2634,13 +2634,16 @@ public class AlignmentUtils return false; // should only pass alignments with datasets here } - // map from dataset sequence to alignment sequence - Map alignedDatasets = new HashMap(); + // map from dataset sequence to alignment sequence(s) + Map> alignedDatasets = new HashMap>(); for (SequenceI seq : aligned.getSequences()) { - // JAL-2110: fail if two or more alignment sequences have a common dataset - // sequence. - alignedDatasets.put(seq.getDatasetSequence(), seq); + SequenceI ds = seq.getDatasetSequence(); + if (alignedDatasets.get(ds) == null) + { + alignedDatasets.put(ds, new ArrayList()); + } + alignedDatasets.get(ds).add(seq); } /* @@ -2656,17 +2659,22 @@ public class AlignmentUtils } /* - * second pass - copy aligned sequences + * second pass - copy aligned sequences; + * heuristic rule: pair off sequences in order for the case where + * more than one shares the same dataset sequence */ for (SequenceI seq : unaligned.getSequences()) { - SequenceI alignedSequence = alignedDatasets.get(seq + List alignedSequences = alignedDatasets.get(seq .getDatasetSequence()); - // JAL-2110: fail if two or more alignment sequences have common dataset - // sequence. // TODO: getSequenceAsString() will be deprecated in the future // TODO: need to leave to SequenceI implementor to update gaps - seq.setSequence(alignedSequence.getSequenceAsString()); + seq.setSequence(alignedSequences.get(0).getSequenceAsString()); + if (alignedSequences.size() > 0) + { + // pop off aligned sequences (except the last one) + alignedSequences.remove(0); + } } return true; diff --git a/test/jalview/analysis/AlignmentUtilsTests.java b/test/jalview/analysis/AlignmentUtilsTests.java index 7661c5d..22bb680 100644 --- a/test/jalview/analysis/AlignmentUtilsTests.java +++ b/test/jalview/analysis/AlignmentUtilsTests.java @@ -2449,8 +2449,9 @@ public class AlignmentUtilsTests { SequenceI dna1 = new Sequence("dna1", "cccGGGTTTaaa"); SequenceI dna2 = new Sequence("dna2", "CCCgggtttAAA"); - SequenceI as1 = dna1.deriveSequence(), as2 = dna1.deriveSequence() - .getSubSequence(3, 7), as3 = dna2.deriveSequence(); + SequenceI as1 = dna1.deriveSequence(); + SequenceI as2 = dna1.deriveSequence().getSubSequence(3, 7); + SequenceI as3 = dna2.deriveSequence(); as1.insertCharAt(6, 5, '-'); String s_as1 = as1.getSequenceAsString(); as2.insertCharAt(6, 5, '-'); @@ -2461,8 +2462,9 @@ public class AlignmentUtilsTests // why do we need to cast this still ? ((Alignment) aligned).createDatasetAlignment(); - SequenceI uas1 = dna1.deriveSequence(), uas2 = dna1.deriveSequence() - .getSubSequence(3, 7), uas3 = dna2.deriveSequence(); + SequenceI uas1 = dna1.deriveSequence(); + SequenceI uas2 = dna1.deriveSequence().getSubSequence(3, 7); + SequenceI uas3 = dna2.deriveSequence(); AlignmentI tobealigned = new Alignment(new SequenceI[] { uas1, uas2, uas3 }); ((Alignment) tobealigned).createDatasetAlignment();