daler / gffutils

GFF and GTF file manipulation and interconversion
http://daler.github.io/gffutils
MIT License
287 stars 78 forks source link

AttributeError: 'FeatureDB' object has no attribute 'strand' #170

Closed mictadlo closed 2 years ago

mictadlo commented 3 years ago

Hello, It appers when a gene has a negative strand then I need to reverse the sequence. Unfortunately, I got the following error:

print("1" + '"' + str(fastaIdx) + '"' + '"' + str(mrna_id) + "'" + db.strand())
AttributeError: 'FeatureDB' object has no attribute 'strand'

with the following code:

import gffutils
import pyfaidx
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC

def getPeptideSeq(fastaIDX, db, mrna_id):
    print("Petide Sequence")
    return Seq(getCdsSeq(fastaIDX, db, db[mrna_id]), IUPAC.unambiguous_dna).translate()

if __name__ == '__main__':
    db = gffutils.FeatureDB('annotation.db', keep_order=True)
    fastaIdx = pyfaidx.Fasta('assembly.fasta')
    print("1" + '"' + str(fastaIdx) + '"' + '"' + str(mrna_id) + "'" + db.strand())

        seq = getPeptideSeq(fastaIdx, db, mrna_id)

What did I miss?

Thank you in advance,

Best wishes,

Michal

daler commented 2 years ago

I guess it's not clear to me what is intended in your example code, but that's correct behavior in that a database itself doesn't have a strand -- it's the individual features that have strands. So you'd probably want to iterate over features of interest at some point, and work on those rather than the entire db.