I failed to add Note=Gene description to mRNA attribute with the below code:

import click
import gffutils
import gffutils.gffwriter as gffwriter

@click.option('--gff3', help="Provide GFF3 file", required=True)
@click.option('--keep', help="Keep GFF3 file", required=True)
@click.option('--reject', help="Reject GFF3 file", required=True)
def run(gff3, keep, reject):
    #db = gffutils.create_db(gff3, dbfn='data/test.db', force=True, keep_order=True, merge_strategy='merge',
    #                        sort_attribute_values=True)

    db = gffutils.FeatureDB('data/test.db', keep_order=True)
    for gene in db.features_of_type('gene', order_by='start'):
        for i in db.children(gene, featuretype='mRNA', order_by='start'):
            print(i.attributes['Note']=["Gene description"])

I got the following error:

File "/projects/bioinf-scripts/mod_braker_gff3.py", line 20
    print(i.attributes['Note']=["Gene description"])
SyntaxError: keyword can't be an expression

What did I miss?

Thank you in advance

  • $\begingroup$ Please edit your question and add a few lines of your input gff file that we can use for testing. $\endgroup$
    – terdon
    Commented Aug 28, 2019 at 11:55
  • 1
    $\begingroup$ But why are you printing it? Shouldn't you first add the attribute (i.attributes['Note']=["Gene description"]) and then print it print(i.attributes['Note'])? I don't know gffutils, but it seems strange to print something before setting it. $\endgroup$
    – terdon
    Commented Aug 28, 2019 at 11:57
  • $\begingroup$ Thank you it works now. $\endgroup$
    – user977828
    Commented Aug 28, 2019 at 12:09
  • $\begingroup$ @user977828 Please post the corrected code as an answer. $\endgroup$
    – Devon Ryan
    Commented Aug 28, 2019 at 12:14

1 Answer 1


You are printing the attribute before setting it, that's why it's complaining. So instead of this:

    print(i.attributes['Note']=["Gene description"])

Set it first and then print:

i.attributes['Note']=["Gene description"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.