Question: Writing Genbank files
0
gravatar for adjon081
3.1 years ago by
adjon0810
adjon0810 wrote:

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

genbank biopython python • 1.4k views
ADD COMMENTlink modified 3.1 years ago by mobiusklein160 • written 3.1 years ago by adjon0810
5
gravatar for mobiusklein
3.1 years ago by
mobiusklein160
United States
mobiusklein160 wrote:

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 COMMENTlink written 3.1 years ago by mobiusklein160

Thanks a lot, greatly appreciated

ADD REPLYlink written 3.1 years ago by adjon0810

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 REPLYlink written 2.1 years ago by malj20

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 REPLYlink written 2.1 years ago by mobiusklein160
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1476 users visited in the last hour