def _fetch_homebrew(container_dir, distro_config): """Fetch homebrew and untar it in the container directory.""" try: os.stat(os.path.join(container_dir, "bin", "brew")) return container_for_directory(container_dir, distro_config) except OSError: with directory.Navigation(tempdir.TempDir().name): with TemporarilyDownloadedFile(_HOMEBREW_URL, filename="brew") as archive_file: with directory.Navigation(tempdir.TempDir().name) as extract: _extract_archive(archive_file, extract) first = os.path.join(extract, os.listdir(extract)[0]) files = [os.path.join(first, p) for p in os.listdir(first)] for filename in files: try: filename_base = os.path.basename(filename) shutil.move( filename, os.path.join(container_dir, filename_base)) except IOError: # suppress(pointless-except) # Ignore stuff that can't be moved for whatever # reason. These are all files that generally # don't matter. pass return OSXContainer(container_dir, distro_config["pkgsys"])
def test_input_unrooted_tree(self): otu61 = os.path.join(path_to_data, '61_otus.gpkg', '61_otus.refpkg') with tempfile.NamedTemporaryFile(suffix='.fa') as bad_alignment: with tempdir.TempDir() as tmp: Create(prerequisites).main( taxtastic_taxonomy=os.path.join(otu61, '61_otus_taxonomy.csv'), taxtastic_seqinfo=os.path.join(otu61, '61_otus_seqinfo.csv'), # created with newick_utils: # nw_prune test/data/61_otus.gpkg/61_otus.refpkg/61_otus.tre 4459468 >test/data/61_otus.without_4459468.tre unrooted_tree=os.path.join(path_to_data, 'create', '61_otus.without_4459468.tre'), sequences=os.path.join(path_to_data, 'create', '61_otus.without_4459468.fasta'), alignment=os.path.join( path_to_data, 'create', '61_otus.without_4459468.aln.fasta'), prefix=tmp, force=True) gpkg = GraftMPackage.acquire(tmp) tree = Tree.get( schema='newick', data=open(gpkg.reference_package_tree_path()).readline()) self.assertEqual(21, len(tree.leaf_nodes()))
def test_import_math(): # math is an extension module, so this should fail with tempdir.TempDir() as t: filename = os.path.join(t, "paper.ap") paper = ActivePaper(filename, "w") paper.import_module('math') paper.close()
def setUp(self): self.universe = mda.Universe(PSF, [DCD, CRD, DCD, CRD, DCD, CRD, CRD]) self.trajectory = self.universe.trajectory self.prec = 3 # dummy output DCD file self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/chain-reader.dcd'
def setUp(self): self.universe = mda.Universe(TRZ_psf, TRZ) self.ag = self.universe.select_atoms('name N') self.prec = 3 self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/partial-write-test.pdb' self.Writer = mda.Writer(self.outfile, n_atoms=len(self.ag))
def setUp(self): self.universe = mda.Universe(XYZ_psf, XYZ_bz2) self.prec = 3 # 4 decimals in xyz file ext = ".xyz" self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/xyz-writer' + ext self.Writer = mda.coordinates.XYZ.XYZWriter
def test_simple_paper(): with tempdir.TempDir() as t: filename1 = os.path.join(t, "simple1.ap") filename2 = os.path.join(t, "simple2.ap") make_simple_paper(filename1) all_paths = [ 'README', 'code', 'code/calc_sine', 'code/initialize', 'data', 'data/frequency', 'data/sine', 'data/time', 'documentation', 'external-dependencies', 'history' ] all_items = [ '/code/calc_sine', '/code/initialize', '/data/frequency', '/data/sine', '/data/time' ] all_deps = { '/data/sine': ["/code/calc_sine", "/data/frequency", "/data/time"], '/data/time': [], '/data/frequency': [], '/code/calc_sine': [], '/code/initialize': [] } sine_deps = ["/code/calc_sine", "/data/frequency", "/data/time"] hierarchy = [[ '/code/calc_sine', '/code/initialize', '/data/frequency', '/data/time' ], ['/data/sine']] check_hdf5_file(filename1, all_paths, sine_deps) check_paper(filename1, all_items, all_deps, hierarchy) with ActivePaper(filename1, "r") as paper: paper.rebuild(filename2) check_hdf5_file(filename2, all_paths, sine_deps) check_paper(filename2, all_items, all_deps, hierarchy)
def test_cycle(self): otu_table = \ [['gene','sample','sequence','num_hits','coverage','taxonomy'], ['ribosomal_protein_L11_rplK_gpkg','minimal','GGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC','7','14.4', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales'], ['ribosomal_protein_S2_rpsB_gpkg','minimal','CGTCGTTGGAACCCAAAAATGAAAAAATATATCTTCACTGAGAGAAATGGTATTTATATC','6','12.2', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli'], ['ribosomal_protein_S17_gpkg','minimal','GCTAAATTAGGAGACATTGTTAAAATTCAAGAAACTCGTCCTTTATCAGCAACAAAACGT','9','18.8', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales; f__Staphylococcaceae; g__Staphylococcus']] otu_table = "\n".join(["\t".join(x) for x in otu_table]) with tempdir.TempDir() as tmp: db_path = os.path.join(tmp, 'my.sdb') collection = OtuTableCollection() collection.add_otu_table(StringIO.StringIO(otu_table)) SequenceDatabase.create_from_otu_table(db_path, collection) db2 = SequenceDatabase.acquire(db_path) s1 = db2.extract_sequence(1) self.assertEqual('ribosomal_protein_L11_rplK_gpkg', s1.marker) self.assertEqual('minimal',s1.sample_name) self.assertEqual('GGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC',s1.sequence) self.assertEqual(7, s1.count) self.assertEqual('Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales', s1.taxonomy) s3 = db2.extract_sequence(3) self.assertEqual('GCTAAATTAGGAGACATTGTTAAAATTCAAGAAACTCGTCCTTTATCAGCAACAAAACGT',s3.sequence) self.assertEqual('Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales; f__Staphylococcaceae; g__Staphylococcus', s3.taxonomy) self.assertEqual(os.path.join(db_path,"sequences.fasta"), db2.sequences_fasta_file)
def test_groups(): with tempdir.TempDir() as t: filename = os.path.join(t, "paper.ap") paper = ActivePaper(filename, 'w') group = paper.data.create_group('group') subgroup = group.create_group('subgroup') group['data1'] = np.arange(10) group['data2'] = 42 assert sorted([g.name for g in paper.iter_groups()]) \ == ['/data/group', '/data/group/subgroup'] assert sorted(list(node for node in group)) \ == ['data1', 'data2', 'subgroup'] assert group['data1'][...].shape == (10,) assert group['data2'][...] == 42 assert paper.data.parent is paper.data assert group.parent is paper.data assert group['data1'].parent is group assert group['data2'].parent is group script = paper.create_calclet("script", """ from activepapers.contents import data assert data.parent is data assert data._codelet is not None assert data._codelet.path == '/code/script' group = data['group'] assert group.parent is data assert group._codelet is not None assert group._codelet.path == '/code/script' """) script.run() paper.close()
def setup(self): self.tmpdir = td.TempDir() self.old_path = os.getcwd() self.resources = os.path.join(self.old_path, 'mdpow', 'tests', 'testing_resources') m = pybol.Manifest(os.path.join(self.resources, 'manifest.yml')) m.assemble('base', self.tmpdir.name)
def test_dummy_datasets(): with tempdir.TempDir() as t: filename = os.path.join(t, "paper.ap") paper = ActivePaper(filename, 'w') paper.data.create_dataset("frequency", data = 0.2) paper.data.create_dataset("time", data=0.1*np.arange(100)) calc_angular = paper.create_calclet("calc_angular", """ from activepapers.contents import data, snapshot import numpy as np frequency = data['frequency'][...] time = data['time'][...] angular = data.create_group('angular') angular.attrs['time'] = data['time'].ref angular.create_dataset("time", data=data['time'].ref) angular.create_dataset("sine", data=np.sin(2.*np.pi*frequency*time)) """) calc_angular.run() paper.replace_by_dummy('/data/angular/sine') dummy = paper.data_group['angular/sine'] assert dummy.attrs.get('ACTIVE_PAPER_GENERATING_CODELET') \ == '/code/calc_angular' assert dummy.attrs.get('ACTIVE_PAPER_DUMMY_DATASET', False) passed = True try: paper.replace_by_dummy('/data/time') except AssertionError: passed = False assert not passed paper.close()
def test_modified_scripts(): with tempdir.TempDir() as t: filename = os.path.join(t, "paper.ap") paper = ActivePaper(filename, 'w') script = paper.create_calclet("script", """ from activepapers.contents import data data.create_dataset('foo', data=42) group = data.create_group('group1') group.mark_as_data_item() group['value'] = 1 group = data.create_group('group2') group['value'] = 2 """) script.run() items = sorted([item.name for item in paper.iter_items()]) assert items == ['/code/script', '/data/foo', '/data/group1', '/data/group2/value'] assert (paper.data['foo'][...] == 42) assert (paper.data['group1/value'][...] == 1) assert (paper.data['group2/value'][...] == 2) script = paper.create_calclet("script", """ from activepapers.contents import data data.create_dataset('foo', data=1) """) script.run() items = sorted([item.name for item in paper.iter_items()]) assert items == ['/code/script', '/data/foo'] assert (paper.data['foo'][...] == 1) paper.close()
def test_biom_hello_world(self): insert_otu_table = [ self.headers, [ '4.12.ribosomal_protein_L11_rplK', 'insert', 'CCTGCAGGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTG', '1', '2.44', 'Root; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales' ], [ '4.12.ribosomal_protein_L11_rplK', 'insert', 'CCTGCAGGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTtttCAAGCAGGTGTG', '2', '2.94', 'Root; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales' ] ] with tempdir.TempDir() as tmp: with tempfile.NamedTemporaryFile(suffix='.otu_table.csv', mode='w') as n: n.write("\n".join(["\t".join(x) for x in insert_otu_table] + [''])) n.flush() extern.run( "%s summarise --biom_prefix '%s' --input_otu_tables '%s'" % (path_to_script, os.path.join(tmp, "mybiom"), n.name)) self.assertEqual( ['mybiom.4.12.ribosomal_protein_L11_rplK.biom'], os.listdir(tmp)) self.assertEqual( '# Constructed from biom file\n#OTU ID\tinsert\ttaxonomy\nRoot; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales; CCTGCAGGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTG\t1.0\tRoot; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales\nRoot; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales; CCTGCAGGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTtttCAAGCAGGTGTG\t2.0\tRoot; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales', extern.run( "biom convert -i '%s' -o /dev/stdout --to-tsv --header-key taxonomy" % os.path.join( tmp, 'mybiom.4.12.ribosomal_protein_L11_rplK.biom')))
def test_clustering(self): otu_table = [ self.headers, [ 'ribosomal_protein_L11_rplK_gpkg', 'minimal', 'GGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC', '7', '4.95', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales' ], [ 'ribosomal_protein_L11_rplK_gpkg', 'minimal', 'GGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATA', '6', '4.95', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli' ], #last base only is different to first sequence [ 'ribosomal_protein_S17_gpkg', 'minimal', 'GCTAAATTAGGAGACATTGTTAAAATTCAAGAAACTCGTCCTTTATCAGCAACAAAACGT', '9', '4.95', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales; f__Staphylococcaceae; g__Staphylococcus' ] ] otu_table = "\n".join(["\t".join(x) for x in otu_table]) with tempfile.NamedTemporaryFile() as f: f.write(otu_table) f.flush() with tempdir.TempDir() as d: cmd = "{} makedb --db_path {}/db --otu_table {} --clustering_divergence 3".format( path_to_script, d, f.name) subprocess.check_call(cmd, shell=True) cmd = "%s query --query_sequence %s --db %s/db" % ( path_to_script, 'AGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC', # first sequence with an extra A at the start d) expected = [ [ 'query_name', 'query_sequence', 'divergence', 'num_hits', 'sample', 'marker', 'hit_sequence', 'taxonomy' ], [ 'unnamed_sequence', 'AGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC', '1', '7', 'minimal', 'ribosomal_protein_L11_rplK_gpkg', 'GGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales' ], [ 'unnamed_sequence', 'AGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATC', '2', '6', 'minimal', 'ribosomal_protein_L11_rplK_gpkg', 'GGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTGAACATA', 'Root; k__Bacteria; p__Firmicutes; c__Bacilli' ] ] self.assertEqualOtuTable( expected, subprocess.check_output(cmd, shell=True))
def setUp(self): self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/ncdf-write-vels-force.ncdf' self.prec = 3 self.top = XYZ_mini self.n_atoms = 3 self.ts1 = mda.coordinates.TRJ.Timestep(self.n_atoms, velocities=True, forces=True) self.ts1._pos[:] = np.arange(self.n_atoms * 3).reshape(self.n_atoms, 3) self.ts1._velocities[:] = np.arange(self.n_atoms * 3).reshape( self.n_atoms, 3) + 100 self.ts1._forces[:] = np.arange(self.n_atoms * 3).reshape( self.n_atoms, 3) + 200 self.ts2 = mda.coordinates.TRJ.Timestep(self.n_atoms, velocities=True, forces=True) self.ts2._pos[:] = np.arange(self.n_atoms * 3).reshape( self.n_atoms, 3) + 300 self.ts2._velocities[:] = np.arange(self.n_atoms * 3).reshape( self.n_atoms, 3) + 400 self.ts2._forces[:] = np.arange(self.n_atoms * 3).reshape( self.n_atoms, 3) + 500
def init_gpg(keys): t = tempdir.TempDir() gpg = gnupg.GPG(homedir=t.name) gpg.temp_dir = t for key in keys: gpg.import_keys(key) return gpg
def _fetch_choco(container_dir, distro_config): """Fetch chocolatey and install it in the container directory.""" try: os.stat(os.path.join(container_dir, "bin", "choco.exe")) return container_for_directory(container_dir, distro_config) except OSError: with tempdir.TempDir() as download_dir: with directory.Navigation(download_dir): _execute_no_output( ["setx", "ChocolateyInstall", container_dir]) # Also set the variable in the local environment # too, so that it gets propagated down to our # children os.environ["ChocolateyInstall"] = container_dir try: os.makedirs(container_dir) except OSError as error: if error.errno != errno.EEXIST: raise error _execute_no_output([ "powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", _CHOCO_INSTALL_CMD ]) # Reset variable back to original state to prevent # polluting the user's registry _execute_no_output(["setx", "ChocolateyInstall", ""]) return WindowsContainer(container_dir, distro_config["pkgsys"])
def setUp(self): self.universe = mda.Universe(GRO) self.prec = 2 # 3 decimals in file in nm but MDAnalysis is in A ext = ".gro" self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/gro-writer' + ext self.outfile2 = self.tmpdir.name + '/gro-writer2' + ext
def make(self): import tarfile, bz2, os.path, sys, os import tempdir #Temporary Directory td = tempdir.TempDir() tempPath = td.name os.chdir(tempPath) #Parse files self.parseDesc() self.parseFiles() if (self.parseINSTALL()): self.createINSTALL() #Create PKGINFO inside the temporary directory self.createPKGINFO() name = self.desc["pkgname"] + "-" + self.desc["pkgver"] + ".pkg.tar.bz2" completePath = os.path.join(self.pkgDest, name) pkg = tarfile.open(completePath, mode=self.comp, dereference=False) for file in self.files: try: pkg.add(file) except: string = "Was not able to add the " + file + " of package: " + self.desc[ 'pkgname'] + "\n Please run repac again as root \n" sys.stderr.write(string) #sys.exit() pkg.close() td.dissolve()
def test_alignment_rereplication(self): gpkg = os.path.join(path_to_data,'61_otus.gpkg') test_sequences=""">FCC0WM1ACXX:2:2208:12709:74426#GTCCAGAA_2/1 ACACTGCCCAGACACCTACGGGTGGCTGCAGTCGAGGATCTTCGGCAATGGGCGAAAGCCTGACCGAGCGACGCCGCGTGTGGGATGAAGGCCCTCGGGT >FCC0WM1ACXX:2:2208:12709:74426#GTCCAGAA/1 ACACTGCCCAGACACCTACGGGTGGCTGCAGTCGAGGATCTTCGGCAATGGGCGAAAGCCTGACCGAGCGACGCCGCGTGTGGGATGAAGGCCCTCGGGT >FCC0WM1ACXX:2:2208:12709:74426#GTCCAGAA/2 CGGGGTATCTAATCCCGTTCGCTCCCCTAGCTTTCGTGCCTCAGCGTCAGAAAAGACCCAGTGAGCCGCTTTCGCCCCCGGTGTTCCTTAGGATATCAAC """ expected_rereplicated_alignment=""">FCC0WM1ACXX:2:2208:12709:74426#GTCCAGAA/2 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------TTGATATCCTAAGGAACACCGGGGGCGAAAGCGGCTCACTGGGTCTTCTGACGCTGAGGCACGAAAGCTAGGGGAGCGAACGGGATTAGATACCCC---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >FCC0WM1ACXX:2:2208:12709:74426#GTCCAGAA_2/1 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ACACTGCCCAGACACCTACGGGTGGCTGCAGTCGAGGATCTTCGGCAATGGGCGAAAGCCTGACCGAGCGACGCCGCGTGTGGGATGAAGGCCCTCGGG------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- >FCC0WM1ACXX:2:2208:12709:74426#GTCCAGAA/1 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ACACTGCCCAGACACCTACGGGTGGCTGCAGTCGAGGATCTTCGGCAATGGGCGAAAGCCTGACCGAGCGACGCCGCGTGTGGGATGAAGGCCCTCGGG-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------""".split() with tempfile.NamedTemporaryFile(suffix=".fa") as tf: tf.write(test_sequences) tf.flush() with tempdir.TempDir() as tmp: cmd = "%s graft --forward %s --graftm_package %s --output_directory %s --force" % (path_to_script, tf.name, gpkg, tmp) extern.run(cmd) filename=os.path.splitext(os.path.basename(tf.name))[0] observed_rereplicated_alignment = [x.strip() for x in open(os.path.join(tmp, filename, "%s_hits.aln.fa" % filename))] self.assertEquals(expected_rereplicated_alignment, observed_rereplicated_alignment)
def test_search_hmms_input(self): with tempdir.TempDir() as tmp: gpkg = tmp + ".gpkg" Create(prerequisites).main( sequences=os.path.join(path_to_data, 'create', 'homologs.trimmed.unaligned.faa'), taxonomy=os.path.join( path_to_data, 'create', 'homologs.tax2tree.rerooted.decorated.tree-consensus-strings' ), hmm=os.path.join( path_to_data, 'create', 'first5.hmm' ), # an HMM created from just the first 5 sequences search_hmm_files=[ os.path.join(path_to_data, 'create', 'homologs.hmm') ], prefix=gpkg, threads=5) self.assertEqual( 'NAME first10\n', open(GraftMPackageVersion2.acquire( gpkg).alignment_hmm_path()).readlines()[1]) self.assertEqual( 1, len(GraftMPackageVersion2.acquire(gpkg).search_hmm_paths())) self.assertEqual( 'NAME homologs.trimmed.aligned\n', open( GraftMPackageVersion2.acquire(gpkg).search_hmm_paths() [0]).readlines()[1])
def test_returns_data_as_is(self): with tempdir.TempDir() as d: tempfile = os.path.join(d.name, 'tempfile') p = self.program(tempfile) d = Data('id', 'payload') self.assertEqual(d, p.run(d))
def test_hello_world(self): with tempdir.TempDir() as tmp: with tempdir.TempDir() as tmp2: cmd1 = "%s create --verbosity 2 --sequences %s --alignment %s --taxonomy %s --rerooted_tree %s --output %s" \ %(path_to_script, os.path.join(path_to_data,'create','homologs.trimmed.unaligned.faa'), os.path.join(path_to_data,'create','homologs.trimmed.aligned.faa'), os.path.join(path_to_data,'create','homologs.tax2tree.rerooted.decorated.tree-consensus-strings'), os.path.join(path_to_data,'create','homologstre.tree'), tmp+".gpkg") extern.run(cmd1) cmd2 = "%s graft --verbosity 2 --graftm_package %s --forward %s --output_directory %s" \ % (path_to_script, "%s.gpkg" % tmp, os.path.join(path_to_data,'create','test.faa'), tmp2+"_") extern.run(cmd2)
def setUp(self): self.universe = mda.Universe(self.topology, self.filename) self.prec = 5 ext = ".ncdf" self.tmpdir = tempdir.TempDir() self.outfile = os.path.join(self.tmpdir.name, 'ncdf-writer-1' + ext) self.outtop = os.path.join(self.tmpdir.name, 'ncdf-writer-top.pdb') self.Writer = mda.coordinates.TRJ.NCDFWriter
def test_published_paper(): with tempdir.TempDir() as t: library.library = [t] ap = ActivePaperExploration("doi:10.6084/m9.figshare.808595") import time_series ts = np.arange(10) assert time_series.integral(ts, 1)[-1] == 40.5 ap.close()
def test_krona(self): archive = '{"fields": ["gene", "sample", "sequence", "num_hits", "coverage", "taxonomy", "read_names", "nucleotides_aligned", "taxonomy_by_known?"], "singlem_package_sha256s": ["2b2afe0114de20451fccfe74360756376dc83d001d890e84e322ab0833eca6ba", "7f406a73d8bb176994055cb966ff350e208986d12c8215722686c17c26e548c7", "735b44ae547c133163cb7d40f417292c35423864d00c95e7f1b32091b27d46c5", "8fc6dcce2766cc01defb3b5c689a1ed8ce9d59b725c67e58c2044dafaae908b3", "172df49937742b8411d41d217500d862567374401eaf393b25107b22ac630202", "4cb1bf226bf28d8198ed5c29e8a76df411d96a6c3ce1256af16887b9a184b0a6", "d473d3ae677e6e46202461ccdedb2aef23c0a10a3412422586b37e397ca37294", "431a2860bb890cd1c7193c565cbf0cc227850cba36fb17fe94df686e74ee9b11", "faa663527bb9aea63cef03859311f2e7f55fe98590a5ec85c5ba85815a6fd13e", "a0daf111380e6e499ad9c10c3ac413aa9016c7503dd459825100168524bff0d1", "aba631d4735aeb9d2dfbbbfee1c0739bf9e99ad6532a3be04ff627f3e6efdae2", "bba10c1feb0c26bdf46aa3d1dcb992744a699cde5cf02bb2728f8397378b342f", "4d91dd794b25fd256508f0814f6a2d31e20dc85e0aa9ea405031398565276768", "9b23c524a6210af0706eea7252c2d378888029f141b9305c3e88cbac3fd83f88", "50a209417b455a48bc67702d6a3809a172c57f00785d8c705a3322e6e2a71f72"], "version": 1, "alignment_hmm_sha256s": ["dd9b7e283598360b89ec91ff3f5c509361a6108a2eadc44bfb29646b1510f6b7", "b1bb943c3449a78f937db960bfdf6b2bed641388d33fce3cb2d5f69e79946ea6", "de92c90f2c83e380ae3953972fb63fcb8ce868dab87a305f9f1811b84ffb3d39", "453ed4a62608a4aec36117a2dd1a276709ff6b130ecb8d7b1612926bfab25527", "20cc450cf4157ecf1772e0325d4d8ed400b597d888a5cb5044ca69098f935656", "4b0bf5b3d7fd2ca16e54eed59d3a07eab388f70f7078ac096bf415f1c04731d9", "7cbba7ba0ed58d21c7519ba3fcef0abe43378e5c38c985b0d5e0e5219f141d92", "4a3bbe5ac594ef3c7c820e74544828e19eca68bf860d64f928729eb4530fce4e", "06a4bed0a765971b891ca4a4bf5680aeef4a4a249ce0c028798c0e912f0ccfb4", "2678fe218ca860a2d88bdbf76935d8c78a00ab6603a041a432505d754ef08250", "b54ff98aa03ab31af39c737a569b23ee4ed9296c8ea088562bfb3db87c38fe4a", "4ae31f14067bf183f38dca20f2aefb580e5ff25848881dd988908b70b67761bb", "d7bb3d544133f38110a329712b3ace7e7d7c989dafa3815d2d5a292b4c575f50", "7639bb919ef54f7baff3ed3a8c924efca97ed375cf4120a6e05d98fd6ef52cbb", "6923b889888ea34fabf463b2c8ad5fe23c94828f1a2631a07601f246f5e87150"], "otus": [["4.11.ribosomal_protein_L10", "minimal", "TTACGTTCACAATTACGTGAAGCTGGTGTTGAGTATAAAGTATACAAAAACACTATGGTA", 2, 4.878048780487805, "Root; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales; f__Staphylococcaceae; g__Staphylococcus", ["HWI-ST1243:156:D1K83ACXX:7:1106:18671:79482", "HWI-ST1243:156:D1K83ACXX:7:1105:19152:28331"], [60, 60], false], ["4.12.ribosomal_protein_L11_rplK", "minimal", "CCTGCAGGTAAAGCGAATCCAGCACCACCAGTTGGTCCAGCATTAGGTCAAGCAGGTGTG", 4, 9.75609756097561, "Root; d__Bacteria; p__Firmicutes; c__Bacilli; o__Bacillales", ["HWI-ST1243:156:D1K83ACXX:7:1109:18214:9910", "HWI-ST1243:156:D1K83ACXX:7:1103:21187:63124", "HWI-ST1243:156:D1K83ACXX:7:1108:10813:6928", "HWI-ST1243:156:D1K83ACXX:7:1105:12385:81842"], [60, 60, 60, 60], false]]}' table_collection = OtuTableCollection() table_collection.add_archive_otu_table(StringIO(archive)) with tempdir.TempDir() as tmp: Summariser.summarise(krona_output=os.path.join(tmp, 'KronaOK.html'), table_collection=table_collection) self.assertTrue(os.path.exists(os.path.join(tmp,'KronaOK.html')))
def setUp(self): self.temp = tempdir.TempDir() self.store_dir = os.path.join(os.path.abspath(self.temp.name), 'test_data') self.app = main({}, **settings) self.storage_location = 'https://storage.onroerenderfgoed.be/' collections_include(self.app, self.store_dir) self.testapp = TestApp(self.app)
def test_module_paper(): with tempdir.TempDir() as t: filename1 = os.path.join(t, "paper1.ap") filename2 = os.path.join(t, "paper2.ap") make_paper_with_module(filename1, 42) check_paper_with_module(filename1, 42) make_paper_with_module(filename2, 0) check_paper_with_module(filename2, 0)
def test_min_aligned_percent(self): # test it doesn't raise with a lower check limit with tempdir.TempDir() as tmp: Create(prerequisites).main( alignment=os.path.join(path_to_data, 'create', 'homologs.trimmed.aligned.faa'), taxonomy=os.path.join( path_to_data, 'create', 'homologs.tax2tree.rerooted.decorated.tree-consensus-strings' ), sequences=os.path.join(path_to_data, 'create', 'homologs.trimmed.unaligned.faa'), rerooted_tree=os.path.join(path_to_data, 'create', 'decorated.tree'), min_aligned_percent=0.5, prefix=tmp + ".gpkg", threads=5) original_alignment_length = len( open( os.path.join( tmp + '.gpkg', os.path.basename(tmp) + '.gpkg.refpkg', 'homologs_deduplicated_aligned.fasta')).readlines()) with tempdir.TempDir() as tmp: Create(prerequisites).main( alignment=os.path.join(path_to_data, 'create', 'homologs.trimmed.aligned.faa'), taxonomy=os.path.join( path_to_data, 'create', 'homologs.tax2tree.rerooted.decorated.tree-consensus-strings' ), sequences=os.path.join(path_to_data, 'create', 'homologs.trimmed.unaligned.faa'), #rerooted_tree=os.path.join(path_to_data,'create','decorated.tree'), min_aligned_percent=0.9, prefix=tmp + ".gpkg", threads=5) self.assertEqual( original_alignment_length - 4, # 2 sequences get removed len( open( os.path.join(tmp + '.gpkg', os.path.basename(tmp) + '.gpkg.refpkg', 'homologs_deduplicated_aligned.fasta')). readlines()))
def setUp(self): self.universe = mda.Universe(PRMncdf, NCDF) self.prec = 6 ext = ".ncdf" self.tmpdir = tempdir.TempDir() self.outfile = self.tmpdir.name + '/ncdf-writer-1' + ext self.outtop = self.tmpdir.name + '/ncdf-writer-top.pdb' self.Writer = mda.coordinates.TRJ.NCDFWriter