This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Please help me finding the best match of the primer sequence from the multi fasta file by allowing 10% mismatch

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

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

No, it is a parctice question.

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

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.

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.

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.

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

Thanks @shenwei356 I will give it a go.

0 answers

No answers yet.

Log in to answer this question.