本文整理汇总了Python中qiime.util.parse_command_line_parameters函数的典型用法代码示例。如果您正苦于以下问题:Python parse_command_line_parameters函数的具体用法?Python parse_command_line_parameters怎么用?Python parse_command_line_parameters使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_command_line_parameters函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
if opts.show_metrics:
print("Known metrics are: %s\n" \
% (', '.join(list_known_metrics()),))
print("For more information, see http://qiime.org/scripts/alpha_diversity_metrics.html")
exit(0)
almost_required_options = ['input_path','output_path','metrics']
for option in almost_required_options:
if getattr(opts,option) == None:
option_parser.error('Required option --%s omitted.' % option)
if os.path.isdir(opts.input_path):
multiple_file_alpha(opts.input_path, opts.output_path, opts.metrics,
opts.tree_path)
elif os.path.isfile(opts.input_path):
try:
f = open(opts.output_path, 'w')
f.close()
except IOError:
print("ioerror, couldn't create output file")
exit(1)
single_file_alpha(opts.input_path, opts.metrics,
opts.output_path, opts.tree_path)
else:
print("io error, input path not valid. does it exist?")
exit(1)
示例2: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
if opts.submit_jobs and not opts.make_jobs:
option_parser.error('Must pass -m if passing -s. (Sorry about this, '+\
'it\'s for backwards-compatibility.)')
min_args = 2
if len(args) != min_args:
option_parser.error('Program requires <commands file> and <job prefix>')
if (len(args[1])>10 or len(args[1])==0):
option_parser.error('job prefix must be 1-10 characters long')
commands = list(open(args[0]))
job_prefix = args[1]
if(not exists(opts.job_dir)):
try:
makedirs(opts.job_dir)
except OSError:
exit(" Jobs directory can not be created. "
+"Check for permissions or file with the same name: %s\n"
% opts.job_dir)
if (opts.make_jobs):
filenames = make_jobs(commands, job_prefix, opts.queue, opts.job_dir)
else:
exit("Should we ever get here???")
if (opts.submit_jobs):
submit_jobs(filenames, opts.verbose)
示例3: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
if opts.num_permutations < 10:
option_parser.error('Number of permuations must be greater than or '
'equal to 10.')
rarefaction_lines = open(opts.alpha_diversity_fp, 'U')
mapping_lines = open(opts.mapping_fp, 'U')
category = opts.category
depth = int(opts.depth)
output_path = opts.output_fp
result = compare_alpha_diversities(rarefaction_lines, mapping_lines,
category, depth, opts.test_type, opts.num_permutations)
rarefaction_lines.close()
mapping_lines.close()
corrected_result = _correct_compare_alpha_results(result,
opts.correction_method)
# write results
outfile = open(output_path, 'w')
header = 'Comparison\ttval\tpval'
lines = [header]
for k,v in corrected_result.items():
lines.append('\t'.join(map(str,[k,v[0],v[1]])))
outfile.write('\n'.join(lines))
outfile.close()
示例4: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
fasta_fp = opts.fasta_fp
mapping_fp = opts.mapping_fp
output_dir = opts.output_dir
truncate_option = opts.truncate_option
primer_mismatches = int(opts.primer_mismatches)
create_dir(output_dir)
if truncate_option not in ['truncate_only', 'truncate_remove']:
raise ValueError('-z option must be either truncate_only or ' +
'truncate_remove')
try:
fasta_f = open(fasta_fp, "U")
fasta_f.close()
except IOError:
raise IOError("Unable to open fasta file, please check path/" +
"permissions.")
try:
mapping_f = open(fasta_fp, "U")
mapping_f.close()
except IOError:
raise IOError("Unable to open mapping file, please check path/" +
"permissions.")
truncate_reverse_primer(fasta_fp, mapping_fp, output_dir, truncate_option,
primer_mismatches)
示例5: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
reference_seqs_filepath = opts.reference_seqs_fp
input_seqs_filepath = opts.fasta_fp
input_otu_filepath = opts.otu_fp
result_path = opts.result_fp or\
'%s_rep_set.fasta' % input_seqs_filepath
log_path = opts.log_fp
if reference_seqs_filepath:
rep_set_picker =\
reference_rep_set_picking_methods[opts.rep_set_picking_method]
rep_set_picker(input_seqs_filepath,
input_otu_filepath,
reference_seqs_filepath,
result_path=result_path,
log_path=log_path,
sort_by=opts.sort_by)
else:
if not input_seqs_filepath:
option_parser.error('--fasta_fp must be provided when not picking'
' representative against a reference set.')
rep_set_picker =\
rep_set_picking_methods[opts.rep_set_picking_method]
rep_set_picker(input_seqs_filepath,
input_otu_filepath,
result_path=result_path,
log_path=log_path,
sort_by=opts.sort_by)
示例6: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
otu_files = map(open, opts.otu_map_fps)
failures_fp = opts.failures_fp
output_fp = opts.output_fp
if failures_fp:
failures_f = open(failures_fp, 'U')
else:
failures_f = None
try:
result = map_otu_map_files(otu_files, failures_file=failures_f)
except KeyError as e:
print ('Some keys do not map (' + str(e) + ') -- is the order of'
' your OTU maps equivalent to the order in which the OTU pickers'
' were run? If expanding a failures file, did you remember to leave'
' out the otu map from the run which generated the failures file?')
exit(1)
if failures_fp is not None:
of = open(output_fp, 'w')
of.write('\n'.join(result))
of.close()
else:
write_otu_map(result.items(), output_fp)
示例7: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
output_dir = opts.output_dir
mapping_category = opts.mapping_category
try:
makedirs(output_dir)
except OSError:
pass
percent_failures_data, percent_failures_plot, num_new_otus_data, \
num_new_otus_plot = generate_new_diversity_plots(
[open(otu_table_fp, 'U') for otu_table_fp in opts.otu_table_fps],
open(opts.gg_fasta_fp, 'U'), open(opts.mapping_fp, 'U'),
mapping_category, opts.min_num_samples,
opts.category_values_to_exclude.split(','), opts.verbose)
# Save plots as PDFs.
percent_failures_plot.savefig(join(output_dir,
'percent_novel_seqs_by_%s.pdf' %
mapping_category))
num_new_otus_plot.savefig(join(output_dir,
'num_novel_otus_by_%s.pdf' %
mapping_category))
# Pickle plot raw data in case we need to load up the data again into new
# plots and interactively tweak them (it'll take too long to rerun the
# whole script for these tweaks).
dump(percent_failures_data, open(join(output_dir,
'percent_novel_seqs_by_%s.p' % mapping_category), 'wb'))
dump(num_new_otus_data, open(join(output_dir,
'num_novel_otus_by_%s.p' % mapping_category), 'wb'))
示例8: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(suppress_verbose=True, **script_info)
mapping_fp = opts.mapping_fp
has_barcodes = not opts.not_barcoded
variable_len_barcodes = opts.variable_len_barcodes
output_dir = opts.output_dir + "/"
char_replace = opts.char_replace
verbose = opts.verbose
disable_primer_check = opts.disable_primer_check
added_demultiplex_field = opts.added_demultiplex_field
# Create output directory, check path/access to mapping file
create_dir(output_dir)
# Test for valid replacement characters
valid_replacement_chars = digits + letters + "_" + "."
if char_replace not in valid_replacement_chars:
option_parser.error('-c option requires alphanumeric, period, or '+\
'underscore character.')
if len(char_replace) != 1:
option_parser.error('-c parameter must be a single character.')
check_mapping_file(mapping_fp, output_dir, has_barcodes, char_replace,\
verbose, variable_len_barcodes,
disable_primer_check, added_demultiplex_field)
示例9: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
negate = opts.negate
if 1 != sum(map(bool,[opts.otu_map,
opts.seq_id_fp,
opts.subject_fasta_fp,
opts.seq_id_prefix])):
option_parser.error("Must pass exactly one of -a, -s, -p, or -m.")
if opts.otu_map:
seqs_to_keep_lookup =\
get_seqs_to_keep_lookup_from_otu_map(
open(opts.otu_map,'U'))
elif opts.seq_id_fp:
seqs_to_keep_lookup =\
get_seqs_to_keep_lookup_from_seq_id_file(
open(opts.seq_id_fp,'U'))
elif opts.subject_fasta_fp:
seqs_to_keep_lookup =\
get_seqs_to_keep_lookup_from_fasta_file(
open(opts.subject_fasta_fp,'U'))
elif opts.seq_id_prefix:
seqs_to_keep_lookup =\
get_seqs_to_keep_lookup_from_prefix(
open(opts.input_fasta_fp),opts.seq_id_prefix)
else:
option_parser.error("Must pass exactly one of -a, -s, or -m.")
filter_fasta_fp(opts.input_fasta_fp,
opts.output_fasta_fp,
seqs_to_keep_lookup,
negate)
示例10: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
split_fasta_on_sample_ids_to_files(MinimalFastaParser(open(opts.input_fasta_fp,'U')),
opts.output_dir,
opts.buffer_size)
示例11: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
if not opts.counts_fname:
parser.error("An otu table file must be specified")
if not opts.map_fname:
parser.error("A Map file must be specified")
prefs,data,background_color,label_color, ball_scale, arrow_colors= \
sample_color_prefs_and_map_data_from_options(opts)
dir_path = opts.dir_path
if dir_path==None or dir_path=='':
dir_path = get_random_directory_name()
create_dir(dir_path)
create_dir(os.path.join(dir_path,"otu_network"))
create_dir(os.path.join(dir_path,"otu_network/props"))
create_dir(os.path.join(dir_path,"otu_network/stats"))
map_lines = open(opts.map_fname,'U').readlines()
otu_sample_lines = open(opts.counts_fname, 'U').readlines()
create_network_and_stats(dir_path,map_lines,otu_sample_lines,prefs,data,background_color,label_color)
示例12: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
output_f = open(opts.output_distance_matrix, 'w')
if opts.otu_table_fp:
otu_table = load_table(opts.otu_table_fp)
samples_to_keep = otu_table.ids()
# samples_to_keep = \
# sample_ids_from_otu_table(open(opts.otu_table_fp,'U'))
elif opts.sample_id_fp:
samples_to_keep = \
get_seqs_to_keep_lookup_from_seq_id_file(
open(opts.sample_id_fp, 'U'))
elif opts.mapping_fp and opts.valid_states:
try:
samples_to_keep = sample_ids_from_metadata_description(
open(opts.mapping_fp, 'U'), opts.valid_states)
except ValueError as e:
option_parser.error(e.message)
else:
option_parser.error('must pass either --sample_id_fp, -t, or -m and '
'-s')
# note that negate gets a little weird here. The function we're calling
# removes the specified samples from the distance matrix, but the other
# QIIME filter scripts keep these samples specified. So, the interface of
# this script is designed to keep the specified samples, and therefore
# negate=True is passed to filter_samples_from_distance_matrix by default.
d = filter_samples_from_distance_matrix(
parse_distmat(
open(opts.input_distance_matrix, 'U')),
samples_to_keep,
negate=not opts.negate)
output_f.write(d)
output_f.close()
示例13: main
def main():
option_parser, opts, args =\
parse_command_line_parameters(**script_info)
otu_table_data = parse_otu_table(open(opts.input_otu_table,'U'))
sort_field = opts.sort_field
mapping_fp = opts.mapping_fp
sorted_sample_ids_fp = opts.sorted_sample_ids_fp
if sort_field and mapping_fp:
mapping_data = parse_mapping_file(open(mapping_fp,'U'))
result = sort_otu_table_by_mapping_field(otu_table_data,
mapping_data,
sort_field)
elif sorted_sample_ids_fp:
sorted_sample_ids = sample_ids_from_f(open(sorted_sample_ids_fp,'U'))
result = sort_otu_table(otu_table_data,
sorted_sample_ids)
else:
parser.error("must provide either --sort_field and --mapping_fp OR --sorted_sample_ids_fp")
# format and write the otu table
result_str = format_otu_table(result[0],result[1],result[2],result[3])
of = open(opts.output_fp,'w')
of.write(result_str)
of.close()
示例14: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
input_path = opts.input_path
output_path = opts.output_path
if isdir(input_path):
# Run PCoA on all distance matrices in the input dir
# Create the output directory if it does not exists
if not exists(output_path):
makedirs(output_path)
# Get all the filenames present in the input directory
file_names = [fname for fname in listdir(input_path)
if not (fname.startswith('.') or isdir(fname))]
# Loop through all the input files
for fname in file_names:
# Get the path to the input distance matrix
infile = join(input_path, fname)
# Run PCoA on the input distance matrix
with open(infile, 'U') as lines:
pcoa_scores = pcoa(lines)
# Store the PCoA results on the output directory
base_fname, ext = splitext(fname)
out_file = join(output_path, 'pcoa_%s.txt' % base_fname)
pcoa_scores.write(out_file)
else:
# Run PCoA on the input distance matrix
with open(input_path, 'U') as f:
pcoa_scores = pcoa(f)
# Store the results in the output file
pcoa_scores.write(output_path)
示例15: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
assignment_method = opts.assignment_method
if assignment_method == 'blast':
if not opts.id_to_taxonomy_fp:
option_parser.error('Option --id_to_taxonomy_fp is required when '
'assigning with blast.')
if not (opts.reference_seqs_fp or opts.blast_db):
option_parser.error('Either a blast db (via -b) or a collection of '
'reference sequences (via -r) must be passed to '
'assign taxonomy using blast.')
if assignment_method == 'rdp':
try:
validate_rdp_version()
except RuntimeError, e:
option_parser.error(e)
if opts.id_to_taxonomy_fp is not None:
if opts.reference_seqs_fp is None:
option_parser.error(
'A filepath for reference sequences must be '
'specified (via -r) along with the id_to_taxonomy '
'file to train the Rdp Classifier.')
elif opts.reference_seqs_fp is not None:
option_parser.error(
'A filepath for an id to taxonomy map must be '
'specified (via -t) along with the reference '
'sequences fp to train the Rdp Classifier.')
else:
pass