defining input files for SeqIO
0
0
Entering edit mode
3 months ago

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 • 162 views
ADD COMMENT
0
Entering edit mode

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"))
ADD REPLY

Login before adding your answer.

Traffic: 1547 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6