Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2012 16:08
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Rename a genbank file to the description of the it's first sequence
#!/usr/bin/env python
import sys
import os
# Biopython libraries or nothing
from Bio import SeqIO
except ImportError:
sys.exit("Biopython library not found. See for installation instructions.")
# User have to pass the genbank file as the first argument in command line
if len(sys.argv) < 2:
sys.exit('Usage: %s <GENBANK FILE>' % sys.argv[0])
# File must exist
genbank_file = sys.argv[1]
if not os.path.exists(genbank_file):
sys.exit('ERROR: File %s was not found!' % sys.argv[1])
# Retrieves the informations and prepares the new file name
parser = SeqIO.parse(open(genbank_file,"r"), "genbank")
gb_first_record =
description = gb_first_record.description.replace(',', '').replace('.', '').replace(' ','_')
os.rename(genbank_file, description+".gbk")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment