# Use biopython to align SeqRecords stored in dict

I'd like to perform multiple alignments, where a gene from each sample was read in from fasta files. The fasta file represented one sample and had multiple genes. I have read in each sample fasta file and now have a dictionary of genes and their samples and sequences. Here is a small example.

The main key is the gene ID for another dictionary as the value. In the dictionary 'R??' is the sample name and key, followed by the annotation and sequence in a list.

{'PRELSG_MIT_v1:5894-6032': {'R47': ['not annotated',
Seq('ATAAAAATAGTTACCATAGCTGTTGATGGATGCTTCGATCATAAAATATGTTTG...GGA')],
'R48': ['not annotated',
Seq('ATAAAAATAGTTACCATAGCTGTTGATGGATGCTTCGATCATAAAATATGTTTG...GGA')],
'R49': ['not annotated',
Seq('ATAAAAATAGTTACCATAGCTGTTGATGGATGCTTCGATCATAAAATATGTTTG...GGA')],
'R50': ['not annotated',
Seq('ATAAAAATAGTTACCATAGCTGTTGATGGATGCTTCGATCATAAAATATGTTTG...GGA')],
'R51': ['not annotated',
Seq('ATAAAAATAGTTACCATAGCTGTTGATGGATGCTTCGATCATAAAATATGTTTG...GGA')],
'R52': ['not annotated',
Seq('ATAAAAATAGTTACCATAGCTGTTGATGGATGCTTCGATCATAAAATATGTTTG...GGA')]},
'exon_PRELSG_MIT00300.1-E1': {'R47': ['cytochrome b',
Seq('TCCAGATAATGCTATTACAGTAGATAGATATGCTACTCCTTTACATATTGTTCC...TTC')],
'R48': ['cytochrome b',
Seq('TCCAGATAATGCTATTACAGTAGATAGATATGCTACTCCTTTACATATTGTTCC...TTC')],
'R49': ['cytochrome b',
Seq('TCCAGATAATGCTATTACAGTAGATAGATATGCTACTCCTTTACATATTGTTCC...TTC')],
'R50': ['cytochrome b',
Seq('TCCAGATAATGCTATTACAGTAGATAGATATGCTACTCCTTTACATATTGTTCC...TTC')],
'R51': ['cytochrome b',
Seq('TCCAGATAATGCTATTACAGTAGATAGATATGCTACTCCTTTACATATTGTTCC...TTC')],
'R52': ['cytochrome b',
Seq('TCCAGATAATGCTATTACAGTAGATAGATATGCTACTCCTTTACATATTGTTCC...TTC')]}}


I'd like to align each gene and write out those alignments to file without any intermediate files written to disk. How do I do that?

• do you want to align each of those Seq('ATAAAAATAGTT...... on top of each other ?
– moth
Nov 11 '21 at 13:54
• Yes, what you said moth. I want one alignment for each gene. Nov 12 '21 at 14:29