return false; // should only pass alignments with datasets here
}
- // map from dataset sequence to alignment sequence
- Map<SequenceI, SequenceI> alignedDatasets = new HashMap<SequenceI, SequenceI>();
+ // map from dataset sequence to alignment sequence(s)
+ Map<SequenceI, List<SequenceI>> alignedDatasets = new HashMap<SequenceI, List<SequenceI>>();
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<SequenceI>());
+ }
+ alignedDatasets.get(ds).add(seq);
}
/*
}
/*
- * 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<SequenceI> 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;
{
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, '-');
// 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();