Skip to content

Commit

Permalink
export: fix export with non-default mode
Browse files Browse the repository at this point in the history
  • Loading branch information
trichter committed Oct 1, 2024
1 parent 01d772d commit 754c37c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion anchorna/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def write_anchors(anchors, fname, mode=None):
The result is a file which should not be read in again with anchorna.
"""
from anchorna import __version__
fts = anchors.convert2fts()
fts = anchors.convert2fts(mode=mode)
offsets = {ft.seqid: ft.meta._gff.pop('offset') for ft in fts}
offsets_header = ''.join(f'#offset {seqid} {offset}\n' for seqid, offset in offsets.items())
if mode is None:
Expand Down
12 changes: 7 additions & 5 deletions anchorna/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _apply_mode(i, o, mode, islen=False):
"""
Transform index, allowed modes are ``'aa', 'cds', 'nt'``
"""
if mode == 'aa':
if mode in ('aa', None):
return i
elif mode == 'cds' or mode == 'nt' and islen:
return 3 * i
Expand Down Expand Up @@ -274,11 +274,11 @@ def remove_contradicting_anchors(self, aggressive=True):
self.data = [anchor for anchor in self if anchor not in remove_anchors]
return AnchorList(remove_anchors, no_cds=self.no_cds).sort()

def convert2fts(self):
def convert2fts(self, **kw):
"""
Convert anchors to `~sugar.core.fts.FeatureList` object
"""
return anchors2fts(self)
return anchors2fts(self, **kw)

def write(self, fname, **kw):
"""
Expand All @@ -288,7 +288,7 @@ def write(self, fname, **kw):
return write_anchors(self, fname, **kw)


def anchors2fts(anchors):
def anchors2fts(anchors, mode=None):
"""
Convert anchors to `~sugar.core.fts.FeatureList` object
Expand All @@ -306,7 +306,9 @@ def anchors2fts(anchors):
assert j > 0
ftype = 'fluke'
name=f'A{i}_{f.seqid}'
ft = Feature(ftype, start=f.start, stop=f.stop,
start = _apply_mode(f.start, f.offset, mode)
stop = _apply_mode(f.stop, f.offset, mode)
ft = Feature(ftype, start=start, stop=stop,
meta=dict(name=name, seqid=f.seqid, score=f.score,
_gff=Attr(source='anchorna', word=f.word,
median_score=f.median_score)))
Expand Down

0 comments on commit 754c37c

Please sign in to comment.