-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
26 lines (19 loc) · 876 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Align import MultipleSeqAlignment
from Bio import AlignIO, SeqIO
from Bio.Align.Applications import ClustalwCommandline
sequences = ["TGACTTCA", "TCACGTCA", "TGACGCCA", "TGACGTCA", "TGTCGCCA", "AGACGTCA"]
# Create SeqRecord objects for each sequence
seq_records = [SeqRecord(Seq(seq), id=f"Seq_{i}") for i, seq in enumerate(sequences)]
# Write the sequences to a FASTA file
SeqIO.write(seq_records, "sequences.fasta", "fasta")
# Run ClustalW to align the sequences
clustalw_cline = ClustalwCommandline("clustalw2", infile="sequences.fasta")
stdout, stderr = clustalw_cline()
# Read the alignment from the ClustalW output file
alignment = AlignIO.read("sequences.aln", "clustal")
# Calculate the consensus sequence
consensus = alignment.dumb_consensus()
# Print the consensus sequence
print(consensus)