Python DNA sequencing

Suppose you are given the following list of strings:

L = ['aabaabac', 'cabaabca', 'aaabbcba', 'aabacbab', 'acababba']

Patterns like this show up in many places, including DNA sequencing. The user has a string of their own with only some letters filled in and the rest as asterisks. An example is a**a****. The user would like to know which of the strings in the list fit with their pattern. In the example just given, the matching strings are the first and fourth. One way to solve this problem is to create a dictionary whose keys are the indices in the user’s string of the non-asterisk characters and whose values are those characters. Write a program implementing this approach (or some other approach) to find the strings that match a user-entered

string.

L = ['aabaabac', 'cabaabca', 'aaabbcba', 'aabacbab', 'acababba']
user =
'a**a****'
d = {}
d_user = {}
T = []
counter1 =
0
for i in range(len(user)):
    T.append((counter1, user[i]))
    counter1 +=
1
d_user = dict(T)
K = []
counter =
0
c = len(L[0])
U = []
for j in range(len(L)):
    
for i in range(c):
        K.append((counter, L[j][i]))
        counter +=
1
   
d = dict(K)
    U.append(d)
    K = []
    counter =
0
counter2 = 0
R = []
for i in range(len(U)):
   
for j in range(len(U[0])):
       
if U[i][j] == d_user[j]:
            counter2 +=
1
   
R.append((i+1, counter2))
    counter2 =
0
print(R)

SOLUTION:

[(
1, 2), (2, 1), (3, 1), (4, 2), (5, 1)]

Коментари

Популарни постови са овог блога

Python Fan functions

Python StopWatch milliseconds

Python Accounting