本文整理汇总了Python中qiime.util.get_tmp_filename函数的典型用法代码示例。如果您正苦于以下问题:Python get_tmp_filename函数的具体用法?Python get_tmp_filename怎么用?Python get_tmp_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_tmp_filename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
# Temporary input file
self.tmp_otu_filepath = get_tmp_filename(prefix="R_test_otu_table_", suffix=".txt")
seq_file = open(self.tmp_otu_filepath, "w")
seq_file.write(test_otu_table)
seq_file.close()
self.tmp_map_filepath = get_tmp_filename(prefix="R_test_map_", suffix=".txt")
seq_file = open(self.tmp_map_filepath, "w")
seq_file.write(test_map)
seq_file.close()
self.files_to_remove = [self.tmp_otu_filepath, self.tmp_map_filepath]
# Prep input files in R format
output_dir = mkdtemp()
self.dirs_to_remove = [output_dir]
# get random forests results
mkdir(join(output_dir, "random_forest"))
self.results = run_supervised_learning(
self.tmp_otu_filepath,
self.tmp_map_filepath,
"Individual",
ntree=100,
errortype="oob",
output_dir=output_dir,
)
示例2: test_get_common_OTUs
def test_get_common_OTUs(self):
"""get_common_OTUs works"""
# create the temporary OTU tables
otu_table1 = '\n'.join(['#Full OTU Counts',
'#OTU ID\tsample1\tsample2\tsample3\tConsensus Lineage',
'0\t0\t2\t0\tlineage0',
'1\t1\t0\t0\tlineage1',
'2\t1\t1\t1\tlineage2'])
otu_table2 = '\n'.join(['#Full OTU Counts',
'#OTU ID\tsample1\tsample2\tsample3\tConsensus Lineage',
'0\t0\t2\t0\tlineage0',
'1\t1\t0\t0\tlineage1',
'2\t0\t1\t1\tlineage2'])
otu_table3 = '\n'.join(['#Full OTU Counts',
'#OTU ID\tsample1\tsample2\tsample3\tConsensus Lineage',
'0\t0\t2\t0\tlineage0',
'2\t1\t1\t1\tlineage2'])
category_info = {'sample1':'0.1',
'sample2':'0.2',
'sample3':'0.3'}
OTU_list = ['1', '0', '2']
fp1 = get_tmp_filename()
fp2 = get_tmp_filename()
fp3 = get_tmp_filename()
try:
f1 = open(fp1,'w')
f2 = open(fp2,'w')
f3 = open(fp3,'w')
except IOError, e:
raise e,"Could not create temporary files: %s, %s" %(f1,f2, f3)
示例3: setUp
def setUp(self):
# Temporary input file
self.tmp_otu_filepath = get_tmp_filename(
prefix='R_test_otu_table_',
suffix='.txt'
)
seq_file = open(self.tmp_otu_filepath, 'w')
seq_file.write(test_otu_table)
seq_file.close()
self.tmp_map_filepath = get_tmp_filename(
prefix='R_test_map_',
suffix='.txt'
)
seq_file = open(self.tmp_map_filepath, 'w')
seq_file.write(test_map)
seq_file.close()
self.files_to_remove = \
[self.tmp_otu_filepath, self.tmp_map_filepath]
# Prep input files in R format
output_dir = mkdtemp()
self.dirs_to_remove = [output_dir]
# get random forests results
mkdir(join(output_dir, 'random_forest'))
self.results = run_supervised_learning(
self.tmp_otu_filepath, self.tmp_map_filepath,'Individual',
ntree=100, errortype='oob',
output_dir=output_dir)
示例4: setUp
def setUp(self):
self.files_to_remove = []
self.dirs_to_remove = []
# Create example output directory
tmp_dir = get_qiime_temp_dir()
self.test_out = get_tmp_filename(tmp_dir=tmp_dir,
prefix='qiime_parallel_tests_',
suffix='',
result_constructor=str)
self.dirs_to_remove.append(self.test_out)
create_dir(self.test_out)
# Create example input file
self.inseqs1_fp = get_tmp_filename(tmp_dir=self.test_out,
prefix='qiime_inseqs',
suffix='.fasta')
inseqs1_f = open(self.inseqs1_fp,'w')
inseqs1_f.write(inseqs1)
inseqs1_f.close()
self.files_to_remove.append(self.inseqs1_fp)
# Define number of seconds a test can run for before timing out
# and failing
initiate_timeout(60)
示例5: setUp
def setUp(self):
self._files_to_remove = []
self.fasta_file_path = get_tmp_filename(prefix='fastq_', \
suffix='.fastq')
fastq_file = open(self.fasta_file_path, 'w')
fastq_file.write(fastq_test_string)
fastq_file.close()
#Error testing files
false_fasta_file = '/'
false_qual_file = '/'
self.read_only_output_dir = get_tmp_filename(prefix = 'read_only_', \
suffix = '/')
create_dir(self.read_only_output_dir)
chmod(self.read_only_output_dir, 0577)
self.output_dir = get_tmp_filename(prefix = 'convert_fastaqual_fastq_',\
suffix = '/')
self.output_dir += sep
create_dir(self.output_dir)
self._files_to_remove.append(self.fasta_file_path)
示例6: test_plot_rank_abundance_graphs_dense
def test_plot_rank_abundance_graphs_dense(self):
"""plot_rank_abundance_graphs works with any number of samples (DenseOTUTable)"""
self.otu_table = parse_biom_table_str(otu_table_dense)
self.dir = get_tmp_filename(tmp_dir=self.tmp_dir,
prefix="test_plot_rank_abundance",
suffix="/")
create_dir(self.dir)
self._dirs_to_remove.append(self.dir)
tmp_fname = get_tmp_filename(tmp_dir=self.dir)
#test empty sample name
self.assertRaises(ValueError, plot_rank_abundance_graphs, tmp_fname,'',
self.otu_table)
#test invalid sample name
self.assertRaises(ValueError, plot_rank_abundance_graphs, tmp_fname,
'Invalid_sample_name',
self.otu_table)
#test with two samples
file_type="pdf"
tmp_file = abspath(self.dir+"rank_abundance_cols_0_2."+file_type)
plot_rank_abundance_graphs(tmp_file, 'S3,S5', self.otu_table,
file_type=file_type)
self.assertTrue(exists(tmp_file))
self.files_to_remove.append(tmp_file)
# test with all samples
tmp_file = abspath(self.dir+"rank_abundance_cols_0_1_2."+file_type)
plot_rank_abundance_graphs(tmp_file,'*', self.otu_table,file_type=file_type)
self.files_to_remove.append(tmp_file)
self.assertTrue(exists(tmp_file))
示例7: setUp
def setUp(self):
# Temporary input file
self.tmp_pc_fp = get_tmp_filename(
prefix='R_test_pcoa',
suffix='.txt'
)
seq_file = open(self.tmp_pc_fp, 'w')
seq_file.write(test_pc)
seq_file.close()
self.tmp_map_fp = get_tmp_filename(
prefix='R_test_map_',
suffix='.txt'
)
map_file = open(self.tmp_map_fp, 'w')
map_file.write(test_map)
map_file.close()
self.files_to_remove = \
[self.tmp_pc_fp, self.tmp_map_fp]
# Prep input files in R format
self.output_dir = mkdtemp()
self.dirs_to_remove = [self.output_dir]
示例8: setUp
def setUp(self):
""" """
self.files_to_remove = []
self.dirs_to_remove = []
tmp_dir = get_qiime_temp_dir()
self.test_out = get_tmp_filename(tmp_dir=tmp_dir,
prefix='qiime_parallel_tests_',
suffix='',
result_constructor=str)
self.dirs_to_remove.append(self.test_out)
create_dir(self.test_out)
self.template_fp = get_tmp_filename(tmp_dir=self.test_out,
prefix='qiime_template',
suffix='.fasta')
template_f = open(self.template_fp,'w')
template_f.write(pynast_test1_template_fasta)
template_f.close()
self.files_to_remove.append(self.template_fp)
self.inseqs1_fp = get_tmp_filename(tmp_dir=self.test_out,
prefix='qiime_inseqs',
suffix='.fasta')
inseqs1_f = open(self.inseqs1_fp,'w')
inseqs1_f.write(inseqs1)
inseqs1_f.close()
self.files_to_remove.append(self.inseqs1_fp)
initiate_timeout(60)
示例9: test_call_log_file
def test_call_log_file(self):
"""GenericRepSetPicker.__call__ writes log when expected
"""
tmp_log_filepath = get_tmp_filename(
prefix='GenericRepSetPickerTest.test_call_output_to_file_l_',
suffix='.txt')
tmp_result_filepath = get_tmp_filename(
prefix='GenericRepSetPickerTest.test_call_output_to_file_r_',
suffix='.txt')
app = GenericRepSetPicker(params=self.params)
obs = app(self.tmp_seq_filepath, self.tmp_otu_filepath,
result_path=tmp_result_filepath, log_path=tmp_log_filepath)
log_file = open(tmp_log_filepath)
log_file_str = log_file.read()
log_file.close()
# remove the temp files before running the test, so in
# case it fails the temp file is still cleaned up
remove(tmp_log_filepath)
remove(tmp_result_filepath)
log_file_exp = ["GenericRepSetPicker parameters:",
'Algorithm:first',
"Application:None",
'ChoiceF:first',
'ChoiceFRequiresSeqs:False',
"Result path: %s" % tmp_result_filepath, ]
# compare data in log file to fake expected log file
for i, j in zip(log_file_str.splitlines(), log_file_exp):
if not i.startswith('ChoiceF:'): # can't test, different each time
self.assertEqual(i, j)
示例10: test_test_wrapper_multiple
def test_test_wrapper_multiple(self):
"""test_wrapper_multiple works"""
# create the temporary OTU tables
otu_table1 = '\n'.join(['#Full OTU Counts',
'#OTU ID\tsample1\tsample2\tsample3\tsample4\tConsensus Lineage',
'0\t1\t2\t0\t1\tlineage0',
'1\t1\t0\t0\t1\tlineage1',
'2\t1\t1\t1\t1\tlineage2'])
otu_table2 = '\n'.join(['#Full OTU Counts',
'#OTU ID\tsample1\tsample2\tsample3\tsample4\tConsensus Lineage',
'0\t0\t2\t0\t1\tlineage0',
'1\t1\t0\t0\t1\tlineage1',
'2\t0\t1\t1\t1\tlineage2'])
otu_table3 = '\n'.join(['#Full OTU Counts',
'#OTU ID\tsample1\tsample2\tsample3\tConsensus Lineage',
'0\t0\t2\t0\t1\tlineage0',
'2\t1\t1\t1\t1\tlineage2'])
category_mapping = ['#SampleID\tcat1\tcat2',
'sample1\tA\t0',
'sample2\tA\t8.0',
'sample3\tB\t1.0',
'sample4\tB\t1.0']
OTU_list = ['1', '0']
fp1 = get_tmp_filename()
fp2 = get_tmp_filename()
fp3 = get_tmp_filename()
try:
f1 = open(fp1,'w')
f2 = open(fp2,'w')
f3 = open(fp3,'w')
except IOError, e:
raise e,"Could not create temporary files: %s, %s" %(f1,f2, f3)
示例11: model2_table
def model2_table(otu_sums, samples, seq_depth, tpk):
"""Return OTU table drawn from dirichlet distribution with given params.
Inputs:
otu_sums - array of floats, weights you want to give to each otu in terms
of its probability mass for sampling. basically how large you want the sum
of that otu to be compared to the others.
samples - int, number of samples for each otu.
seq_depth - the sum of each col of the data table, the number of
observations.
tpk - total prior knowledge. controls how spiky the distribution will be.
higher total prior knowledge will allow it to be much spikier which means
less deviation away from otu_sums.
"""
prior_vals = otu_sums
pvs_str = 'c(%s)' % ','.join(map(str,prior_vals))
out_fp = get_tmp_filename()
command_str = COMMAND_STR % (pvs_str, tpk, samples, seq_depth, out_fp)
command_file = get_tmp_filename()
o = open(command_file, 'w')
o.write(command_str)
o.close()
os.system('R --slave < ' + command_file)
o = open(out_fp)
lines = map(str.rstrip ,o.readlines())
o.close()
return array([map(float,line.split(',')) for line in lines])
示例12: null_from_data
def null_from_data(data, tpk, Rseed=None):
"""generates null from dirichlet model of data based on row sums
Inputs:
tpk - int, total prior knowledge to allow the rdirichlet code. higher
tpk will result in the simulated table more closely matching the
initial data.
Rseed - int/None, whether or not to seed R at a given value.
"""
prior_vals = data.sum(1)
pvs_str = 'c(%s)' % ','.join(map(str,prior_vals))
sams_str = data.shape[1] # num cols
seq_depth = data.sum(0).mean()
out_fp = get_tmp_filename()
command_str = COMMAND_STR % (pvs_str, tpk, sams_str, seq_depth, out_fp)
if Rseed!=None:
command_str = command_str[:23]+'set.seed('+str(Rseed)+')\n'+\
command_str[23:]
command_file = get_tmp_filename()
open(command_file, 'w').write(command_str)
cmd_status, cmd_output = getstatusoutput('R --slave < ' + command_file)
if cmd_status==32512:
raise ValueError, 'Most likely you do not have R installed, ' +\
'which is a dependency for QIIME'
elif cmd_status==256:
raise ValueError, 'Most likely you do not have gtools library ' +\
'installed in R installed, which is a dependency for QIIME'
lines = map(str.rstrip , open(out_fp).readlines())
return array([map(float,line.split(',')) for line in lines])
示例13: setUp
def setUp(self):
# create the temporary input files
self.tmp_seq_filepath = get_tmp_filename(prefix="ReferenceRepSetPickerTest_", suffix=".fasta")
seq_file = open(self.tmp_seq_filepath, "w")
seq_file.write(dna_seqs)
seq_file.close()
self.ref_seq_filepath = get_tmp_filename(prefix="ReferenceRepSetPickerTest_", suffix=".fasta")
seq_file = open(self.ref_seq_filepath, "w")
seq_file.write(reference_seqs)
seq_file.close()
self.tmp_otu_filepath = get_tmp_filename(prefix="ReferenceRepSetPickerTest_", suffix=".otu")
otu_file = open(self.tmp_otu_filepath, "w")
otu_file.write(otus_w_ref)
otu_file.close()
self.result_filepath = get_tmp_filename(prefix="ReferenceRepSetPickerTest_", suffix=".fasta")
otu_file = open(self.result_filepath, "w")
otu_file.write(otus_w_ref)
otu_file.close()
self.files_to_remove = [
self.tmp_seq_filepath,
self.tmp_otu_filepath,
self.ref_seq_filepath,
self.result_filepath,
]
self.params = {"Algorithm": "first", "ChoiceF": first_id}
示例14: setUp
def setUp(self):
self.infernal_test1_input_fp = get_tmp_filename(
prefix='InfernalAlignerTests_',suffix='.fasta')
open(self.infernal_test1_input_fp,'w').write(infernal_test1_input_fasta)
self.infernal_test1_template_fp = get_tmp_filename(
prefix='InfernalAlignerTests_',suffix='template.sto')
open(self.infernal_test1_template_fp,'w').\
write(infernal_test1_template_stockholm)
# create temp file names (and touch them so we can reliably
# clean them up)
self.result_fp = get_tmp_filename(
prefix='InfernalAlignerTests_',suffix='.fasta')
open(self.result_fp,'w').close()
self.log_fp = get_tmp_filename(
prefix='InfernalAlignerTests_',suffix='.log')
open(self.log_fp,'w').close()
self._paths_to_clean_up = [
self.infernal_test1_input_fp,
self.result_fp,
self.log_fp,
self.infernal_test1_template_fp,
]
self.infernal_test1_aligner = InfernalAligner({
'template_filepath': self.infernal_test1_template_fp,
})
self.infernal_test1_expected_aln = \
LoadSeqs(data=infernal_test1_expected_alignment,aligned=Alignment,\
moltype=DNA)
示例15: _create_directory_structure
def _create_directory_structure(self, correct=True):
"""Creates a directory structure for check_exist_filepaths function
Returns:
base_dir: the base directory path
mapping_fps: a list with the relative paths from base_dir to
the created mapping files
If correct=False, it adds one mapping file to the mapping_fps list that
do not exists
"""
base_dir = get_tmp_filename(tmp_dir=self.tmp_dir, suffix='')
mkdir(base_dir)
self._dirs_to_clean_up.append(base_dir)
mapping_fps = []
for i in range(5):
mapping_fp = get_tmp_filename(tmp_dir='', suffix='.txt')
mapping_fps.append(mapping_fp)
path_to_create = join(base_dir, mapping_fp)
f = open(path_to_create, 'w')
f.close()
self._paths_to_clean_up.append(path_to_create)
if not correct:
mapping_fps.append(get_tmp_filename(tmp_dir='', suffix='.txt'))
return base_dir, mapping_fps