How to write gffutils.feature.Feature object to file
1
2
Entering edit mode
3.2 years ago
Irsan ★ 7.8k

How do you most efficiently write a collection of gffutils.feature.Feature objects to file, so that you can create a gff3 file from a collection of Feature objects? I am trying to create a gff3 file without the ##FASTA part at the bottom, so I think I dont need the actual sequence records. Options I so far have are

  • Writing my own code, converting a Feature object to string. Have to take care with converting the attributes and all its items to an appropriate string representation
  • Converting gffutils.feature.Feature to Bio.SeqIO.SeqRecord objects, and using GFF.write() to create my file
  • I found some (old?) documentation that you could convert at Feature object to string by str(my_feature) or my_feature.str() or my_feature.to_string() but all those didnt work
my_feature = gffutils.feature.feature_from_line('contig_A\texample\texon\t1\t100\t.\t+\t.\tName=seq_A')
str(my_feature)
my_feature.str()
my_feature.to_string()
gffutils python gff • 1.3k views
ADD COMMENT
2
Entering edit mode
3.2 years ago

str(my_feature) works for me on gffutils v0.10.1:

import gffutils

with open('my.gff3', 'w') as fout:
    my_feature = gffutils.feature.feature_from_line('contig_A\texample\texon\t1\t100\t.\t+\t.\tName=seq_A')
    fout.write(str(my_feature) + '\n')

This issue should be relevant, in case you haven't seen it already.

ADD COMMENT
0
Entering edit mode

Excellent, my issue was that I am using Feature objects instantiated by myself using the Feature constructor. When I used floats for certain values in the Feature attributes and then the str() function crashes on converting those floats. When I instantiate a Feature object where all values in the attributes are strings it goes well!

ADD REPLY

Login before adding your answer.

Traffic: 1654 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6