From e440cc78dafd6927275b5541836cd5744623553a Mon Sep 17 00:00:00 2001 From: Chris Maffeo <cmaffeo2@illinois.edu> Date: Fri, 17 Aug 2018 15:02:23 -0500 Subject: [PATCH] Enabled automatic creation of terminal 5prime and 3prime ends --- segmentmodel.py | 62 +++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/segmentmodel.py b/segmentmodel.py index 4f17c64..9e34112 100644 --- a/segmentmodel.py +++ b/segmentmodel.py @@ -2061,41 +2061,33 @@ class SegmentModel(ArbdModel): """ Ensure unconnected ends have 5prime Location objects """ for seg in self.segments: ## TODO move into Segment calls - import pdb - if False: # TODO: Make this happen conditionally - if seg.start5.connection is None: - add_end = True - for l in seg.get_locations("5prime"): - if l.address == 0 and l.on_fwd_strand: - add_end = False - break - if add_end: - seg.add_5prime(0) - if 'end5' in seg.__dict__ and seg.end5.connection is None: - add_end = True - for l in seg.get_locations("5prime"): - if l.address == 1 and (l.on_fwd_strand is False): - add_end = False - break - if add_end: - seg.add_5prime(seg.num_nt-1,on_fwd_strand=False) - - if 'start3' in seg.__dict__ and seg.start3.connection is None: - add_end = True - for l in seg.get_locations("3prime"): - if l.address == 0 and (l.on_fwd_strand is False): - add_end = False - break - if add_end: - seg.add_3prime(0,on_fwd_strand=False) - if seg.end3.connection is None: - add_end = True - for l in seg.get_locations("3prime"): - if l.address == 1 and l.on_fwd_strand: - add_end = False - break - if add_end: - seg.add_3prime(seg.num_nt-1) + five_prime_locs = seg.get_locations("5prime") + three_prime_locs = seg.get_locations("3prime") + + def is_start_5prime(l): + return l.get_nt_pos() < 1 and l.on_fwd_strand + def is_end_5prime(l): + return l.get_nt_pos() > seg.num_nt-1 and not l.on_fwd_strand + def is_start_3prime(l): + return l.get_nt_pos() < 1 and not l.on_fwd_strand + def is_end_3prime(l): + return l.get_nt_pos() > seg.num_nt-1 and l.on_fwd_strand + + if seg.start5.connection is None: + if len(list(filter( is_start_5prime, five_prime_locs ))) == 0: + seg.add_5prime(0) # TODO ensure this is the same place + + if 'end5' in seg.__dict__ and seg.end5.connection is None: + if len(list(filter( is_end_5prime, five_prime_locs ))) == 0: + seg.add_5prime(seg.num_nt-1,on_fwd_strand=False) + + if 'start3' in seg.__dict__ and seg.start3.connection is None: + if len(list(filter( is_start_3prime, three_prime_locs ))) == 0: + seg.add_3prime(0,on_fwd_strand=False) + + if seg.end3.connection is None: + if len(list(filter( is_end_3prime, three_prime_locs ))) == 0: + seg.add_3prime(seg.num_nt-1) # print( [(l,l.get_connected_location()) for l in seg.locations] ) # addresses = np.array([l.address for l in seg.get_locations("5prime")]) -- GitLab