Question: Please help me finding the best match of the primer sequence from the multi fasta file by allowing 10% mismatch
0
gravatar for kmmistr1
5 months ago by
kmmistr110
kmmistr110 wrote:

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)
ADD COMMENTlink modified 5 months ago • written 5 months ago by kmmistr110

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

ADD REPLYlink written 5 months ago by genomax89k

No, it is a parctice question.

ADD REPLYlink written 5 months ago by kmmistr110

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

ADD REPLYlink written 5 months ago by Joe17k

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 REPLYlink written 5 months ago by kmmistr110
1

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 REPLYlink written 5 months ago by Carambakaracho2.2k

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 REPLYlink written 5 months ago by kmmistr110

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

ADD REPLYlink written 5 months ago by shenwei3565.3k

Thanks @shenwei356 I will give it a go.

ADD REPLYlink written 5 months ago by kmmistr110
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 734 users visited in the last hour