def setUp(self,**kwargs): TestBase.setUp(self) dnaseq = testutil.datafile('dnaseq.fasta') tryannot = testutil.tempdatafile('tryannot') db = seqdb.BlastDB(dnaseq) try: db.__doc__ = 'little dna' worldbase.Bio.Test.dna = db annoDB = seqdb.AnnotationDB({1:('seq1',5,10,'fred'), 2:('seq1',-60,-50,'bob'), 3:('seq2',-20,-10,'mary')}, db, sliceAttrDict=dict(id=0, start=1, stop=2, name=3)) annoDB.__doc__ = 'trivial annotation' worldbase.Bio.Test.annoDB = annoDB nlmsa = cnestedlist.NLMSA(tryannot,'w',pairwiseMode=True, bidirectional=False) try: for annID in annoDB: nlmsa.addAnnotation(annoDB[annID]) nlmsa.build(verbose=False) nlmsa.__doc__ = 'trivial map' worldbase.Bio.Test.map = nlmsa worldbaseSchema.Bio.Test.map = metabase.ManyToManyRelation(db, annoDB,bindAttrs=('exons',)) worldbase.commit() worldbase.clear_cache() finally: nlmsa.close() finally: db.close()
def test_run_gunzip(self): 'test uncompress_file gunzip' zipfile = testutil.datafile('test.gz') outfile = testutil.tempdatafile('test3.out') uncompress_file(zipfile, newpath=outfile) h = testutil.get_file_md5(outfile) self.assertEqual(h.hexdigest(), '1db5a21a01ba465fd26c3203d6589b0e')
def test_do_gunzip(self): 'test do_gunzip' zipfile = testutil.datafile('test.gz') outfile = testutil.tempdatafile('test4.out') do_gunzip(zipfile, outfile) h = testutil.get_file_md5(outfile) self.assertEqual(h.hexdigest(), '1db5a21a01ba465fd26c3203d6589b0e')
def test_run_unzip(self): 'test uncompress_file unzip' zipfile = testutil.datafile('test.zip') outfile = testutil.tempdatafile('test.out') uncompress_file(zipfile, newpath=outfile, singleFile=True) h = testutil.get_file_md5(outfile) self.assertEqual(h.hexdigest(), '12ada4c51ccb4c7277c16f1a3c000b90')
def test_do_unzip(self): 'test do_unzip' zipfile = testutil.datafile('test.zip') outfile = testutil.tempdatafile('test2.out') do_unzip(zipfile, outfile, singleFile=True) h = testutil.get_file_md5(outfile) self.assertEqual(h.hexdigest(), '12ada4c51ccb4c7277c16f1a3c000b90')
def test_do_gunzip(self): "test do_gunzip" zipfile = testutil.datafile("test.gz") outfile = testutil.tempdatafile("test4.out") do_gunzip(zipfile, outfile) h = testutil.get_file_md5(outfile) self.assertEqual(h.hexdigest(), "1db5a21a01ba465fd26c3203d6589b0e")
def setUp(self, **kwargs): TestBase.setUp(self) dnaseq = testutil.datafile('dnaseq.fasta') tryannot = testutil.tempdatafile('tryannot') db = seqdb.BlastDB(dnaseq) try: db.__doc__ = 'little dna' self.pygrData.Bio.Test.dna = db annoDB = seqdb.AnnotationDB({1: ('seq1', 5, 10, 'fred'), 2: ('seq1', -60, -50, 'bob'), 3: ('seq2', -20, -10, 'mary')}, db, sliceAttrDict=dict(id=0, start=1, stop=2, name=3)) annoDB.__doc__ = 'trivial annotation' self.pygrData.Bio.Test.annoDB = annoDB nlmsa = cnestedlist.NLMSA(tryannot, 'w', pairwiseMode=True, bidirectional=False) try: for annID in annoDB: nlmsa.addAnnotation(annoDB[annID]) nlmsa.build() nlmsa.__doc__ = 'trivial map' self.pygrData.Bio.Test.map = nlmsa self.schema.Bio.Test.map = metabase.ManyToManyRelation(db, annoDB, bindAttrs=('exons', )) self.metabase.commit() self.metabase.clear_cache() finally: nlmsa.close() finally: db.close()
def setUp(self, **kwargs): TestBase.setUp(self) dnaseq = testutil.datafile("dnaseq.fasta") tryannot = testutil.tempdatafile("tryannot") db = seqdb.BlastDB(dnaseq) try: db.__doc__ = "little dna" self.pygrData.Bio.Test.dna = db annoDB = seqdb.AnnotationDB( {1: ("seq1", 5, 10, "fred"), 2: ("seq1", -60, -50, "bob"), 3: ("seq2", -20, -10, "mary")}, db, sliceAttrDict=dict(id=0, start=1, stop=2, name=3), ) annoDB.__doc__ = "trivial annotation" self.pygrData.Bio.Test.annoDB = annoDB nlmsa = cnestedlist.NLMSA(tryannot, "w", pairwiseMode=True, bidirectional=False) try: for annID in annoDB: nlmsa.addAnnotation(annoDB[annID]) nlmsa.build() nlmsa.__doc__ = "trivial map" self.pygrData.Bio.Test.map = nlmsa self.schema.Bio.Test.map = metabase.ManyToManyRelation(db, annoDB, bindAttrs=("exons",)) self.metabase.commit() self.metabase.clear_cache() finally: nlmsa.close() finally: db.close()
def test_empty2(self): "NLMSA Empty 2" blasthits = testutil.tempdatafile('blasthits2') msa = cnestedlist.NLMSA(blasthits, mode='w', pairwiseMode=True) try: msa.build() raise AssertionError('failed to trap empty alignment!') except nlmsa_utils.EmptyAlignmentError: pass
def test_empty(self): "NLMSA Empty" blasthits = testutil.tempdatafile("blasthits") msa = cnestedlist.NLMSA(blasthits, "memory", pairwiseMode=True) try: msa.build() raise AssertionError("failed to trap empty alignment!") except nlmsa_utils.EmptyAlignmentError: pass
def test_headerfile_write_fail(self): subdb = SequenceFileDB(self.dbfile) try: del subdb.filepath # remove 'filepath' attribute for test db = PrefixUnionDict({'prefix': subdb}) assert len(db) == 2 assert 'prefix.seq1' in db output = testutil.tempdatafile('prefixUnionDict-write-fail.txt') try: db.writeHeaderFile(output) except AttributeError: pass finally: subdb.close() # closes both db and subdb
def all_vs_all_blast_save(): """ Creates the blast files used during testing. Must be called before running the tests """ tempdir = testutil.TempDir("blast-test") testutil.change_pygrdatapath(tempdir.path) sp_hbb1 = testutil.datafile("sp_hbb1") all_vs_all = testutil.tempdatafile("all_vs_all") sp = seqdb.BlastDB(sp_hbb1) msa = cnestedlist.NLMSA(all_vs_all, mode="w", pairwiseMode=True, bidirectional=False) # get strong homologs, save alignment in msa for every sequence reader = islice(sp.iteritems(), None) for id, s in reader: sp.blast(s, msa, expmax=1e-10, verbose=False) # done constructing the alignment, so build the alignment db indexes msa.build(saveSeqDict=True) db = msa.seqDict.dicts.keys()[0] working, result = {}, {} for k in db.values(): edges = msa[k].edges(minAlignSize=12, pIdentityMin=0.5) for t in edges: assert len(t[0]) >= 12 tmpdict = dict( map(lambda x: (x, None), [(str(t[0]), str(t[1]), t[2].pIdentity(trapOverflow=False)) for t in edges]) ) result[repr(k)] = tmpdict.keys() result[repr(k)].sort() # save it into worldbase data = testutil.TestData() data.__doc__ = "sp_allvall" data.result = result worldbase.Bio.Blast = data worldbase.commit()
def test_headerfile_write(self): header = testutil.datafile('prefixUnionDict-2.txt') db = PrefixUnionDict(filename=header) try: assert len(db) == 4 assert 'a.seq1' in db assert 'b.seq1' in db output = testutil.tempdatafile('prefixUnionDict-write.txt') db.writeHeaderFile(output) finally: close_pud_dicts(db) db2 = PrefixUnionDict(filename=output, trypath=[os.path.dirname(header)]) try: assert len(db2) == 4 assert 'a.seq1' in db2 assert 'b.seq1' in db2 finally: close_pud_dicts(db2)
def test_build(self): "NLMSA build" testnlmsa = testutil.tempdatafile('testnlmsa') msa = cnestedlist.NLMSA(testnlmsa, mode='w', pairwiseMode=True, bidirectional=False)