def test10(): n = random.randint(50, 400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(10, n - 10) j = random.randint(10, n - 10) if i > j: i, j = j, i s = s[:i] + "a" + s[j:] seq[i:j] = 'a' n2 = random.randint(50, 400) s2 = randomSeq(n) seq2 = dnaSeq.dnaSeq(s2) i2 = random.randint(10, n2 - 10) j2 = random.randint(10, n2 - 10) if i2 > j2: i2, j2 = j2, i2 s2 = s2[:i2] + "aaa" + s2[j2:] seq2[i2:j2] = 'aaa' return 0.5 * int(str(seq) == s) + 0.5 * int(str(seq2) == s2)
def test2(): """Testing constructor exception""" try: dnaSeq.dnaSeq(2) except Exception as e: return isinstance(e, ValueError) return False
def test10(): n = random.randint(50,400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(10,n-10) j = random.randint(10,n-10) if i > j: i,j = j,i s = s[:i] + "a" + s[j:] seq[i:j] = 'a' n2 = random.randint(50,400) s2 = randomSeq(n) seq2 = dnaSeq.dnaSeq(s2) i2 = random.randint(10,n2-10) j2 = random.randint(10,n2-10) if i2 > j2: i2,j2 = j2,i2 s2 = s2[:i2] + "aaa" + s2[j2:] seq2[i2:j2] = 'aaa' return 0.5*int(str(seq)==s) + 0.5*int(str(seq2)==s2)
def test11(): n = random.randint(50,400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) n2 = random.randint(50,400) s2 = randomSeq(n2) seq2 = dnaSeq.dnaSeq(s2) return 0.8*int(str(seq+seq2) == s+s2) + 0.2*int(isinstance(seq+seq2, dnaSeq.dnaSeq))
def test11(): n = random.randint(50, 400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) n2 = random.randint(50, 400) s2 = randomSeq(n2) seq2 = dnaSeq.dnaSeq(s2) return 0.8 * int(str(seq + seq2) == s + s2) + 0.2 * int( isinstance(seq + seq2, dnaSeq.dnaSeq))
def test13(): n = random.randint(50, 400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(0, n) j = random.randint(0, n) if i > j: i, j = j, i return dnaSeq.dnaSeq(s[i:j]) in seq
def test13(): n = random.randint(50,400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(0,n) j = random.randint(0,n) if i > j: i,j = j,i return dnaSeq.dnaSeq(s[i:j]) in seq
def test6(): n = random.randint(50,400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(0,n-1) j = -1*random.randint(1,n) return 0.5*int(seq[i] == s[i]) + 0.5*int(seq[j]==seq[j])
def test19(): """Test with differnt column width""" colwidth = random.randint(60, 100) L = [ dnaSeq_sol.dnaSeq(randomSeq(random.randint(300, 600))) for i in range(5) ] for d in L: d.info = ">" + "".join([random.choice("ABCDEFH ") for i in range(30)]) dnaSeq_sol.writeFA(L, "test1.fa", col_width=colwidth) L2 = [] for l in L: d = dnaSeq.dnaSeq(str(l)) d.info = l.info L2.append(d) dnaSeq.writeFA(L2, "test2.fa", col_width=colwidth) ## compare files for l1, l2 in zip(open("test1.fa"), open("test2.fa")): if l1[0] == '>': if l1.lstrip('>').strip() != l2.lstrip('>').strip(): return False else: if l1 != l2: return False return True
def test19(): """Test with differnt column width""" colwidth = random.randint(60,100) L = [dnaSeq_sol.dnaSeq(randomSeq(random.randint(300,600))) for i in range(5)] for d in L: d.info = ">" + "".join([random.choice("ABCDEFH ") for i in range(30)]) dnaSeq_sol.writeFA(L, "test1.fa", col_width = colwidth) L2 = [] for l in L: d = dnaSeq.dnaSeq(str(l)) d.info = l.info L2.append(d) dnaSeq.writeFA(L2, "test2.fa", col_width = colwidth) ## compare files for l1,l2 in zip(open("test1.fa"), open("test2.fa")): if l1[0] == '>': if l1.lstrip('>').strip() != l2.lstrip('>').strip(): return False else: if l1 != l2: return False return True
def test6(): n = random.randint(50, 400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(0, n - 1) j = -1 * random.randint(1, n) return 0.5 * int(seq[i] == s[i]) + 0.5 * int(seq[j] == seq[j])
def test18(): """Test to make sure it creates a file that is readable""" L = [dnaSeq.dnaSeq(randomSeq(random.randint(300,600))) for i in range(5)] for d in L: d.info = ">" + "".join([random.choice("ABCDEFH ") for i in range(30)]) dnaSeq.writeFA(L, "test1.fa") L2 = dnaSeq.readFA("test1.fa") return all([o1.info.lstrip('>').strip()==o2.info.lstrip('>').strip() and str(o1)==str(o2) for o1,o2 in zip(L,L2)])
def test16(): n = random.randint(50, 400) s = randomSeq(n) seq1 = dnaSeq.dnaSeq(s) seq2 = dnaSeq_sol.dnaSeq(s) seq1.reverse_complement() seq2.reverse_complement() return str(seq1) == str(seq2)
def test16(): n = random.randint(50,400) s = randomSeq(n) seq1 = dnaSeq.dnaSeq(s) seq2 = dnaSeq_sol.dnaSeq(s) seq1.reverse_complement() seq2.reverse_complement() return str(seq1)==str(seq2)
def test9(): n = random.randint(50,400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(10,n-10) s = s[:i] + "a" + s[i+1:] seq[i] = "a" return str(seq) == s
def test9(): n = random.randint(50, 400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(10, n - 10) s = s[:i] + "a" + s[i + 1:] seq[i] = "a" return str(seq) == s
def test18(): """Test to make sure it creates a file that is readable""" L = [dnaSeq.dnaSeq(randomSeq(random.randint(300, 600))) for i in range(5)] for d in L: d.info = ">" + "".join([random.choice("ABCDEFH ") for i in range(30)]) dnaSeq.writeFA(L, "test1.fa") L2 = dnaSeq.readFA("test1.fa") return all([ o1.info.lstrip('>').strip() == o2.info.lstrip('>').strip() and str(o1) == str(o2) for o1, o2 in zip(L, L2) ])
def test7(): n = random.randint(50,400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(0,n//2) j = random.randint(n//2+1,n) i2 = -1*random.randint(0,n//2) j2 = -1*random.randint(n//2+1,n) i3 = random.randint(0,n//2) j3 = random.randint(n//2+1,n) return (1/3.0)*int(str(seq[i:j])==s[i:j]) + (1/3.0)*int(str(seq[i2:j2])==s[i2:j2]) + (1/3.0)*int(str(seq[i3:j3:2])==s[i3:j3:2])
def test7(): n = random.randint(50, 400) s = randomSeq(n) seq = dnaSeq.dnaSeq(s) i = random.randint(0, n // 2) j = random.randint(n // 2 + 1, n) i2 = -1 * random.randint(0, n // 2) j2 = -1 * random.randint(n // 2 + 1, n) i3 = random.randint(0, n // 2) j3 = random.randint(n // 2 + 1, n) return (1 / 3.0) * int(str(seq[i:j]) == s[i:j]) + (1 / 3.0) * int( str(seq[i2:j2]) == s[i2:j2]) + (1 / 3.0) * int( str(seq[i3:j3:2]) == s[i3:j3:2])
def test1(): """Test that the constructor run on a legit sequence withot exceptions""" s = dnaSeq.dnaSeq("ACGTacgtNn") return isinstance(s, dnaSeq.dnaSeq)
def test5(): n = random.randint(50, 400) s = randomSeq(n) return str(dnaSeq.dnaSeq(s)) == s
def test4(): n = random.randint(50, 150) s = dnaSeq.dnaSeq(randomSeq(n)) return len(s) == n
def test3(): """Testing constructor exception""" try: dnaSeq.dnaSeq("ABCD") except Exception as e: return type(e) == dnaSeq.DNAError
def setUp(self): self.seq1 = dnaSeq.dnaSeq("".join(['A' for i in range(80)])) self.seq1.info = ">ONE" self.seq2 = dnaSeq.dnaSeq("".join(['C' for i in range(80)])) self.seq2.info = ">TWO" self.seqs = [self.seq1, self.seq2]
def test5(): n = random.randint(50,400) s = randomSeq(n) return str(dnaSeq.dnaSeq(s)) == s
def test8(): # Make sure index slice returns a sequence s = dnaSeq.dnaSeq("ACGT")[0:2] return isinstance(s, dnaSeq.dnaSeq)
def containsTest(self): self.assertIn(dnaSeq.dnaSeq(self.s[self.i:self.j]), self.seq, "Could not find a substring of bases in the generated dnaSeq")
def baseTest(self): dna = dnaSeq.dnaSeq("ACGTacgtNn") self.assertIsInstance(dna, dnaSeq.dnaSeq, "Constructor failed, object is not of type dnaSeq")
def test4(): n = random.randint(50,150) s = dnaSeq.dnaSeq(randomSeq(n)) return len(s) == n
def setUp(self): super(SimpleTwoSeqTestCase, self).setUp() self.n2 = random.randint(30, 400) self.s2 = randomSeq(self.n2) self.seq2 = dnaSeq.dnaSeq(self.s2)
def setUp(self): super(SimpleSeqTestCase, self).setUp() self.seq = dnaSeq.dnaSeq(self.s)