diff --git a/segmentmodel.py b/segmentmodel.py index 4f17c64f7b4fb1d8dbc4e5b38cf4ac580144117f..9e34112dd8bb816c4273ba81027e1296606f4d90 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")])