Skip to content

Commit

Permalink
sort snap-trained.scaffold.fasta writing per bug #1060
Browse files Browse the repository at this point in the history
  • Loading branch information
hyphaltip committed Aug 21, 2024
1 parent 13c7f6d commit d674164
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions funannotate/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class suppress_stdout_stderr(object):
A context manager for doing a "deep suppression" of stdout and stderr in
Python, i.e. will suppress all print, even if the print originates in a
compiled C/Fortran sub-function.
This will not suppress raised exceptions, since exceptions are printed
This will not suppress raised exceptions, since exceptions are printed
to stderr just before a script exits, and after the context manager has
exited (at least, I think that is why it lets exceptions through).
Expand Down Expand Up @@ -8278,9 +8278,16 @@ def _sortDict(d):
trainingFasta = os.path.join(dir, "snap-training.scaffolds.fasta")
with open(trainingFasta, "w") as outfile:
with open(os.path.abspath(fasta), "r") as infile:
seqids = {}
for title, seq in SimpleFastaParser(infile):
if title in list(scaff2genes.keys()):
outfile.write(">{:}\n{:}\n".format(title, softwrap(seq)))
seqids[title] = seq
# need to write out the fasta file in a sorted way otherwise the ZFF and FASTA don't match
# cannot assume the input genome is actual in ID sorted order
# see bug #1060
for title in natsort(seqids):
outfile.write(">{:}\n{:}\n".format(title, softwrap(seqids[title])))


# convert to ZFF format
origzff = os.path.join(dir, "snap.training.zff")
Expand Down

0 comments on commit d674164

Please sign in to comment.