From 5455d407e70a28a15ab9a8608611575dc35ec5c6 Mon Sep 17 00:00:00 2001 From: Chris Maffeo <cmaffeo2@illinois.edu> Date: Tue, 13 Aug 2019 17:01:35 -0500 Subject: [PATCH] Moved _connect_ends routine from 'DoubleStrandedSegment' to parent 'Segment' --- mrdna/segmentmodel.py | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/mrdna/segmentmodel.py b/mrdna/segmentmodel.py index 86550d1..0ffdc48 100644 --- a/mrdna/segmentmodel.py +++ b/mrdna/segmentmodel.py @@ -754,6 +754,30 @@ class Segment(ConnectableElement, Group): on_fwd_strand = True self.add_location(nt,"3prime",on_fwd_strand) + ## Real work + def _connect_ends(self, end1, end2, type_, force_connection=False): + debug = False + ## TODO remove self? + ## validate the input + for end in (end1, end2): + assert( isinstance(end, Location) ) + assert( end.type_ in ("end3","end5") ) + assert( end1.type_ != end2.type_ ) + + ## Remove other connections involving these points + if end1.connection is not None: + if debug: print("WARNING: reconnecting {}".format(end1)) + end1.connection.delete() + if end2.connection is not None: + if debug: print("WARNING: reconnecting {}".format(end2)) + end2.connection.delete() + + ## Create and add connection + if end2.type_ == "end5": + end1.container._connect( end2.container, Connection( end1, end2, type_=type_ ), in_3prime_direction=True ) + else: + end2.container._connect( end1.container, Connection( end2, end1, type_=type_ ), in_3prime_direction=True ) + def get_3prime_locations(self): return sorted(self.get_locations("3prime"),key=lambda x: x.address) @@ -1126,29 +1150,6 @@ class DoubleStrandedSegment(Segment): loc.is_3prime_side_of_connection = True other_loc.is_3prime_side_of_connection = False - ## Real work - def _connect_ends(self, end1, end2, type_, force_connection): - debug = False - ## TODO remove self? - ## validate the input - for end in (end1, end2): - assert( isinstance(end, Location) ) - assert( end.type_ in ("end3","end5") ) - assert( end1.type_ != end2.type_ ) - - ## Remove other connections involving these points - if end1.connection is not None: - if debug: print("WARNING: reconnecting {}".format(end1)) - end1.connection.delete() - if end2.connection is not None: - if debug: print("WARNING: reconnecting {}".format(end2)) - end2.connection.delete() - - ## Create and add connection - if end2.type_ == "end5": - end1.container._connect( end2.container, Connection( end1, end2, type_=type_ ), in_3prime_direction=True ) - else: - end2.container._connect( end1.container, Connection( end2, end1, type_=type_ ), in_3prime_direction=True ) def _get_num_beads(self, contour, max_basepairs_per_bead, max_nucleotides_per_bead): # return int(contour*self.num_nt // max_basepairs_per_bead) return int(contour*(self.num_nt**2/(self.num_nt+1)) // max_basepairs_per_bead) @@ -2887,7 +2888,8 @@ class SegmentModel(ArbdModel): history = [] if not strands_cover_segment(seg, is_fwd): pos = nt = find_nt_not_in_strand(seg, is_fwd) - s = Strand(is_circular = True) + s = Strand(segname="S{:03d}".format(len(strands)), + is_circular = True) history = _recursively_build_strand(s, seg, pos, is_fwd) strands.append(s) return history -- GitLab