-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrna_splicing.py
53 lines (41 loc) · 1.75 KB
/
rna_splicing.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
""" Splicing RNA: removing exons from a DNA sequence and transcribing
and translating it into a amino acid sequence """
__author__ = "Navami Shenoy"
import dna_to_rna as dna
import rna_to_protein as rna
def splicing(dna_string, introns):
""" returns the amino acid sequence after splicing introns,
transcribing DNA, and translating RNA into protein"""
# splicing
for intron in introns: # for every intron in the list
if intron in dna_string: # if intron exists in the string
dna_string = dna_string.replace(intron,'') # remove intron
spliced_string = "".join(dna_string) # concatenate exons
#transcription
spliced_rna = dna.dna_to_rna(spliced_string)
#translation
protein = rna.rna_to_protein(spliced_rna)
return protein
def readFASTA(filename):
""" read and parse FASTA file. capture
labels and their corresponding sequences
in a dictionary """
# works more like parsing a FASTQ file
seqs = {}
with open(filename, 'r') as f:
for line in f:
if line[0] == '>': # capture label
label = line[1:].rstrip()
genome = ''
else: # capture sequence
genome += line.rstrip()
seqs[label] = genome
return seqs
# testing
seqs = readFASTA('rosalind_splc.txt') # test file source: https://rosalind.info
seqs = list(seqs.values())
dna_string = seqs[0] # the DNA string
introns = seqs[1:] # the list of introns
print(splicing(dna_string, introns))
# Output: MAGRSRDMGSRPAAQVFCFAVRYPWGSPGSSFQYCNASRARSDCTSHFSSSLCQTCRVRALPSSMTLHDRLVHGCGGRRLPDTAILKTFQRNRMRTNLRHRATDVRSNLYSSAPFGSPKVLHPFSKRLFRSTMGFSPAAYSPKPRTRSCALFSKGVRVSRMLSRLRQPSARPPCSEVSHTPRTFVRGSSRRQRATLNG