import subprocess
from Bio import AlignIO

# Use the full path to muscle.exe
muscle_exe = r"C:\Users\Admin\muscle3.8.31_i86win32.exe"  # Update path as needed

try:
    # Run MUSCLE using subprocess
    subprocess.run([
        muscle_exe,
        "-in", "input_sequences.fasta",  # Input file with sequences to align
        "-out", "aligned_sequences.fasta"  # Output file for the alignment
    ], check=True)
    
    # Read and print the aligned sequences
    alignment = AlignIO.read("aligned_sequences.fasta", "fasta")
    print(alignment)
    
except FileNotFoundError:
    print("Error: MUSCLE executable not found. Check the path:", muscle_exe)
except subprocess.CalledProcessError as e:
    print(f"Error running MUSCLE: {e}")

# Output Example:
# >seq1
# ATGCGTACGTA
# >seq2
# ATGCGTACGTC
# >seq3
# ATGCGTACGAG