2
$\begingroup$

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

#!/usr/bin/python3
import click
import gffutils
import gffutils.gffwriter as gffwriter

@click.command()
@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'):
        print(gene)
        for i in db.children(gene, featuretype='mRNA', order_by='start'):
            print(i)
            print(i.id)
            print(i.attributes['Note']=["Gene description"])
            db.update([i])

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

$\endgroup$
  • $\begingroup$ Please edit your question and add a few lines of your input gff file that we can use for testing. $\endgroup$ – terdon Aug 28 '19 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 Aug 28 '19 at 11:57
  • $\begingroup$ Thank you it works now. $\endgroup$ – user977828 Aug 28 '19 at 12:09
  • $\begingroup$ @user977828 Please post the corrected code as an answer. $\endgroup$ – Devon Ryan Aug 28 '19 at 12:14
2
$\begingroup$

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"]
print(i)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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