Blastn through NCBIWWW not giving any results, as opposed to the online BLAST

55 Views Asked by At

I am trying to create a simple pipeline that takes a file containing various short sequences, and run them through blast. I have an example sequence;

>some_random_sequence
AAGGTTCGGTCCAAATTGAA

which returns a hit for FUT3 (using the RefSeq_Gene DB and using grch38 as an entrez_query). However, when I try to run this using NCBIWWW (Biopython) I don't get any results and I would like to figure out why.

A snippet that contains, the call that I am using, is listed here;

from Bio.Blast import NCBIWWW
from io import StringIO

sequence=['>some_random_sequence\n','AAGGTTCGGTCCAAATTGAA']

lines = "".join(sequence)
file = StringIO(lines)
results = NCBIWWW.qblast(
    program="blastn",
    database="RefSeq_Gene",
    entrez_query="grch38",
    sequence=file.read(),
    # Manually setting the parameters because short_query checks the length
    # of the sequence, but for some reason includes the name (resulting in
    # a length of 42, and thus defeating the entire purpose of using
    # short_query (which does a if len(sequence) < 31).
    expect=1000,
    word_size=7,
    nucl_reward=1,
    filter=None,
    lcase_mask=None,
    # short_query=True,
)
with open('test_output.xml', 'w') as save_file:
    blast_results = results.read()
    save_file.write(blast_results)
1

There are 1 best solutions below

0
On

Try this, I have included some action, which will help to know the status of yor submission and operation

from Bio import SeqIO
from Bio.Blast import NCBIWWW, NCBIXML
from io import StringIO

sequence = [">some_random_sequence\n", "AAGGTTCGGTCCAAATTGAA"]

lines = "".join(sequence)
file = StringIO(lines)

print("Connecting to NCBI server...")
results = NCBIWWW.qblast(
    program="blastn",
    database="refseq_genomic",
    entrez_query="grch38",
    sequence=file.getvalue(),
    expect=1000,
    word_size=7,
    nucl_reward=1,
    filter=None,
    lcase_mask=None,
    #timeout=60,  # Set a timeout of 60 seconds if u want 
)

print("Connection established. Submitting BLAST query...")
with open('test_output.xml', 'w') as save_file:
    blast_results = results.read()
    save_file.write(blast_results)

print("Query submitted. Waiting for results...")

# Parse and print the results
print("Results received. Parsing and displaying information...")
blast_parser = NCBIXML.parse(StringIO(blast_results))
for record in blast_parser:
    print(f"\nQuery: {record.query[:50]}...")  # Print first 50 characters of the query
    for alignment in record.alignments:
        print(f"Subject: {alignment.title}")
        for hsp in alignment.hsps:
            print(f"Score: {hsp.score}\nE-value: {hsp.expect}\n\n{hsp.query}\n{hsp.match}\n{hsp.sbjct}\n")

print("Process completed.")