Question

The file genomic_dna.txt contains a section of genomic DNA, and the file exons.txt contains a list...

The file genomic_dna.txt contains a section of genomic DNA, and the file exons.txt contains a list of
start/stop positions of exons. Each exon is on a separate line and the start and stop positions are
separated by a comma. The start and stop positions follow Python conventions; they start from zero
and are inclusive at the start and exclusive at the end. Write a program that will extract the exon
segments, concatenate them, and write them to a new file.
This is a tricky exercise with several parts. Before starting, think about how to divide the complexity of
the problem to easier tasks.
Your program will have to:
 read the exon file line by line
 split each exon line into two numbers
 turn those numbers into integers
 extract the matching part of the genomic DNA sequence
 concatenate all the exon sequences together

FILES:

exon.txt

5,58
72,133
190,276
340,398

gennomic_dna.txt

TCGATCGTACCGTCGACGATGCTACGATCGTCGATCGTAGTCGATCATCGATCGATCGACTGATCGATCGATCGATCGATCGATATCGATCGATATCATCGATGCATCGATCATCGATCGATCGATCGATCGATCGATCATATGTCAGTCGATGCATCGTAGCATCGTATAGTAGCTACGTAGCTACGATCGATCGATCGATCGTAGCTAGCTAGCTAGATCGATCATCATCGTAGCTAGCTCGACTAGCTACGTACGATCGATGCATCGATCGTAGCTAGTACGATCGCGTAGCTAGCATGCTACGTAGATCGATCGATGCATGCTAGCTAGCTAGCTACGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGTAGCTAGCTACGATCGATGCTACGTAGATCGATCGCTAGTAGATCGATCGCTAGCTAGCTGACTAGTACGCTGCTAGTAGTCAGCTAGATCGATGCTAGTCA

python
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# dna.py

# Open file genomic_data.txt and store into fin file object
fin = open("genonmic_dna.txt","r")
# Read the contents of the file and store to dna_sequence
dna_sequence = fin.read()
# Close the file object
fin.close()

# Open file exons.txt and store into fin file object
fin = open("exon.txt","r")
# Read the contents of the file and split it by the lines and store to a list called exons
exons = fin.read().splitlines()
# Close the file object
fin.close()

# String to store the final sequence
final_sequence = ""

# Iterate through each range in the exons list (every value is in the form 'number,number' )
for exon in exons:
# Split it by the comma and store the two values to starting_position and ending_position
starting_position, ending_position = exon.split(',')
# Currently starting_position and ending_position are simply strings that represent a number
# Convert it to integer using int()
starting_position = int(starting_position)
ending_position = int(ending_position)
# Extract the matching part from the dna_sequence
final_sequence = final_sequence + dna_sequence[starting_position:ending_position]

# Open file object for multiple.txt in write mode
fout = open("multiple.txt","w")
# Write the final_sequence
fout.write(final_sequence)
# Close the file object
fout.close()

Sample Input/Output

Suppose our genomic_dna.txt is as follows:

TCGATCGTACCGTCGACGATGCTACGATCGTCGATCGTAGTCGATCATCGATCGATCGACTGATCGATCGATCGATCGATCGATATCGATCGATATCATCGATGCATCGATCATCGATCGATCGATCGATCGATCGATCATATGTCAGTCGATGCATCGTAGCATCGTATAGTAGCTACGTAGCTACGATCGATCGATCGATCGTAGCTAGCTAGCTAGATCGATCATCATCGTAGCTAGCTCGACTAGCTACGTACGATCGATGCATCGATCGTAGCTAGTACGATCGCGTAGCTAGCATGCTACGTAGATCGATCGATGCATGCTAGCTAGCTAGCTACGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGTAGCTAGCTACGATCGATGCTACGTAGATCGATCGCTAGTAGATCGATCGCTAGCTAGCTGACTAGTACGCTGCTAGTAGTCAGCTAGATCGATGCTAGTCA

And exons.txt as follows:

5,58
72,133
190,276
340,398

then by running the python program, we get a new file multiple.txt whose content is as follows:

ACTTACGTACTA

Add a comment
Know the answer?
Add Answer to:
The file genomic_dna.txt contains a section of genomic DNA, and the file exons.txt contains a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT