Analyze genetic data by implementing the Burrows-Wheeler Transform used in DNA…
- User
Analyze genetic data by implementing the Burrows-Wheeler Transform used in DNA alignment. Write the function to transform a genome string into its BWT form for easier compression and searching.
- Assistant
Implementing Burrows-Wheeler Transform
Providing a Python function that appends a sentinel character to the input string, generates all rotations, sorts them, and returns the last column as the BWT output for compression and searching. Below is a simple Python implementation of the Burrows–Wheeler Transform (BWT) for a given genome string. It appends a special end-of-text marker (commonly the dollar sign
$) to ensure correct rotation ordering and recoverability.def burrows_wheeler_transform(genome: str) -> str: """ Computes the Burrows–Wheeler Transform for a genome string. A special end-of-text marker '$' is appended if not present. """ # Ensure the genome has a unique end marker if '$' not in genome: genome += '$' # Generate all cyclic rotations of the genome rotations = [genome[i:] + genome[:i] for i in range(len(genome))] # Sort rotations lexicographically rotations.sort() # BWT is the last column of the sorted rotations bwt = ''.join(rotation[-1] for rotation in rotations) return bwt # Example usage: if __name__ == "__main__": genome_sequence = "ACGTACGT" transformed = burrows_wheeler_transform(genome_sequence) print(transformed) # e.g., "TTGG$AACCA"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.