This is a test version of Biostars. For the public version, visit https://www.biostars.org.
defining input files for SeqIO

very silly question from an absolute newbie, but I am trying to run a python script I found online and am running into some issues with defining the genbank file that is required as the input for the script.

This is the beginning of the script:

#!/usr/bin/env python
import sys
import Bio
from Bio import SeqIO, SeqFeature
from Bio.SeqRecord import SeqRecord
import os

def get_interregions(genbank_path, intergene_length=1):
    seq_record = SeqIO.parse(open(genbank_path), "genbank").next()

I have tried replacing the both instances of genbank_path with the name of the gb file (both with and without quotation marks) or the path to the current folder, but I am either getting a syntax error or a message saying

 "AttributeError: 'GenBankIterator' object has no attribute 'next'

Any suggestion would be much appreciated.

seqio python

The next is build in function of python, not class function of GenBankIterator. If you want to use it, you can do it like this:

next(SeqIO.parse(open(genbank_path), "genbank"))

If you are sure, that the files you are working with will always contain one sequence, you can use the SeqIO.read().

Hope this helps.

Btw.: don't forget to close the handle to the opened genbank_path file (you can run into problems with file handle limits). If you don't want to bother with opening and closing files here, the SeqIO will happily accept just path to a file. You can do just

next(SeqIO.parse(genbank_path, "genbank"))

0 answers

No answers yet.

Log in to answer this question.