2 from testlib
import testutil
, PygrTestProgram
3 from pygr
import sequence
5 class Sequence_Test(unittest
.TestCase
):
6 'basic sequence class tests'
9 self
.seq
= sequence
.Sequence('atttgactatgctccag', 'foo')
11 def test_length(self
):
13 assert len(self
.seq
) == 17
17 assert str(self
.seq
[5:10]) == 'actat'
19 def test_slicerc(self
):
20 "Sequence slice then reverse complement"
21 assert str(-(self
.seq
[5:10])) == 'atagt'
23 def test_rcslice(self
):
24 "Sequence reverse complement then slice"
25 assert str((-self
.seq
)[5:10]) == 'gcata'
27 def test_truncate(self
):
29 assert str(self
.seq
[-202020202:5]) == 'atttg'
30 assert self
.seq
[-202020202:5] == self
.seq
[0:5]
31 assert self
.seq
[-2020202:] == self
.seq
32 assert str(self
.seq
[-202020202:-5]) == 'atttgactatgc'
33 assert str(self
.seq
[-5:2029]) == 'tccag'
34 assert str(self
.seq
[-5:]) == 'tccag'
37 raise ValueError('failed to trap out of bounds slice')
41 self
.seq
[-10000:-3000]
42 raise ValueError('failed to trap out of bounds slice')
47 raise ValueError('failed to trap out of bounds slice')
51 def test_rctruncate(self
):
52 "Sequence reverse complement truncate"
54 assert str(seq
[-202020202:5]) == 'ctgga'
55 assert seq
[-202020202:5] == seq
[0:5]
56 assert seq
[-2020202:] == seq
57 assert str(seq
[-202020202:-5]) == 'ctggagcatagt'
58 assert str(seq
[-5:2029]) == 'caaat'
59 assert str(seq
[-5:]) == 'caaat'
62 raise ValueError('failed to trap out of bounds slice')
67 raise ValueError('failed to trap out of bounds slice')
72 raise ValueError('failed to trap out of bounds slice')
78 assert str(self
.seq
[5:15] * self
.seq
[8:]) == 'atgctcc'
80 def test_rcjoin(self
):
81 "Sequence reverse complement join"
82 assert str((-(self
.seq
[5:10])) * ((-self
.seq
)[5:10])) == 'ata'
84 def test_seqtype(self
):
86 assert self
.seq
.seqtype() == sequence
.DNA_SEQTYPE
87 assert sequence
.Sequence('auuugacuaugcuccag', 'foo').seqtype() == \
89 assert sequence
.Sequence('kqwestvvarphal', 'foo').seqtype() == \
90 sequence
.PROTEIN_SEQTYPE
94 #from pygrdata_test import PygrSwissprotBase
95 class Blast_Test(PygrSwissprotBase):
96 'test basic blast functionality'
97 @skip_errors(OSError,KeyError)
99 PygrSwissprotBase.setup(self)
101 self.sp = pygr.Data.Bio.Seq.Swissprot.sp42()
103 blastIndexPath = os.path.join(os.path.dirname(self.sp.filepath),
105 self.sp.formatdb(blastIndexPath)
107 hbb = self.sp['HBB1_TORMA']
108 hits = self.sp.blast(hbb)
109 edges = hits[hbb].edges(maxgap=1,maxinsert=1,
110 minAlignSize=14,pIdentityMin=0.5)
112 assert len(t[0])>=14, 'result shorter than minAlignSize!'
113 result = [(t[0],t[1],t[2].pIdentity()) for t in edges]
114 store = PygrDataTextFile(os.path.join('results', 'seqdb1.pickle'))
115 correct = store['hbb blast 1']
116 assert approximate_cmp(result,correct,.0001) == 0, 'blast results should match'
117 result = [(t[0],t[1],t[2].pIdentity()) for t in hits[hbb].generateSeqEnds()]
118 correct = store['hbb blast 2']
119 assert approximate_cmp(result,correct,.0001) == 0, 'blast results should match'
120 trypsin = self.sp['PRCA_ANASP']
123 raise ValueError('failed to catch bad alignment query')
126 class Blast_reindex_untest(Blast_Test):
127 'test building blast indexes under a different name'
128 @skip_errors(OSError,KeyError)
130 PygrSwissprotBase.setup(self)
132 self.sp = pygr.Data.Bio.Seq.Swissprot.sp42()
134 blastIndexPath = os.path.join(os.path.dirname(self.sp.filepath),'wikiwacky')
136 #self.sp.formatdb(blastIndexPath) # FORCE IT TO STORE INDEX WITH DIFFERENT NAME
137 #print 'blastIndexPath is',self.sp.blastIndexPath
141 if __name__
== '__main__':
142 PygrTestProgram(verbosity
=2)