ViennaRNA / forgi

An RNA manipulation library.
GNU General Public License v3.0
52 stars 31 forks source link

Problem encountered: to_neato_string() #42

Open stevewu2001 opened 2 years ago

stevewu2001 commented 2 years ago

The following code would produce a KeyError:

""" import forgi.graph.bulge_graph as fgb import sys import os

class RedirectStdStreams(object): def init(self, stdout=None, stderr=None): self._stdout = stdout or sys.stdout self._stderr = stderr or sys.stderr def enter(self): self.old_stdout, self.old_stderr = sys.stdout, sys.stderr self.old_stdout.flush(); self.old_stderr.flush() sys.stdout, sys.stderr = self._stdout, self._stderr def exit(self, exc_type, exc_value, traceback): self._stdout.flush(); self._stderr.flush() sys.stdout = self.old_stdout sys.stderr = self.old_stderr

def create_bg_from_db(db_str): devnull = open(os.devnull, 'w') with RedirectStdStreams(stdout=devnull): bg = fgb.BulgeGraph.from_dotbracket(db_str) return bg

db_str = ".................." bg = create_bg_from_db(db_str) print(bg.to_neato_string()) """

If the dot-bracket string does not have any brackets (no stems), there will be a missing key 's0'.