-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdna.py
33 lines (25 loc) · 942 Bytes
/
dna.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
27
28
29
30
31
32
33
from Bio.Seq import Seq
def dna_to_rna(dna_sequence):
dna_seq = Seq(dna_sequence)
rna_sequence = dna_seq.transcribe()
return str(rna_sequence)
def rna_to_protein(rna_sequence):
rna_seq = Seq(rna_sequence)
protein_sequence = rna_seq.translate()
return str(protein_sequence)
def is_valid_dna(dna_sequence):
return all(base in "ATCG" for base in dna_sequence.upper())
def main():
print("Welcome to the DNA Sequence Analyzer")
dna_sequence = input("Enter a DNA sequence: ").upper()
if not is_valid_dna(dna_sequence):
print("Invalid DNA sequence. Please only use A, T, C, and G.")
return
rna_sequence = dna_to_rna(dna_sequence)
protein_sequence = rna_to_protein(rna_sequence)
print("\nResults:")
print(f"DNA Sequence: {dna_sequence}")
print(f"RNA Sequence: {rna_sequence}")
print(f"Protein Sequence: {protein_sequence}")
if __name__ == "__main__":
main()