Commit ab3f6df3 authored by cmaffeo2's avatar cmaffeo2
Browse files

remove_dna now removes sequence

parent 3cfec3ce
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment