Codon alignment via Python?
The basic process would be (in pseudocode, I don't know python well enough, I'm a Perl geek):

$seq1=ATGCCAGGCTGA
$seq2=ATGGGACCATAA;
for ($i=0;$i&lt;length($seq1);$i++){
   codons1[$i]=amino_acid
}
for ($i=0;$i&lt;length($seq2);$i++){
       codons2[$i]=amino_acid
}


At this point you will have two arrays or hashes or tuples or dicts or whatever holding the amino acid that corresponds to each codon position of the input seqs. You go and do your translation and dS/dN thing and you can then use these lists to map back to the original nucleotides:

for ($i=0;$i&lt;length($ProteinSseq1);$i++){
  print codons1[$i]
}


You will need to adapt this to deal with codons correctly (i++ will only increment by one, you need to extract the triplets) and then to read the gaps but these are all programming issues that have nothing to do with the biological side of things.