sequence_hard
sequence_hard

Reputation: 5385

How to get sequence description from gi number through biopython?

I have a list of GI (genbank identifier) numbers. How can I get the Sequence description (as 'mus musculus hypothetical protein X') for each GI number so that I can store it in a variable and write it to a file? Thanks for your help!

Upvotes: 0

Views: 245

Answers (2)

Damian
Damian

Reputation: 21

This is a script I wrote to pull the entire GenBank file for each genbank identifier in a file. It should be easy enough to change for your applications.

#This program will open a file containing NCBI sequence indentifiers, find the associated 
#information and write the data to *.gb

import os
import sys
from Bio import Entrez
Entrez.email = "[email protected]" #Always tell NCBI who you are

try:                              #checks to make sure input file is in the folder
    name = raw_input("\nEnter file name with sequence identifications only: ")
    handle = open(name, 'r')
except:
    print "File does not exist in folder! Check file name and extension."
    quit()

outfile = os.path.splitext(name)[0]+"_GB_Full.gb"
totalhand = open(outfile, 'w')

for line in handle:
    line = line.rstrip()                #strips \n from file
    print line
    fetch_handle = Entrez.efetch(db="nucleotide", rettype="gb", retmode="text", id=line)
    data = fetch_handle.read()
    fetch_handle.close()
    totalhand.write(data)

Upvotes: 2

sequence_hard
sequence_hard

Reputation: 5385

So, in case anybody else had that question, here is the solution:

handle=Entrez.esummary(db="nucleotide, protein, ...", id="gi or NCBI_ref number")
record=Entrez.read(handle)
handle.close()
description=record[0]["Title"]
print description

This will print the sequence description that corresponds to the identifier.

Upvotes: 0

Related Questions