Please help me finding the best match of the primer sequence from the multi fasta file by allowing 10% mismatch
0
0
Entering edit mode
4.6 years ago
kmmistr1 ▴ 10

Hi, I am trying to find the best match of the primer sequence which is 20bp long from a multi fasta file consisting 3 sequences in python3. 10 % mismatch is allowed. I tried to match complement bases of primer and found 1 match but there are supposed to be 2 more but I am struggling with it. Can anyone help me please?

The code I wrote to find the match of complement bases of primer are:

1)

def complement(bases):  ### returning complement bases
    List=[]
    seq_dict={"A":"T","T":"A","G":"C","C":"G"}
    for x in bases:
        if x in seq_dict:
            List.append(seq_dict[x])
    return ''.join(List)

complement(Primer)

2)

with open(multi_fasta,"r")as f_in:   ### extracting the sequence in which there is a primer(complement) match in it
    for lines in f_in:
        if lines.startswith(">"):
            headers=lines.strip()
        else:
            seq=lines.strip()
            if complement(Primer) in lines:
                print(headers+ "\n" + lines)

3) applying re.search to find the location of the match

import re
with open(multi_fasta, "r")as f_in:   
    for lines in f_in:
        if not lines.startswith(">"):
            seq=lines
            r1=re.search(comp_primer, seq)
            print (r1)
Python Primer matching multifasta file • 1.4k views
ADD COMMENT
0
Entering edit mode

If this is an assignment then please make a note of it. People would then not try to provide a separate solution.

ADD REPLY
0
Entering edit mode

No, it is a parctice question.

ADD REPLY
0
Entering edit mode

Would you not prefer to use PrimerBLAST or Primer3 or something?

ADD REPLY
0
Entering edit mode

I have tried Standalone Blast in jupyter notebook (Python3) and I have successfully created database too but getting error while blasting that database and primer.

ADD REPLY
1
Entering edit mode

cheers @kmmistr1

congratulations on building the database. Thank you for sharing your experience with your error. May the reader assume you're handling it on your own? Otherwise you most certainly had shared more details...

Also, please do not add comments as answers.

ADD REPLY
0
Entering edit mode

Sorry, actually I am new here and I am still learning how to post our questions and how to reply to someone's comments. I didn't realise I actually added a comment instead of replying to thecomment. Thank you for your help.

ADD REPLY
0
Entering edit mode

try seqkit locate for searching primers, and seqkit amplicon for extracting amplicon with primers, both commands allow mismatch.

ADD REPLY
0
Entering edit mode

Thanks @shenwei356 I will give it a go.

ADD REPLY

Login before adding your answer.

Traffic: 2310 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