Knowee
Questions
Features
Study Tools

WAP for searching a pattern in a string motif finding

Question

WAP for searching a pattern in a string motif finding

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python program that uses the built-in find() function to search for a pattern in a string. This is a basic motif finding algorithm.

def find_motif(string, pattern):
    # Initialize an empty list to store the positions
    positions = []

    # Initialize position as 0
    position = 0

    while True:
        # Find the pattern in the string
        position = string.find(pattern, position)

        # If the pattern is not found, break the loop
        if position == -1:
            break

        # Append the position to the list
        positions.append(position)

        # Increment the position
        position += 1

    # Return the positions
    return positions

# Test the function
string = "GATATATGCATATACTT"
pattern = "ATAT"
print(find_motif(string, pattern))

This program will output [1, 3, 9], which are the starting positions of the pattern "ATAT" in the string "GATATATGCATATACTT" (0-indexed). Note that Python's find() function returns the lowest index of the substring (if found). If not found, it returns -1.

This problem has been solved

Similar Questions

1. How exhaustive search method uses Brute force approach to evaluate various problems and find whether the given string follows the specified pattern and return 0 or 1 accordingly. Examples: Pattern “abba” input: “redblueredblue” should return 1 Pattern “aaaa” input: ”asdasdasdasd” should return 1 Pattern “aabb” input: “xyzabcxyzabc” ” should return 0

WAP to plot codon frequency in a given sequence

WAP that will translate a DNA sequence into protein

Which of the following tools is commonly used to identify conserved protein motifs in a set of sequences? BLAST Clustal Omega PROSITE Flye

WAP that will print the complement DNA sequence of your choice

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.