This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Primer matching with sequence using biopython

I have two primers forward and reverse and i also have a gene sequence file. I want to match the primer with the sequence and then chopped the bases that comes between the primers. Can anyone help me out this?

I need a script that i can perform on jupyternote book and by using biopython.

Thank you

primers biopython alignment

1 answer

I presume what you want to do is extract the sequence encapsulated by your primers?

Here's a little function that'll help.

You'll need the re and random modules for this.

#Function definition.

def ext_primer_seq(seq, fwd, rev):

    regstr = r"(?<=" + fwd + r")" + r"[ATGCN\.\*]*" + r"(?=" + rev + r")"
    myregex = re.compile(regstr)

    return(myregex.findall(seq))


#Example run.
fwd = "GTACC"
rev = "CAGGG"

seq = ''.join(random.choices(['A', 'T', 'G', 'C'], k = 50)) + fwd + ''.join(random.choices(['A', 'T', 'G', 'C'], k = 10)) + rev + ''.join(random.choices(['A', 'T', 'G', 'C'], k = 25))

print(seq)

#'GAGTAGCAAGCCACGCGCGTTCTCGACCATCCATAACAAAGCCAAGACGGGTACCCGATACTTTTCAGGGCAGCAAAAGCACGTATCCGCCGGGC'

ext_primer_seq(seq, fwd, rev)
#['CGATACTTTT']

Does this help?

Log in to answer this question.