-
Notifications
You must be signed in to change notification settings - Fork 0
/
dna_to_rna
28 lines (22 loc) · 969 Bytes
/
dna_to_rna
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
#This is a general purpose program to translate a DNA into a RNA strand.
#The exercice can be found here: https://rosalind.info/problems/rna/
#The user can either paste a DNA sequence or give the .txt file pathway to it.
def transcribing_sequence(sequence):
#formating the sequence and changing T for U:
sequence = sequence.upper()
transcribed_sequence = sequence.replace('T', 'U')
print(transcribed_sequence)
#asking the user
choice = int(input('Type 1 to enter the .txt file pathway or 2 to paste your sequence: '))
#reading a file or the paste from the user
if choice == 1:
dir_pathway = input('Type the file pathway. If it is already on this program file, just type <filename.txt>: ')
file = open(f"{dir_pathway}", 'r')
sequence_nuc = file.read()
elif choice == 2:
sequence_nuc = input('Paste your sequence here: ')
#calling the function
transcribing_sequence(sequence_nuc)
#closing the file
if choice == 1:
file.close()