Primer matching with sequence using biopython
1
0
Entering edit mode
3 months ago

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 • 257 views
ADD COMMENT
1
Entering edit mode
3 months ago
Dunois ★ 1.5k

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?

ADD COMMENT

Login before adding your answer.

Traffic: 1237 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6