Writing Genbank files
1
0
Entering edit mode
6.4 years ago
adjon081 • 0

Hi all,

I have information about a gene stored in a Python Class as shown below

class Gene():

"""
Gene:
    Class which stores all the information about a gene from GenBank file
    locus_tag, note, translation, protein_id, product are 
    all set to N/A by default and start, stop, codon_start, 
    transl_table and strand are 0
"""


def __init__(self,locus_tag = "N/A", gene = "N/A", 
                start = 0, stop = 0, note = "N/A", codon_start = 0, 
                transl_table = 0, product = "N/A", protein_id = "N/A", 
                translation = "N/A", strand = 0):
    self.__locus_tag = locus_tag
    self.__note = note
    self.__start = start
    self.__stop = stop
    self.__codon_start = codon_start
    self.__transl_table = transl_table
    self.__product = product
    self.__protein_id = protein_id
    self.__translation = translation
    self.__strand = strand
    self.__gene = gene

All these are arranged in a circular linked list and I want to write this information into a genbank file, and have come up with the following

def record(self):
"""
    Returns a record of a gene to be written to a genbank file
"""
z = self.get_strand()
sequence = Seq(self.get_translation(), IUPAC.protein)
rec = SeqRecord(sequence,
                   id = self.get_protein(),
                   name = self.get_gene(),
                   description = self.get_note())
loc = SeqFeature(FeatureLocation(
                (self.get_start(),self.get_stop()),
                type="CDS",strand=self.get_strand()))
rec.features = [loc]
print(rec.format("genbank"))

but every time I run this code I get this error:

TypeError: __init__() got an unexpected keyword argument 'type'

Please does anyone know how to do this or has a better way of doing this?

Thanks in advance

biopython Genbank Python • 2.3k views
ADD COMMENT
5
Entering edit mode
6.4 years ago
mobiusklein ▴ 180

It looks like a parenthesis problem.

Solution:

loc = SeqFeature(FeatureLocation(self.get_start(),self.get_stop()),
                 type="CDS",strand=self.get_strand())

You wrote

loc = SeqFeature(FeatureLocation(
            (self.get_start(),self.get_stop()),
            type="CDS",strand=self.get_strand()))

You have a nested construction which can be re-formatted like so

loc = SeqFeature(
    FeatureLocation(
        (
            self.get_start(),self.get_stop()
        ), type="CDS",strand=self.get_strand()
    )
)

placing each pair of parentheses's contents in new lines, indenting the contents accordingly. What's happening is you've passed the type and strand arguments to SeqFeature as arguments to the FeatureLocation __init__ method. You're also passing a tuple of the start and stop coordinates as the first argument to FeatureLocation, when you should be passing the start and stop coordinates separately.

ADD COMMENT
0
Entering edit mode

Thanks a lot, greatly appreciated

ADD REPLY
0
Entering edit mode

I got this error,

AttributeError: 'SeqRecord' object has no attribute 'get_strand'

what I'm missing?

That's for CDS sequences, but what if I want the same complete file that is downloaded from the browser?

Thanks!

ADD REPLY
0
Entering edit mode

The entity denoted self in the code being debugged here was an instance of a class OP's created. I don't think it is 1:1 with SeqRecord. If you're trying to write a SeqRecord in GenBank format, I think you'd just pass your SeqRecord through SeqIO.write(records, handle, "genbank"). I'm not a regular user of BioPython, so I can't comment further on that.

ADD REPLY

Login before adding your answer.

Traffic: 2859 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