diff --git a/mrdna/readers/cadnano_segments.py b/mrdna/readers/cadnano_segments.py index 59fb2fe10feff8f9e6d299b2fde68307b35d9808..0d366b8134522e7a7d6781bfe8ccc55f7184a567 100644 --- a/mrdna/readers/cadnano_segments.py +++ b/mrdna/readers/cadnano_segments.py @@ -327,9 +327,12 @@ class cadnano_part(SegmentModel): bp = int(round(b.get_nt_position(segment))) if bp < 0: bp = 0 if bp >= segment.num_nt: bp = segment.num_nt-1 - b.beta = bp_to_zidx[bp] - if 'orientation_bead' in b.__dict__: - b.orientation_bead.beta = bp_to_zidx[bp] + try: + b.beta = bp_to_zidx[bp] + if 'orientation_bead' in b.__dict__: + b.orientation_bead.beta = bp_to_zidx[bp] + except: + pass seg._generate_bead_callbacks.append(callback) def atomic_callback(nucleotide, bp_to_zidx=bp_to_zidx): @@ -338,8 +341,11 @@ class cadnano_part(SegmentModel): bp = int(round(segment.contour_to_nt_pos( nt.contour_position ))) if bp < 0: bp = 0 if bp >= segment.num_nt: bp = segment.num_nt-1 - nt.beta = bp_to_zidx[bp] - nt.parent.occupancy = segment.occupancy + try: + nt.beta = bp_to_zidx[bp] + nt.parent.occupancy = segment.occupancy + except: + pass seg._generate_nucleotide_callbacks.append(atomic_callback) diff --git a/mrdna/segmentmodel.py b/mrdna/segmentmodel.py index 91342f2a4c829332d8477f4e3779c477326389f6..7f3c015c016a185e70bc7f14defdbebd695e752b 100644 --- a/mrdna/segmentmodel.py +++ b/mrdna/segmentmodel.py @@ -276,8 +276,8 @@ class SegmentParticle(PointParticle): if seg == target_seg: # pdb.set_trace() ## Found a segment in our target - sign = (contour_in_seg == 1) - (contour_in_seg == 0) - assert( sign in (1,-1) ) + sign = 1 if contour_in_seg == 1 else -1 + if sign == -1: assert( contour_in_seg == 0 ) if distance < cutoff: # TODO: check if this does anything cutoff = distance return [[distance, contour_in_seg+sign*seg.nt_pos_to_contour(distance)]], [(seg, contour_in_seg, distance)] @@ -1932,17 +1932,21 @@ class SegmentModel(ArbdModel): """ Reassign bead types """ if self.DEBUG: print("Assigning bead types") beadtype_s = dict() - + beadtype_count = dict(D=0,O=0,S=0) + def _assign_bead_type(bead, num_nt, decimals): num_nt0 = bead.num_nt bead.num_nt = np.around( np.float32(num_nt), decimals=decimals ) - key = (bead.type_.name[0].upper(), bead.num_nt) + char = bead.type_.name[0].upper() + key = (char, bead.num_nt) if key in beadtype_s: bead.type_ = beadtype_s[key] else: t = deepcopy(bead.type_) - t.__dict__["nts"] = bead.num_nt*2 if t.name[0].upper() in ("D","O") else bead.num_nt - t.name = t.name + "%03d" % (t.nts*10**decimals) + t.__dict__["nts"] = bead.num_nt*2 if char in ("D","O") else bead.num_nt + # t.name = t.name + "%03d" % (t.nts*10**decimals) + t.name = char + "%03d" % (beadtype_count[char]) + beadtype_count[char] += 1 if self.DEBUG: print( "{} --> {} ({})".format(num_nt0, bead.num_nt, t.name) ) beadtype_s[key] = bead.type_ = t