Question
Help me on Python!!!! plz DNA or deoxyribonucleic acid is a nucleic acid that contains genetic information. It is responsible for propagation of inherited traits.
Help me on Python!!!! plz
DNA or deoxyribonucleic acid is a nucleic acid that contains genetic information. It is responsible for propagation of inherited traits. DNA is organized as two complementary strands that Watson and Crick called the Double Helix. Each strand is built out of nucleotides called bases of which there are four - adenine (A), thymine (T), cytosine (C), and guanine (G). The bases of the two complementary strands that make up the DNA pair up in this order: A+T, T+A, C+G, and G+C. Strands have directionality and the sequence order does matter. Genetic information is determined by the sequence of bases along the strand.
DNA has played an important role in research in computer science. For example research in string searching algorithms has been motivated by finding sequences in DNAs. For the present assignment, we are interested in finding the longest common base sequence in two DNA strands. Each strand is represented by the sequence of letters A, T, C, and G. For the two strands ACTG and TGCA the longest common sequence is TG. It is quite possible for two strands not to have any common sequence (a sequence of 1 base does not count). Also there could be two or more common sequences that have the same longest length.
In your program you will open a text file called dna.txt. The first line of data is an integer number n that gives the number of pairs of DNA to follow. You will read one pair of DNA strings at a time. The maximum length of each string is 80 characters. Assume that each string consists only of characters 'A', 'T', 'C' and 'G'. It is acceptable if a string is in lower case or is in mixed upper and lower case. Convert both strings to upper case. Print out the longest common sequence(s) for the two strings. If there is more than one longest common sequence then print each of those sequences on separate lines. The sequences should be left aligned. If there is no common sequence your program should output No Common Sequence Found.
Sample output session would look like:
Longest Common Sequences Pair 1: TCG Pair 2: TGAT GGAC Pair 3: No Common Sequence Found
Your program should have a good, clean logical structure. We will be looking at good documentation, descriptive variable names, and adherence to the coding convention mentioned below. Your file DNA.py will have the following header:
Extra Credit (5 pts): If there are two or more largest DNA sub-strands that are identical, then output only one. If you can get your code to do that let the TAs know and they will check for it and give you credit.
What I have so far
--------------------------------------------------
dna.txt
3 GAAGGTCGAA CCTCGGGA ATGATGGAC GTGATAAGGACCC AAATTT GGGCCC
--------------------------------------------------
It is Code what I wrote but I am getting wrong answer
ef main (): # open file for reading in_file = open ("./dna.txt", "r") # read the number of pairs num_pairs = in_file.readline () num_pairs = num_pairs.strip() num_pairs = int (num_pairs) # read each pair of dna strands for i in range (num_pairs): st1 = in_file.readline() st2 = in_file.readline() st1 = st1.strip() st2 = st2.strip() st1 = st1.upper () st2 = st2.upper () # order the strands by size if (len(st1) > len (st2)): dna1 = st1 dna2 = st2 else: dna1 = st2 dna2 = st1 # get all substrands of dna2 wnd = len (dna2) length = len(dna2) store_sub_strand1 = [] store_sub_strand2 = [] while (wnd > 1): start_idx = 0 start_idx2=0 while ((start_idx + wnd) <= len(dna2)): sub_strand1 = dna2[start_idx: start_idx + wnd] #decrease window from left sub_strand2 = dna2[start_idx2: length] #decrease window from right if sub_strand1 in dna1 or sub_strand2 in dna1: if len(sub_strand1) > len(store_sub_strand1): store_sub_strand1 = sub_strand1 elif len(sub_strand2) > len(store_sub_strand2): store_sub_strand2 = sub_strand2 if len(store_sub_strand1) > len(store_sub_strand2): print(store_sub_strand1) print() elif len(store_sub_strand2) > len(store_sub_strand1): print(store_sub_strand2) print() elif len(store_sub_strand1) == len(store_sub_strand2): print(store_sub_strand1) print(store_sub_strand2) if store_sub_strand1 == []: print("none")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started