From ab3f6df30ac7a4b2b79be07317a9d64216832f4c Mon Sep 17 00:00:00 2001
From: Chris Maffeo <cmaffeo2@illinois.edu>
Date: Fri, 21 Sep 2018 13:07:24 -0500
Subject: [PATCH] remove_dna now removes sequence

---
 mrdna/model/nbPot.py  |  2 +-
 mrdna/segmentmodel.py | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/mrdna/model/nbPot.py b/mrdna/model/nbPot.py
index e730a45..697f675 100644
--- a/mrdna/model/nbPot.py
+++ b/mrdna/model/nbPot.py
@@ -129,7 +129,7 @@ def nbPot(x,bps1,bps2):
         try:
             _pot_dict[key] = _cached_params['{}:{}'.format(*key)]
         except: 
-            print( "failed" )
+            # print( "Unable to find cached parammeters for beads {}-{}".format(*key) )
             cache_file = CACHE_DIR / filename
             try:
                 _pot_dict[key] = load_np(cache_file)
diff --git a/mrdna/segmentmodel.py b/mrdna/segmentmodel.py
index f62513c..1fa1be2 100644
--- a/mrdna/segmentmodel.py
+++ b/mrdna/segmentmodel.py
@@ -414,7 +414,7 @@ class Segment(ConnectableElement, Group):
     def _get_location_positions(self):
         return [self.contour_to_nt_pos(l.address) for l in self.locations]
 
-    def insert_dna(self, at_nt: int, num_nt: int):
+    def insert_dna(self, at_nt: int, num_nt: int, seq=tuple()):
         assert(np.isclose(np.around(num_nt),num_nt))
         if at_nt < 0:
             raise ValueError("Attempted to insert DNA into {} at a negative location".format(self))
@@ -427,13 +427,15 @@ class Segment(ConnectableElement, Group):
         nt_positions = self._get_location_positions()
         new_nt_positions = [p if p <= at_nt else p+num_nt for p in nt_positions]
 
+        ## TODO: handle sequence
+
         self.num_nt = self.num_nt+num_nt
 
         for l,p in zip(self.locations, new_nt_positions):
             l.address = self.nt_pos_to_contour(p)
 
     def remove_dna(self, first_nt: int, last_nt: int):
-        """ Removes nucleotides between first_nt and last_nt """
+        """ Removes nucleotides between first_nt and last_nt, inclusive """
         assert(np.isclose(np.around(first_nt),first_nt))
         assert(np.isclose(np.around(last_nt),last_nt))
         tmp = min((first_nt,last_nt))
@@ -456,10 +458,16 @@ class Segment(ConnectableElement, Group):
         if len(bad_locations) > 0:
             raise Exception("Attempted to remove DNA containing locations {} from {} between {} and {}".format(bad_locations,self,first_nt,last_nt))
 
-        num_nt = last_nt-first_nt
-        new_nt_positions = [p if p <= last_nt else p-num_nt for p in nt_positions]
+        removed_nt = last_nt-first_nt+1
+        new_nt_positions = [p if p <= last_nt else p-removed_nt for p in nt_positions]
+        num_nt = self.num_nt-removed_nt
+
+        if self.sequence is not None and len(self.sequence) == self.num_nt:
+            self.sequence = [s for s,i in zip(self.sequence,range(self.num_nt)) 
+                                if i < first_nt or i > last_nt]
+            assert( len(self.sequence) == num_nt )
 
-        self.num_nt = self.num_nt-num_nt
+        self.num_nt = num_nt
 
         for l,p in zip(self.locations, new_nt_positions):
             l.address = self.nt_pos_to_contour(p)
-- 
GitLab