3

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

terdon
  • 10,071
  • 5
  • 22
  • 48
user977828
  • 453
  • 3
  • 9
  • Please [edit] your question and add a few lines of your input gff file that we can use for testing. – terdon Aug 28 '19 at 11:55
  • 1
    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. – terdon Aug 28 '19 at 11:57
  • Thank you it works now. – user977828 Aug 28 '19 at 12:09
  • @user977828 Please post the corrected code as an answer. – Devon Ryan Aug 28 '19 at 12:14

1 Answers1

2

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)
terdon
  • 10,071
  • 5
  • 22
  • 48