This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to scan NCBI database using Biopython and save information as a fasta file?

Hello, I am attempting to use Entrez to search the keyword “covid” in the nucleotide database and write the top 5 sequence records to a fasta file.

I completed the code for question 1, but I am having trouble with saving the sequences in a fasta file. Any advice would be much appreciated, thank you.

enter image description here

entrez ncbi biopython

Makayla : Deleting questions which are solved is not appropriate. Consider accepting the answer (green check mark) since it solved your issue.

1 answer

Is the image above your own code or simply a screen grab from somewhere (it is always best to actually post code by pasting and using 101010 button to format).

If this is your code then you are retrieving data as XML and not fasta. So change to (retmode="fasta") and that should get you fasta sequence. Following is Entrezdirect equivalent:

$ efetch -db nuccore -id NM_001283041 -format fasta | head -5
>NM_001283041.3 Homo sapiens ubiquitin specific peptidase 25 (USP25), transcript variant 1, mRNA
ATTCCGGGCGGCCGCTCCCTCCGTCCCCTCTCTCCCTTCCCCAAAGCAGCCCGCGGACCGGCAGCAAAGG
AACGTGCGAACGCGTGACGCCGCCCGACTGGCTCGCGCTCTCCCGTGCCCCGGCGTCCTCCGCCCGCTCA
TGGCCCGGGCCGCCGCGGACGAGCGGCGCTGAGGCGGGCCGCGTGGAGACGTGAGGCGGCCGCCGTGGCC

Thank you, that worked.

Log in to answer this question.