Commit 1ef1c11e authored by cmaffeo2's avatar cmaffeo2 Committed by New Tbgl User
Browse files

Added function for setting sequence of strand

parent 9e20fee1
......@@ -333,7 +333,7 @@ class Segment(ConnectableElement, Group):
def randomize_unset_sequence(self):
bases = list(seqComplement.keys())
bases = ['T'] ## FOR DEBUG
# bases = ['T'] ## FOR DEBUG
if self.sequence is None:
self.sequence = [random.choice(bases) for i in range(self.num_nts)]
else:
......@@ -890,20 +890,24 @@ class StrandInSegment(Group):
assert( np.abs(self.num_nts-nts) < 1e-5 )
# print(" Creating {}-nt StrandInSegment in {} from {} to {} {}".format(self.num_nts, segment.name, start, end, is_fwd))
def _nucleotide_ids(self):
nt0 = self.start # seg.contour_to_nt_pos(self.start)
assert( np.abs(nt0 - round(nt0)) < 1e-5 )
nt0 = int(round(nt0))
assert( (self.end-self.start) >= 0 or not self.is_fwd )
direction = (2*self.is_fwd-1)
return range(nt0,nt0 + direction*self.num_nts, direction)
def get_sequence(self):
""" return 5-to-3 """
# TODOTODO test
seg = self.segment
nt0 = self.start # seg.contour_to_nt_pos(self.start)
assert( np.abs(nt0 - round(nt0)) < 1e-5 )
nt0 = int(round(nt0))
assert( (self.end-self.start) >= 0 or not self.is_fwd )
if self.is_fwd:
# return [seqComplement[seg.sequence[nt]] for nt in range(nt0,nt0+self.num_nts)]
return [seg.sequence[nt] for nt in range(nt0,nt0+self.num_nts)]
return [seg.sequence[nt] for nt in self._nucleotide_ids()]
else:
return [seqComplement[seg.sequence[nt]] for nt in range(nt0,nt0-self.num_nts,-1)]
return [seqComplement[seg.sequence[nt]] for nt in self._nucleotide_ids()]
def get_contour_points(self):
c0,c1 = [self.segment.nt_pos_to_contour(p) for p in (self.start,self.end)]
......@@ -930,17 +934,23 @@ class Strand(Group):
self.add( s )
self.num_nts += s.num_nts
def set_sequence(self,sequence):
def set_sequence(self,sequence, set_complement=True):
## validate input
assert( np.all( [i in ('A','T','C','G') for i in sequence] ) )
assert( len(sequence) >= self.num_nts )
seq_idx = 0
## set sequence on each segment
for s in self.children:
seg = s.segment
# TODOTODO
...
if seg.sequence is None:
seg.sequence = [None for i in range(seg.num_nts)]
...
if self.is_fwd:
seg.sequence[nt] = sequence[seq_idx]
else:
seg.sequence[nt] = seqComplement[sequence[seq_idx]]
seq_idx += 1
# def get_sequence(self):
# sequence = []
......
Supports Markdown
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