def test_move(self): stat = ftmstat.StemStat("stem new:s_0 5 10.388 2.43294047108") oldstat = self.sm.elem_defs["s0"] self.mover_realstats._prev_stats = {} movestring = self.mover_realstats._move(self.sm, "s0", stat) self.assertEqual(self.sm.elem_defs["s0"], stat) self.assertEqual(self.mover_realstats._prev_stats["s0"], oldstat) self.assertEqual(movestring, "s0:test:s_0->new:s_0;")
def parse_stats_file(file_handle): stats = { "stem": defaultdict(list), "angle": defaultdict(list), "loop": defaultdict(list), "3prime": defaultdict(list), "5prime": defaultdict(list) } for line in file_handle: line = line.strip() if "#" in line: line = line.split('#')[0] if not line: continue if line.startswith("stem"): stem_stat = ftmstats.StemStat(line) stats["stem"][stem_stat.bp_length].append(stem_stat) elif line.startswith("angle") or line.startswith( "open") or line.startswith("pseudo"): angle_stat = ftmstats.AngleStat() try: angle_stat.parse_line(line) except Exception as e: with log_to_exception(log, e): log.error( "Could not parse file due to error parsing line '{}'". format(line)) raise if len(angle_stat.define) > 0 and angle_stat.define[ 0] == 1: #An angle at the beginning of a structure #I guess this should never happen, if the stats do not stem from faulty bulge graphs. log.error( "Ignoring angle stat {} because it is at the beginning of a structure." " Does the stat come from a faulty BulgeGraph?".format( angle_stat.pdb_name)) continue angle_stat.ang_type = patch_angtype(angle_stat.ang_type) log.debug( "Reading angle_stat with dimensions %s and %s, and type %s. With define %s", angle_stat.dim1, angle_stat.dim2, angle_stat.ang_type, angle_stat.define) stats["angle"][(angle_stat.dim1, angle_stat.dim2, angle_stat.ang_type)].append(angle_stat) # Adding the reverse does not work as intended and produces a lot of structures # that do not fulfill the constraint energy. # stats["angle"][(angle_stat.dim1, angle_stat.dim2, -angle_stat.ang_type)].append(angle_stat) # Note that CoarseGrainRNA.get_stats extracts two angle stats per angle. else: key = line.split()[0] if key not in ["3prime", "5prime", "loop"]: raise ValueError( "Illegal line in stats file: '{}'".format(line)) stat = ftmstats.LoopStat(line) stats[key][stat.bp_length].append(stat) return stats
def get_stem_stats(self, stem): ''' Calculate the statistics for a stem and return them. These statistics will describe the length of the stem as well as how much it twists. @param stem: The name of the stem. @return: A StemStat structure containing the above information. ''' ss = ftms.StemStat() ss.pdb_name = self.name #ss.bp_length = abs(self.defines[stem][0] - self.defines[stem][1]) ss.bp_length = self.stem_length(stem) ss.phys_length = ftuv.magnitude(self.coords[stem][0] - self.coords[stem][1]) ss.twist_angle = ftug.get_twist_angle(self.coords[stem], self.twists[stem]) ss.define = self.defines[stem] return ss
def test_read_stats_file(self): stats = fbstat.read_stats_file("test/fess/data/test1.stats") log.info(stats) self.assertEqual(len(stats["stem"]), 1) self.assertEqual(len(stats["angle"]), 3) self.assertEqual(len(stats["loop"]), 2) self.assertEqual(len(stats["3prime"]), 1) self.assertEqual(len(stats["5prime"]), 1) self.assertEqual(stats["stem"][5], [ ftmstats.StemStat( "stem test:s_0 5 10.388 2.43294047108 1 5 10 15 GCAUG UGCAU") ]) a_stat = ftmstats.AngleStat() a_stat.parse_line( "angle test:i_0 5 2 2.203691 2.099941 0.586450 17.134279 1.191397 1.274896 1" ) self.assertEqual(stats["angle"][(5, 2, 1)], [a_stat]) a_stat.parse_line( "angle test:m_0 4 1000 0.985166 -1.185545 -2.000463 13.701389 0.982669 0.267821 -4" ) self.assertEqual( stats["angle"][( 4, 1000, 6 )], # We patched ang_type to use 6 for all ml-segments. -6<=>-3, but -6<=>+4 [a_stat]) self.assertEqual(stats["loop"][6], [ ftmstats.LoopStat( "loop test:h_0 6 15.2401560955 0.269833051418 0.731484795668") ]) self.assertEqual(stats["3prime"][4], [ ftmstats.LoopStat( "3prime test:t_0 4 20.4034805163 1.47912394946 -0.0715301558972" ) ]) self.assertEqual(stats["5prime"][4], [ ftmstats.LoopStat( "5prime test:f_0 4 20.4034805163 1.47912394946 -0.0715301558972" ) ])
def setUp(self): self.example_stem_stat = ftms.StemStat( "stem exampleStat 3 5.29399999969 1.19302425058 1 3 7 9") self.example_hairpin_stat = ftms.LoopStat( "loop exampleStat 3 14.8069260882 1.2124527925 1.12478051025 86 88" )