Question

In: Computer Science

I dont know how to make de bruijn sequence in python. We have to print output...

I dont know how to make de bruijn sequence in python. We have to print output by following this step.

1.start with a string of n consecutive zeroes

2.append 1 to the end of the string if the n-digit suffix that would be formed this way has not already appeared in the sequence; otherwise a 0 is appended to the end of the string.

3.repeat step 2 until the length of the sequence equals 2 **n

For instance, when we put input 4, we have to print output 0000111101100101

Solve me this question in pycharm... and please show the code.

Solutions

Expert Solution

Here is one of the simplest code for generating the de-bruijn sequence. I am attaching the code below with some screenshots of the output.

Although, for the input 4, my code is generating the output string having the same number of zeroes and one's as that you give in your question but the order is not preserved, but you should not worry about that because we can have more than one bruijn sequence for a given input.

Code :

def de_bruijn(d, n):
pos_seq = [0 for _ in range(n)]
l = 1
de_bruijn_seq = []
while True:
if n % l == 0:
de_bruijn_seq.extend(pos_seq[0:l])
for i in range(l, n):
pos_seq[i] = pos_seq[i-l]
l = n
while l > 0 and pos_seq[l-1] >= d-1:
l-=1
if l == 0:
break
pos_seq[l-1] += 1
return de_bruijn_seq
  
st = de_bruijn(2,4)
for i in st:
print(i, end="")

Screenshots :

​​​​​​

Explanation :

1. pos_seq will have the all posible type of subsequence of size n for the given d

2. de_bruijn_seq will store the de_bruijn seq and return it to the calling function where we store it's value in a var st

3. var l is acting as a pointer to move between the sequence

4. We only store a pos_seq in de_bruijn_seq, when n%l becomes zero

5. We break out of the loop when l becomes zero

6. At last we print our de_bruijn sequence using a for loop


Related Solutions

I have this exercise and i dont know how to do it DDB Corporation was formed...
I have this exercise and i dont know how to do it DDB Corporation was formed by twenty-four shareholders on January 1, 2017. The shareholders will be having their semi-annual meeting on September 28, 2018 to review the financial results for January 1 – June 30, 2018. As of January 1, 2018, the company has a retained deficit (this means the company incurred a net loss in 2017). The following are the unadjusted balances of DDB Corporation as of June...
I am having a lot of difficulty on problem 2 I dont know how to use...
I am having a lot of difficulty on problem 2 I dont know how to use switch. Branching and looping Objectives: 1. Write a program that uses branching and a while loop. 2. Using boolean expressions and primitive variable types. Note: if you don’t have a laptop, work with another person. When you are done with the exercise, show your TA that you both worked on the assignment together and you will both get credit for the work. Problem 1:...
determine the sequence below then answer following questions. IF YOU DONT KNOW IT OR ITS NOT...
determine the sequence below then answer following questions. IF YOU DONT KNOW IT OR ITS NOT GIVEN SKIP IT! sequence: GGGCGGGGTCTATACATGCAAGTCGAGCGAACGGATTAAGAGCTTGCTCTTAAGAAGTTAGCGGCGGACGGGTGAGTAACACGTGGGTAACCTGCCCATAAGACTGGGATAACTCCGGGAAACCGGGGCTAATACCGGATAACATTTTGCACCGCATGGTGCAAGATTGAAAGGCGGCTTCGGCTGTCACTTATGGATGGACCCGCGTCGCATTAGCTAGTTGGTGAGGTAACGGCTCACCAAGGCGACGATGCGTAGCCGACCTGAGAGGGTGATCGGCCACACTGGGACTGAGACACGGCCCAGACTCCTACGGGAGGCAGCAGTAGGGAATCTTCCGCAATGGACGAAAGTCTGACGGAGCAACGCCGCGTGAGCGATGAAGGCCTTCGGGTCGTAAAGCTCTGTTGTTAGGGAAGAACAAGTATGAGTTGAATAAGCTCATGCCTTGACGGTACCTAACCAGAAAGCCACGGCTAACTACGTGCCAGCAGCCGCGGTAATACGTAGGTGGCAAGCGTTATCCGGAATTATTGGGCGTAAAGCGCGCGCAGGCGGTTTCTTAAGTCTGATGTGAAAGCCCACGGCTCAACCGTGGAGGGTCATTGGAAACTGGGAGACTTGAGTGCAGAAGAGGAGAGTGGAATTCCATGTGTAGCGGTGAAATGCGTAGAGATATGGAGGAACACCAGTGGCGAAGGCGACTCTCTGGTCTGTAACTGACGCTGAGGCGCGAAAGCGTGGGGAGCAAACAGGATTAGATACCCTGG question: _______ 4.0 pts. B. Name the gene that we will be sequencing in order to identify the unknown. C. Explain why this region is considered to be the target for identification instead of sequencing the entire genome? D. What is the size (in bp) of target DNA in E. coli __________ 4.0 pts. What do we mean by...
What's wrong with my Python code. We have to find the regularexpression in Python My output...
What's wrong with my Python code. We have to find the regularexpression in Python My output should look like this My IP address 128. 0. 0. 1 My IP address 53. 20. 62. 201 My code ipAddresses = [] ipRegEx = re.compile(r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")    result = myRegEx.find all(Search Text)    def Regular_expression(ipAddresses)       for i in ipAddresses:          print(i) ipSearchResult = ipRegEx.search(line)    if ipSearchResult != None and ipSearchResult.group() not in ipAddresses:       ipAddresses.append(ipSearchResult.group()) we have to use loop too.
I have this mystery code. I dont know what the code does. Can somone please explain...
I have this mystery code. I dont know what the code does. Can somone please explain with examples. (python 3.xx) from typing import Dict, TextIO, Tuple, List def exam(d1: Dict[str, List[int]], d2: Dict[int, int]) -> None: """ *Mystery code* """ for key in d1: value = d1[key] for i in range(len(value)): value[i] = d2[value[i]]   
REFER TO CANADIAN SOLAR CASE ... I DONT KNOW HOW TO ATTACH IT, its too long...
REFER TO CANADIAN SOLAR CASE ... I DONT KNOW HOW TO ATTACH IT, its too long to type... PART A:Explain the CAGE model, its components, and its usefulness in evaluating international business decisions. PART B:For Canadian Solar, use the CAGE model to evaluate the challenges inherent in the joint venture decision.
REFER TO CANADIAN SOLAR CASE ... its too long to post, I dont know how to...
REFER TO CANADIAN SOLAR CASE ... its too long to post, I dont know how to attach it. a) Should Canadian Solar try to be global? Please justify your answer. b) What global strategy would you recommend that Canadian Solar pursue? Please justify your answer.
PLEASE ANSWER ALL I HAVE AN EXAM TODAY AND THESE DONT MAKE SENSE TO ME Hyperalbumenia...
PLEASE ANSWER ALL I HAVE AN EXAM TODAY AND THESE DONT MAKE SENSE TO ME Hyperalbumenia may result in __levels of a drug that demonstrates strong protein binding a) Increased b) Decreased c) No change is observed When you have a patient with decreased renal function what modifications may have to be made to drug dosing a) Increasing the dose b) Increasing the frequency of the dose c) Decreasing the dose d) Decreasing the frequency of the dose c) More...
Write the following Python script: Problem Statement We want to know how many different people have...
Write the following Python script: Problem Statement We want to know how many different people have eaten at a restaurant this past week. The parameter meals has strings in the format "name:restaurant" for a period of time. Sometimes a person eats at the same restaurant often. Return the number of different people who have eaten at the eating establishment specified by parameter restaurant. For example, "John Doe:Moes" shows that John Doe ate one meal at Moes. Write function howMany that...
I need to know how to make an ethical decision in detail?
I need to know how to make an ethical decision in detail?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT