From: Jim Procter Date: Thu, 14 Jul 2016 10:28:14 +0000 (+0100) Subject: JAL-2110 JAL-2147 JAL-2145 - pad CDS alignment reconstructed from aligned proteins X-Git-Tag: Release_2_10_0~140^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2baee069f9edaef280f0115bae42d4ac7b77bb9b;p=jalview.git JAL-2110 JAL-2147 JAL-2145 - pad CDS alignment reconstructed from aligned proteins --- diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 5e04d31..9aaaed2 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -867,6 +867,8 @@ public class AlignmentUtils * Realigns the given dna to match the alignment of the protein, using codon * mappings to translate aligned peptide positions to codons. * + * Always produces a padded CDS alignment. + * * @param dna * the alignment whose sequences are realigned by this method * @param protein @@ -883,6 +885,7 @@ public class AlignmentUtils // todo: implement this List mappings = protein.getCodonFrames(); int alignedCount = 0; + int width = 0; // alignment width for padding CDS for (SequenceI dnaSeq : dna.getSequences()) { if (alignCdsSequenceAsProtein(dnaSeq, protein, mappings, @@ -890,6 +893,17 @@ public class AlignmentUtils { alignedCount++; } + width = Math.max(dnaSeq.getLength(), width); + } + int oldwidth, diff; + for (SequenceI dnaSeq : dna.getSequences()) + { + oldwidth = dnaSeq.getLength(); + diff = width - oldwidth; + if (diff > 0) + { + dnaSeq.insertCharAt(oldwidth, diff, dna.getGapCharacter()); + } } return alignedCount; }