如何在python / biopython中对本地数据库进行本地查询?

时间:2019-03-22 22:00:26

标签: python biopython blast jquery-ui-selectmenu

首先,我要明确地说我是编程方面的超级新手。 我有2个zip文件(每个文件包含一个数据库)和4个fasta文件(每个文件包含三个蛋白质序列,一个文件包含一个核苷酸序列)。

我想创建一个程序,用户可以从菜单中选择一个程序,以针对其数据库分别运行氨基酸或核苷酸文件。下面提到的代码是我能够做到的最好的代码。不幸的是,它根本没有运行。如果您能指导我如何处理我,我将非常有责任。

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 个答案:

答案 0 :(得分:0)

您似乎是BLASTING NCBI,而不是本地BLAST。我建议您从这里开始进行本地BLAST:

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