def setUp(self): random.seed(30) self.max_homopolymer = 3 self.repeat_length = 4 self.max_content = 0.6 self.sequences = [ "".join([index_base.get(random.randint(0, 3)) for _ in range(24)]) for _ in range(50) ]
def encode(self, bit_segments): dna_sequences = [] for segment_index, bit_segment in enumerate(bit_segments): dna_sequence = [] if len(bit_segment) % 2 != 0: bit_segment = [0] + bit_segment for position in range(0, len(bit_segment), 2): dna_sequence.append(index_base.get(self.mapping_rules.index(bit_segment[position: position + 2]))) dna_sequences.append(dna_sequence) if self.need_logs: self.monitor.output(segment_index + 1, len(bit_segments)) return dna_sequences
def get_dna(self, seed, prng, bit_segments, header_size): self.seed = seed self.payload = None self.chuck_indices = prng.get_src_blocks_wrap(seed) for chuck_index in self.chuck_indices: if self.payload is None: self.payload = bit_segments[chuck_index] else: self.payload = list( map(self.xor, self.payload, bit_segments[chuck_index])) bit_list = self._get_seed_list(header_size) + self.payload dna_sequence = [] for index in range(0, len(bit_list), 2): dna_sequence.append( index_base.get(bit_list[index] * 2 + bit_list[index + 1])) return dna_sequence
def encode(self, bit_segments): dna_sequences = [] for segment_index, bit_segment in enumerate(bit_segments): dna_sequence = [] if len(bit_segment) % 2 != 0: raise ValueError( "The length of inputted binary segment must be divided by 2!" ) for position in range(0, len(bit_segment), 2): dna_sequence.append( index_base.get( self.mapping_rules.index( bit_segment[position:position + 2]))) dna_sequences.append(dna_sequence) if self.need_logs: self.monitor.output(segment_index + 1, len(bit_segments)) return dna_sequences