1
$\begingroup$

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,

$\endgroup$
4
  • $\begingroup$ Presumably the field isn't called strand. Can you just print all the available fields in your db object? Also, what input are you giving? Can you provide a minimal, full example that we can try? $\endgroup$
    – terdon
    Sep 22 '21 at 16:43
  • 1
    $\begingroup$ gffutils databases don't typically have a single strand as they contain many features with different strands. It is typically the Feature objects within the database that have a strand attribute: pythonhosted.org/gffutils/autodocs/gffutils.Feature.html. Was it supposed to be db[mrna_id].strand or something like that. $\endgroup$ Sep 26 '21 at 23:20
  • $\begingroup$ Thank you, it worked. $\endgroup$ Sep 28 '21 at 0:55
  • $\begingroup$ If something worked, can you please write it up as an accepted answer? This keeps the StackExchange answer-fishing bots happy. $\endgroup$
    – gringer
    Sep 29 '21 at 4:42

Your Answer

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

Browse other questions tagged or ask your own question.