How do I blast a local query against a local database in python/biopython?

1k views Asked by At

First of all, I want to come clean that I am a super beginner in programming. I have 2 zip files (containing one database each) and 4 fasta files (three containing a protein sequence each and one contains a nucleotide sequence).

I would like to create a program that the user can select from a menu either to run an amino acid or a nucleotide file against its database respectively. The code mentioned below was the best that I was able to do. Unfortunately, it doesn't run at all. I will be very obligated if you could direct me on how to handle it?

import sys 
import zipfile

def main():
def menu():

print("*****MAIN MENU*****")`

print()

choice = input("""
                  A: For nucleotide "DNA" quest 
                  B: For amino acid "Protein" quest 
                  Q: For Exit the program
                  Please enter your choice: """)

if choice == "A" or choice =="a":
    Dnaquery()

elif choice == "B" or choice =="b":
    Proteinquery()

elif choice=="Q" or choice=="q":
    sys.exit
else:
    print("You must only select either A,B,or Q.")
    print("Please try again")
    menu()

    def Dnaquery(): #for nucletide query
       with zipfile.ZipFile("Dna.zip","r") as zip_ref:
          zip_ref.extractall("C:\Users\Gpapa\Desktop\Zipfiles\DnaDatabase>")

       from Bio.Blast import NCBIWWW
       fasta_string = open("Dna.fasta").read()
       result_handle = NCBIWWW.qblast("blastn", "nt", fasta_string)

   def Proteinquery(): #for protein query
   with zipfile.ZipFile("Protein.zip","r") as zip_ref:
             zip_ref.extractall("C:\Users\Gpapa\Desktop\Zipfiles\ProteinDatabase>")
    def menu2 ()
    print("************Select Protein 2 blast **************")

    print()

     choice = input("""
                  1: For Protein Query 1
                  2: For Protein Query 2
                  3: For Protein Query 3
                  Please enter your choice: """)

     if choice == 1:
      from Bio.Blast import NCBIWWW
      fasta_string = open("protein1.fasta").read()
       result_handle = NCBIWWW.qblast("blastp", "prot", fasta_string)

     elif choice == 2:
     from Bio.Blast import NCBIWWW
      fasta_string = open("protein2.fasta").read()
      result_handle = NCBIWWW.qblast("blastp", "prot", fasta_string)
      elif choice==3:
      from Bio.Blast import NCBIWWW
      fasta_string = open("protein3.fasta").read()
      result_handle = NCBIWWW.qblast("blastp", "prot", fasta_string)
      else:
       print("You must only select either 1,2,or 3")
       print("Please try again")
    menu2()

    main()
1

There are 1 answers

0
Damian On

It looks like you are BLASTing NCBI, not a local BLAST. I suggest you start here for a local BLAST:

https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=Download