From 78cb44ebe90b3cbaa5c4920aaee87e27d1117f40 Mon Sep 17 00:00:00 2001
From: Chris Maffeo <cmaffeo2@illinois.edu>
Date: Wed, 19 Sep 2018 11:57:46 -0500
Subject: [PATCH] Changed how particles are named so that it no longer reflects
the number of nucleotides represented, but is more robust to clashes
---
mrdna/readers/cadnano_segments.py | 16 +++++++++++-----
mrdna/segmentmodel.py | 16 ++++++++++------
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/mrdna/readers/cadnano_segments.py b/mrdna/readers/cadnano_segments.py
index 59fb2fe..0d366b8 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 91342f2..7f3c015 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
--
GitLab