本文整理汇总了Python中skbio.util.create_dir函数的典型用法代码示例。如果您正苦于以下问题:Python create_dir函数的具体用法?Python create_dir怎么用?Python create_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
if opts.attempt_read_reorientation:
if not opts.mapping_fp:
option_parser.error("To use --attempt_read_reorientation, one must "
"supply a mapping file that contains both LinkerPrimerSequence "
"and ReversePrimer columns.")
if opts.input_type == "barcode_paired_end":
if not opts.fastq2:
option_parser.error("To use input_type of barcode_paired_end, "
"a second fastq file must be specified with --fastq2")
if not opts.fastq2:
disable_header_match = True
else:
disable_header_match = opts.disable_header_match
fastq1 = qiime_open(opts.fastq1)
if opts.fastq2:
fastq2 = qiime_open(opts.fastq2)
else:
fastq2 = None
create_dir(opts.output_dir)
if opts.mapping_fp:
map_fp = qiime_open(opts.mapping_fp)
else:
map_fp = None
extract_barcodes(fastq1, fastq2, opts.output_dir, opts.input_type,
opts.bc1_len, opts.bc2_len, opts.rev_comp_bc1, opts.rev_comp_bc2,
opts.char_delineator, opts.switch_bc_order, map_fp,
opts.attempt_read_reorientation, disable_header_match)
示例2: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
input_dir = opts.input_dir
output_dir = opts.output_dir
create_dir(output_dir)
lanes = opts.lanes.split(',')
bases = opts.bases
read = opts.read
ignore_pass_filter = opts.ignore_pass_filter
for lane in lanes:
read1_fps = sorted(glob('%s/s_%s_%d_*qseq.txt' % (input_dir,
lane.replace(
',',
''),
read)))
# sort so results will be consistent across different runs (important
# so amplicon and barcodes read headers will match)
output_fp = '%s/s_%s_%s_sequences.fastq' % (output_dir, lane, read)
output_f = open(output_fp, 'w')
for read1_fp in read1_fps:
for record in iter_split_lines(open(read1_fp, 'U')):
fastq_s, pass_filter = illumina_data_to_fastq(record,
number_of_bases=bases)
if ignore_pass_filter or pass_filter != 0:
output_f.write('%s\n' % fastq_s)
output_f.close()
示例3: write_checkpoint
def write_checkpoint(current_key, ctr, cluster_mapping,
ids, bestscores, order, out_fp):
"""write intermediate results to checkpoint file
current_key: the identifier of the current denoiser round
ctr: a uniq counter to label the checkpoint
cluster_mapping: an intermediate cluster mapping as dict
ids: the dict of active ids
order: a list of ids, which defines the order of which flowgrams are clustered
bestscores: a dict of
"""
checkpoint_dir = out_fp + "/checkpoints/"
if (not exists(checkpoint_dir)):
create_dir(checkpoint_dir)
out_fp = checkpoint_dir + "/checkpoint%d.pickle" % ctr
out_fh = open(out_fp, "w")
pickle.dump(
(current_key,
ctr,
cluster_mapping,
ids,
bestscores,
order),
out_fh)
return out_fp
示例4: make_jobs
def make_jobs(commands, job_prefix, queue, jobs_dir="jobs/",
walltime="72:00:00", ncpus=1, nodes=1, keep_output="oe"):
"""prepare qsub text files.
command: list of commands
job_prefix: a short, descriptive name for the job.
queue: name of the queue to submit to
jobs_dir: path to directory where job submision scripts are written
walltime: the maximal walltime
ncpus: number of cpus
nodes: number of nodes
keep_output: keep standard error, standard out, both, or neither
o=std out, e=std err, oe=both, n=neither
"""
filenames = []
create_dir(jobs_dir)
for command in commands:
fd, job_name = mkstemp(dir=jobs_dir, prefix=job_prefix + "_",
suffix=".txt")
close(fd)
out_fh = open(job_name, "w")
out_fh.write(QSUB_TEXT % (walltime, ncpus, nodes, queue, job_prefix,
keep_output, command))
out_fh.close()
filenames.append(job_name)
return filenames
示例5: main
def main():
args = handle_program_options()
if osp.isfile(args.out_dir):
print("--out_dir (-o) option must be a valid directory and not a file",
file=sys.stderr)
sys.exit(1)
# will fail gracefully if dir exists
skbu.create_dir(args.out_dir)
metagenomes = []
if args.metagenome_id is not None:
metagenomes.append(args.metagenome_id)
elif args.metagenome_file is not None:
metagenomes.extend(parse_metagenome_file(args.metagenome_file))
if args.verbose:
msg = 'Processing requested for {} metagenome(s) found in: {}'
print(msg.format(len(metagenomes), args.metagenome_file))
# MG-RAST stage.file ids for downloading
derep_passed = '150.1'
screen_passed = '299.1'
for mg_id in metagenomes:
if args.verbose:
print('Processing metagenome: {}'.format(mg_id))
print('\tDownloading: Dereplication Passed...', end='')
sys.stdout.flush()
derepp_rsp = mgapi.mgrast_request('download', mg_id,
{'file': derep_passed},
auth_key=args.auth_key)
derepp_sc = SequenceCollection.read(StringIO(derepp_rsp.text),
format='fastq',
variant='illumina1.8')
if args.verbose:
print('{} sequences'.format(len(derepp_sc)))
print('\tDownloading: Screen Passed...', end='')
sys.stdout.flush()
screenp_rsp = mgapi.mgrast_request('download', mg_id,
{'file': screen_passed},
auth_key=args.auth_key)
screenp_ids = extract_seq_ids(screenp_rsp.text, fmt='fastq',
variant='illumina1.8')
if args.verbose:
print('{} sequences'.format(len(screenp_ids)))
# filter dereplication passed with IDs from screen passed
failed_screen = filter_seqs(derepp_sc, screenp_ids)
if args.verbose:
nsp = len(screenp_ids)
print('\tRemoved {} sequences from Dereplication Passed'.format(nsp))
print('\tleaving {} sequences'.format(len(failed_screen)))
out_fp = osp.join(args.out_dir, mg_id + '_screen_failed.fastq')
failed_screen.write(out_fp, format='fastq', variant='illumina1.8')
if args.verbose:
print('Sequence data written to: ' + out_fp)
示例6: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
if len(opts.taxa_summary_fps) != 2:
option_parser.error("Exactly two taxa summary files are required. You "
"provided %d." % len(opts.taxa_summary_fps))
# Create the output dir if it doesn't already exist.
try:
create_dir(opts.output_dir)
except:
option_parser.error("Could not create or access output directory "
"specified with the -o option.")
sample_id_map = None
if opts.sample_id_map_fp:
sample_id_map = parse_sample_id_map(open(opts.sample_id_map_fp, 'U'))
results = compare_taxa_summaries(
parse_taxa_summary_table(open(opts.taxa_summary_fps[0], 'U')),
parse_taxa_summary_table(open(opts.taxa_summary_fps[1], 'U')),
opts.comparison_mode, correlation_type=opts.correlation_type,
tail_type=opts.tail_type, num_permutations=opts.num_permutations,
confidence_level=opts.confidence_level,
perform_detailed_comparisons=opts.perform_detailed_comparisons,
sample_id_map=sample_id_map,
expected_sample_id=opts.expected_sample_id)
# Write out the sorted and filled taxa summaries, basing their
# filenames on the original input filenames. If the filenames are the same,
# append a number to each filename.
same_filenames = False
if basename(opts.taxa_summary_fps[0]) == \
basename(opts.taxa_summary_fps[1]):
same_filenames = True
for orig_ts_fp, filled_ts_lines, file_num in zip(opts.taxa_summary_fps,
results[:2], range(0, 2)):
filename_suffix = '_sorted_and_filled'
if same_filenames:
filename_suffix += '_%d' % file_num
filled_ts_fp = add_filename_suffix(orig_ts_fp, filename_suffix)
filled_ts_f = open(join(opts.output_dir, filled_ts_fp), 'w')
filled_ts_f.write(filled_ts_lines)
filled_ts_f.close()
# Write the overall comparison result.
overall_comp_f = open(join(opts.output_dir, 'overall_comparison.txt'), 'w')
overall_comp_f.write(results[2])
overall_comp_f.close()
# Write the correlation vector containing the pairwise sample comparisons.
if opts.perform_detailed_comparisons:
corr_vec_f = open(join(opts.output_dir,
'detailed_comparisons.txt'), 'w')
corr_vec_f.write(results[3])
corr_vec_f.close()
示例7: main
def main():
with open('/data/input/AppSession.json', 'U') as fd_json:
app = json.load(fd_json)
jobs = '1'
# get command attributes, etc
for item in app['Properties']['Items']:
if item['Name'] == 'Input.Projects':
project_id = item['Items'][0]['Id']
if item['Name'] == 'Input.number-of-jobs':
jobs = item['Content']
# from BaseSpace's documentation
input_dir = '/data/input/samples/'
base = join('/data/output/appresults/', project_id)
output_dir = join(base, 'sl-out')
# for sanity
create_dir(output_dir)
# split libraries
cmd = ("multiple_split_libraries_fastq.py "
"-i '{input_dir}' -o '{output_dir}'")
params = {'input_dir': input_dir, 'output_dir': output_dir}
system_call(cmd.format(**params))
for log_file in glob(join(output_dir, 'log_*')):
with open(log_file, 'U') as fd_log:
print fd_log.read()
# OTU picking
input_dir = join(output_dir, 'seqs.fna')
output_dir = join(base, 'closed-ref')
cmd = ("pick_closed_reference_otus.py "
"-i '{input_seqs}' -o '{output_dir}'")
params = {'input_seqs': input_dir, 'output_dir': output_dir, 'jobs': jobs}
# see https://github.com/biocore/qiime/issues/2034
if jobs != '1':
cmd += ' -a -O {jobs}'
system_call(cmd.format(**params))
for log_file in glob(join(output_dir, 'log_*')):
with open(log_file, 'U') as fd_log:
print fd_log.read()
input_dir = join(output_dir, 'otu_table.biom')
output_dir = join(base, 'closed-ref', 'table-summary.txt')
cmd = ("biom summarize-table "
"-i '{input_table}' -o '{output_summary}'")
params = {'input_table': input_dir, 'output_summary': output_dir}
system_call(cmd.format(**params))
return 0
示例8: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
# Create the output dir if it doesn't already exist.
out_dir = opts.output_dir
try:
create_dir(out_dir)
except:
option_parser.error("Could not create or access output directory "
"specified with the -o option.")
map_f = open(opts.mapping_fp, 'U')
dm_f = open(opts.distance_matrix_fp, 'U')
fields = map(strip, opts.fields.split(','))
fields = [field.strip('"').strip("'") for field in fields]
color_individual_within_by_field = opts.color_individual_within_by_field
results = make_distance_boxplots(dm_f, map_f, fields, width=opts.width,
height=opts.height, suppress_all_within=opts.suppress_all_within,
suppress_all_between=opts.suppress_all_between,
suppress_individual_within=opts.suppress_individual_within,
suppress_individual_between=opts.suppress_individual_between,
y_min=opts.y_min, y_max=opts.y_max,
whisker_length=opts.whisker_length, box_width=opts.box_width,
box_color=opts.box_color,
color_individual_within_by_field=color_individual_within_by_field,
sort=opts.sort)
for field, plot_figure, plot_data, plot_labels, plot_colors in results:
output_plot_fp = join(out_dir, "%s_Distances.%s" %
(field, opts.imagetype))
plot_figure.savefig(output_plot_fp, format=opts.imagetype,
transparent=opts.transparent)
if not opts.suppress_significance_tests:
sig_tests_f = open(join(out_dir, "%s_Stats.txt" % field), 'w')
sig_tests_results = all_pairs_t_test(plot_labels, plot_data,
tail_type=opts.tail_type,
num_permutations=opts.num_permutations)
sig_tests_f.write(sig_tests_results)
sig_tests_f.close()
if opts.save_raw_data:
# Write the raw plot data into a tab-delimited file.
assert(len(plot_labels) == len(plot_data))
raw_data_fp = join(out_dir, "%s_Distances.txt" % field)
raw_data_f = open(raw_data_fp, 'w')
for label, data in zip(plot_labels, plot_data):
raw_data_f.write(label.replace(" ", "_") + "\t")
raw_data_f.write("\t".join(map(str, data)))
raw_data_f.write("\n")
raw_data_f.close()
示例9: setUp
def setUp(self):
# create the temporary input files that will be used
self.iupac = {'A': 'A', 'T': 'T', 'G': 'G', 'C': 'C', 'R': '[AG]',
'Y': '[CT]', 'S': '[GC]', 'W':
'[AT]', 'K': '[GT]', 'M': '[AC]',
'B': '[CGT]', 'D': '[AGT]', 'H': '[ACT]', 'V': '[ACG]', 'N': '[ACGT]'}
self.output_dir = mkdtemp()
self.output_dir += '/'
create_dir(self.output_dir)
示例10: write_xml_file
def write_xml_file(self, element, fp):
"""Writes an XML file after calling one of the XML generation
functions
Parameters
----------
element : ET.Element
The Element to be written
fp : str
The filepath to which the XML will be written
"""
create_dir(self.xml_dir)
ET.ElementTree(element).write(fp, encoding='UTF-8')
示例11: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
out_dir = opts.output_dir
categories = opts.categories.split(",")
# Create the output dir if it doesn't already exist.
try:
if not exists(out_dir):
create_dir(out_dir)
except:
option_parser.error(
"Could not create or access output directory '%s' " "specified with the -o option." % out_dir
)
compare_categories(opts.input_dm, opts.mapping_file, opts.method, categories, opts.num_permutations, out_dir)
示例12: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
if opts.num_permutations < 1:
option_parser.error(
"--num_permutations must be greater than or equal to 1.")
# Create the output dir if it doesn't already exist.
try:
if not path.exists(opts.output_dir):
create_dir(opts.output_dir)
except:
option_parser.error("Could not create or access output directory "
"specified with the -o option.")
sample_id_map = None
if opts.sample_id_map_fp:
sample_id_map = dict([(k, v[0])
for k, v in fields_to_dict(open(opts.sample_id_map_fp, "U")).items()])
input_dm_fps = opts.input_dms
distmats = [parse_distmat(open(dm_fp, 'U')) for dm_fp in input_dm_fps]
if opts.method == 'mantel':
output_f = open(path.join(opts.output_dir, 'mantel_results.txt'), 'w')
output_f.write(run_mantel_test('mantel', input_dm_fps, distmats,
opts.num_permutations, opts.tail_type,
comment_mantel_pmantel, sample_id_map=sample_id_map))
elif opts.method == 'partial_mantel':
output_f = open(path.join(opts.output_dir,
'partial_mantel_results.txt'), 'w')
output_f.write(run_mantel_test('partial_mantel', input_dm_fps,
distmats, opts.num_permutations, opts.tail_type,
comment_mantel_pmantel, control_dm_fp=opts.control_dm,
control_dm=parse_distmat(open(opts.control_dm, 'U')),
sample_id_map=sample_id_map))
elif opts.method == 'mantel_corr':
output_f = open(path.join(opts.output_dir,
'mantel_correlogram_results.txt'), 'w')
result_str, correlogram_fps, correlograms = run_mantel_correlogram(
input_dm_fps, distmats, opts.num_permutations, comment_corr,
opts.alpha, sample_id_map=sample_id_map,
variable_size_distance_classes=opts.variable_size_distance_classes)
output_f.write(result_str)
for corr_fp, corr in zip(correlogram_fps, correlograms):
corr.savefig(path.join(opts.output_dir, corr_fp + opts.image_type),
format=opts.image_type)
output_f.close()
示例13: setUp
def setUp(self):
# create the temporary input files that will be used
self._files_to_remove = []
fd, self.qual_fp = mkstemp(prefix='qual_scores_', suffix='.qual')
close(fd)
seq_file = open(self.qual_fp, 'w')
seq_file.write(qual_scores)
seq_file.close()
self.output_dir = mkdtemp()
self.output_dir += '/'
create_dir(self.output_dir)
self.expected_output_text_file = expected_output_text_file
self._files_to_remove =\
[self.qual_fp]
示例14: test_create_dir
def test_create_dir(self):
# create a directory
tmp_dir_path = mkdtemp()
# create a random temporary directory name
tmp_dir_path2 = join(mkdtemp(), str(uuid4()))
tmp_dir_path3 = join(mkdtemp(), str(uuid4()))
self.dirs_to_remove += [tmp_dir_path, tmp_dir_path2, tmp_dir_path3]
# create on existing dir raises OSError if fail_on_exist=True
self.assertRaises(OSError, create_dir, tmp_dir_path, fail_on_exist=True)
self.assertEqual(create_dir(tmp_dir_path, fail_on_exist=True, handle_errors_externally=True), 1)
# return should be 1 if dir exist and fail_on_exist=False
self.assertEqual(create_dir(tmp_dir_path, fail_on_exist=False), 1)
# if dir not there make it and return always 0
self.assertEqual(create_dir(tmp_dir_path2), 0)
self.assertEqual(create_dir(tmp_dir_path3, fail_on_exist=True), 0)
示例15: split_fasta
def split_fasta(infile, seqs_per_file, outfile_prefix, working_dir=''):
""" Split infile into files with seqs_per_file sequences in each
infile: list of fasta lines or open file object
seqs_per_file: the number of sequences to include in each file
out_fileprefix: string used to create output filepath - output filepaths
are <out_prefix>.<i>.fasta where i runs from 0 to number of output files
working_dir: directory to prepend to temp filepaths (defaults to
empty string -- files written to cwd)
List of output filepaths is returned.
"""
if seqs_per_file <= 0:
raise ValueError("seqs_per_file must be > 0!")
seq_counter = 0
out_files = []
if working_dir and not working_dir.endswith('/'):
working_dir += '/'
create_dir(working_dir)
for seq_id, seq in parse_fasta(infile):
if seq_counter == 0:
current_out_fp = '%s%s.%d.fasta' \
% (working_dir, outfile_prefix, len(out_files))
current_out_file = open(current_out_fp, 'w')
out_files.append(current_out_fp)
current_out_file.write('>%s\n%s\n' % (seq_id, seq))
seq_counter += 1
if seq_counter == seqs_per_file:
current_out_file.close()
seq_counter = 0
if not current_out_file.closed:
current_out_file.close()
return out_files