def test_ComplexDomains(self): foo = objects.Complex(sequence=[ self.d1, self.d2, self.d3, '+', self.d1, '+', self.d1c, self.d3c, self.d1c, self.d2 ], structure=list('..(+(+))..')) self.assertEqual(foo.sequence, [ self.d1, self.d2, self.d3, '+', self.d1, '+', self.d1c, self.d3c, self.d1c, self.d2 ]) self.assertEqual(foo.lol_sequence, [[self.d1, self.d2, self.d3], [self.d1], [self.d1c, self.d3c, self.d1c, self.d2]]) self.assertEqual(foo.nucleotide_sequence, list('YYYYYNNNNNRRRRR+YYYYY+RRRRRYYYYYRRRRRNNNNN')) bar = objects.Complex(sequence=[ self.d1c, self.d3c, self.d1c, self.d2, '+', self.d1, self.d2, self.d3, '+', self.d1 ], structure=list('((..+..)+)')) self.assertEqual(foo, bar) self.assertTrue(foo == bar)
def test_IO_kernel(self): t0 = self.t0 t1 = self.t1 t2 = self.t2 d3 = self.d3 d4 = self.d4 d5 = self.d5 d6 = self.d6 d7 = self.d7 t0c = self.t0c t1c = self.t1c t2c = self.t2c d3c = self.d3c d4c = self.d4c d5c = self.d5c d6c = self.d6c d7c = self.d7c sequence = [ d4, t0, '+', d6, t2, '+', d3, '+', d3, t2, '+', t0, d5, t1, '+', t0, d7, t1, '+', t1c, d7c, t1c, d5c, t2c, '+', d3c, d3c, t2c, d6c, t0c, d4c, t0c ] structure = [ '(', '(', '+', '(', '(', '+', '(', '+', '(', '(', '+', '.', '(', '(', '+', '.', '(', '(', '+', ')', ')', ')', ')', ')', '+', ')', ')', ')', ')', ')', ')', '.' ] foo = objects.Complex(sequence=sequence, structure=structure) fooIO = objects.TestTubeIO( objects.TestTube(complexes={foo.name: (foo, float("inf"), None)})) f = open(os.devnull, "w") fooIO.write_pil_kernel(f)
def test_ComplexInit(self): #NOTE: There is no particular reason for this Error, so it might change! with self.assertRaises(objects.NuskellObjectError): foo = objects.Complex() foo = objects.Complex(sequence=list('RNNNY'), structure=list('(...)')) self.assertIsInstance(foo, objects.Complex) self.assertEqual(foo.sequence, list('RNNNY')) self.assertEqual(foo.structure, list('(...)')) self.assertEqual(foo.lol_sequence, [list('RNNNY')]) self.assertEqual(foo.nucleotide_sequence, list('RNNNY')) self.assertEqual(foo.rotate_once, foo) for r in foo.rotate: self.assertEqual(r.sequence, list('RNNNY')) self.assertEqual(r.structure, list('(...)'))
def _TestTube_from_DOM(self, domstring): solution = objects.TestTube() [doms, cplxs] = np.parse_dom_string(domstring) domains = dict() for n, l in doms: domains[n] = objects.Domain(list('N'*int(l)), name=n) domains[n+'*'] = domains[n].get_ComplementDomain(list('N'*int(l))) for n, se, ss in cplxs: for e, x in enumerate(se) : x = ''.join(x) if x == '+' : continue se[e] = domains[x] cx = objects.Complex(se, ss, name=n) solution.add_complex(cx, (float('inf'), True)) return solution
def test_names(self): objects.reset_names() foo = objects.Complex(sequence=[ self.d1, self.d2, self.d3, '+', self.d1, '+', self.d1c, self.d3c, self.d1c, self.d2 ], structure=list('..(+(+))..')) self.assertEqual(foo.name, 'cplx0') with self.assertRaises(objects.NuskellObjectError): foo.name = 'bar' objects.reset_names() foo.name = 'foo' self.assertEqual(foo.name, 'foo') self.assertSetEqual(objects.Complex.names, set(['foo'])) foo.name = 'bar' self.assertEqual(foo.name, 'bar') self.assertSetEqual(objects.Complex.names, set(['bar'])) objects.reset_names()
def test_IO_dna(self): # NOTE: This function writes to a file, so we need to compare it to # pre-written output-file. Doesn't feel necessary at this point ... t0 = self.t0 t1 = self.t1 t2 = self.t2 d3 = self.d3 d4 = self.d4 d5 = self.d5 d6 = self.d6 d7 = self.d7 t0c = self.t0c t1c = self.t1c t2c = self.t2c d3c = self.d3c d4c = self.d4c d5c = self.d5c d6c = self.d6c d7c = self.d7c sequence = [ d4, t0, '+', d6, t2, '+', d3, '+', d3, t2, '+', t0, d5, t1, '+', t0, d7, t1, '+', t1c, d7c, t1c, d5c, t2c, '+', d3c, d3c, t2c, d6c, t0c, d4c, t0c ] structure = [ '(', '(', '+', '(', '(', '+', '(', '+', '(', '(', '+', '.', '(', '(', '+', '.', '(', '(', '+', ')', ')', ')', ')', ')', '+', ')', ')', ')', ')', ')', ')', '.' ] foo = objects.Complex(sequence=sequence, structure=structure) fooIO = objects.TestTubeIO( objects.TestTube(complexes={foo.name: (foo, float("inf"), None)})) #fooIO.write_dnafile(sys.stdout) f = open(os.devnull, "w") fooIO.write_dnafile(f)
def test_rotations(self): foo = objects.Complex(sequence=[ self.d1, self.d2, self.d3, '+', self.d1, '+', self.d1c, self.d3c, self.d1c, self.d2 ], structure=list('..(+(+))..')) self.assertEqual(foo.rotate_once, foo) self.assertEqual(foo.sequence, [ self.d1, '+', self.d1c, self.d3c, self.d1c, self.d2, '+', self.d1, self.d2, self.d3 ]) self.assertEqual(foo.structure, list('(+)(..+..)')) self.assertEqual(foo.nucleotide_sequence, list('YYYYY+RRRRRYYYYYRRRRRNNNNN+YYYYYNNNNNRRRRR')) for r in foo.rotate: self.assertEqual(r, foo) self.assertEqual(foo.sequence, [ self.d1, '+', self.d1c, self.d3c, self.d1c, self.d2, '+', self.d1, self.d2, self.d3 ]) self.assertEqual(foo.structure, list('(+)(..+..)')) self.assertEqual(foo.nucleotide_sequence, list('YYYYY+RRRRRYYYYYRRRRRNNNNN+YYYYYNNNNNRRRRR'))