本文整理汇总了Python中qiime.filter.filter_otus_from_otu_table函数的典型用法代码示例。如果您正苦于以下问题:Python filter_otus_from_otu_table函数的具体用法?Python filter_otus_from_otu_table怎么用?Python filter_otus_from_otu_table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filter_otus_from_otu_table函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filter_otus_from_otu_table_negate
def test_filter_otus_from_otu_table_negate(self):
"""filter_otus_from_otu_table: functions as expected with negate=True
"""
actual = filter_otus_from_otu_table(self.input_otu_table1,
self.input_seqs_to_discard1,
negate=True)
self.assertEqual(actual,self.expected_otu_table1b)
示例2: rarefy_to_files
def rarefy_to_files(self, output_dir, small_included=False,
include_full=False, include_lineages=False,
empty_otus_removed=False,subsample_f=subsample):
""" computes rarefied otu tables and writes them, one at a time
this prevents large memory usage"""
if not include_lineages:
for (val, id, meta) in self.otu_table.iterObservations():
try:
del meta['taxonomy']
except (TypeError,KeyError) as e:
# no meta or just no taxonomy present
pass
self.output_dir = output_dir
for depth in self.rare_depths:
for rep in range(self.num_reps):
sub_otu_table = get_rare_data(self.otu_table,
depth,
small_included,
subsample_f=subsample_f)
if empty_otus_removed:
sub_otu_table = filter_otus_from_otu_table(\
sub_otu_table,
sub_otu_table.ObservationIds, 1, inf, 0, inf)
self._write_rarefaction(depth, rep, sub_otu_table)
if include_full:
self._write_rarefaction('full', 0, self.otu_table)
示例3: rarefy_to_file
def rarefy_to_file(
self,
output_fname,
small_included=False,
include_lineages=False,
empty_otus_removed=False,
subsample_f=subsample,
):
""" computes rarefied otu tables and writes them, one at a time
this prevents large memory usage
for depth in self.rare_depths:
for rep in range(self.num_reps):"""
if not include_lineages:
for (val, id, meta) in self.otu_table.iterObservations():
del meta["taxonomy"]
sub_otu_table = get_rare_data(self.otu_table, self.depth, small_included, subsample_f=subsample_f)
if empty_otus_removed:
sub_otu_table = filter_otus_from_otu_table(sub_otu_table, sub_otu_table.ObservationIds, 1, inf, 0, inf)
self._write_rarefaction(output_fname, sub_otu_table)
示例4: filter_by_otu_hits
def filter_by_otu_hits(num_otu_hits, otu_table):
"""Filter the OTU table by the number of otus per sample"""
# Filter out rows with sum > num_otu_hits
new_otu_table = filter_otus_from_otu_table(otu_table, otu_table.ObservationIds,
num_otu_hits, inf,0,inf)
return new_otu_table
示例5: main
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
input_fp = opts.input_fp
output_fp = opts.output_fp
min_count = opts.min_count
max_count = opts.max_count
min_count_fraction = opts.min_count_fraction
if min_count_fraction < 0. or min_count_fraction > 1.:
option_parser.error("min_count_fraction must be between 0 and 1")
if min_count != 0 and min_count_fraction != 0:
option_parser.error(
"cannot specify both min_count and min_count_fraction")
min_samples = opts.min_samples
max_samples = opts.max_samples
otu_ids_to_exclude_fp = opts.otu_ids_to_exclude_fp
negate_ids_to_exclude = opts.negate_ids_to_exclude
if not (min_count != 0 or
min_count_fraction != 0 or
not isinf(max_count) or
otu_ids_to_exclude_fp is not None or
min_samples != 0 or not isinf(max_samples)):
option_parser.error("No filtering requested. Must provide either "
"min counts, max counts, min samples, max samples, min_count_fraction, "
"or exclude_fp (or some combination of those).")
otu_table = load_table(opts.input_fp)
if min_count_fraction > 0:
min_count = otu_table.sum() * min_count_fraction
print otu_table.sum(), min_count
otu_ids_to_keep = set(otu_table.observation_ids)
if otu_ids_to_exclude_fp:
if otu_ids_to_exclude_fp.endswith('.fasta') or \
otu_ids_to_exclude_fp.endswith('.fna'):
otu_ids_to_exclude = set([id_.strip().split()[0]
for id_, seq in parse_fasta(open(otu_ids_to_exclude_fp, 'U'))])
else:
otu_ids_to_exclude = set([l.strip().split('\t')[0]
for l in open(otu_ids_to_exclude_fp, 'U')])
otu_ids_to_keep -= otu_ids_to_exclude
filtered_otu_table = filter_otus_from_otu_table(otu_table,
otu_ids_to_keep,
min_count,
max_count,
min_samples,
max_samples,
negate_ids_to_exclude)
write_biom_table(filtered_otu_table, opts.output_fp)
示例6: pick_subsampled_open_reference_otus
#.........这里部分代码省略.........
final_repset_f.write('>%s\n%s\n' % (otu_id,seq))
new_refseqs_f.close()
final_repset_f.close()
# Prep the make_otu_table.py command
otu_table_fp = '%s/otu_table_mc%d.biom' % (output_dir,min_otu_size)
make_otu_table_cmd = 'make_otu_table.py -i %s -o %s' %\
(otu_no_singletons_fp,otu_table_fp)
commands.append([("Make the otu table",make_otu_table_cmd)])
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
# initialize output file names - these differ based on what combination of
# taxonomy assignment and alignment/tree building is happening.
if run_assign_tax and run_align_and_tree:
tax_input_otu_table_fp = otu_table_fp
otu_table_w_tax_fp = \
'%s/otu_table_mc%d_w_tax.biom' % (output_dir,min_otu_size)
align_and_tree_input_otu_table = otu_table_w_tax_fp
pynast_failure_filtered_otu_table_fp = \
'%s/otu_table_mc%d_w_tax_no_pynast_failures.biom' % (output_dir,min_otu_size)
elif run_assign_tax:
tax_input_otu_table_fp = otu_table_fp
otu_table_w_tax_fp = \
'%s/otu_table_mc%d_w_tax.biom' % (output_dir,min_otu_size)
elif run_align_and_tree:
align_and_tree_input_otu_table = otu_table_fp
pynast_failure_filtered_otu_table_fp = \
'%s/otu_table_mc%d_no_pynast_failures.biom' % (output_dir,min_otu_size)
if run_assign_tax:
if exists(otu_table_w_tax_fp) and getsize(otu_table_w_tax_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." % otu_table_w_tax_fp)
else:
# remove files from partially completed runs
remove_files([otu_table_w_tax_fp],error_on_missing=False)
taxonomy_fp = assign_tax(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback)
# Add taxa to otu table
add_metadata_cmd = 'biom add-metadata -i %s --observation-metadata-fp %s -o %s --sc-separated taxonomy --observation-header OTUID,taxonomy' %\
(tax_input_otu_table_fp,taxonomy_fp,otu_table_w_tax_fp)
commands.append([("Add taxa to OTU table",add_metadata_cmd)])
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
if run_align_and_tree:
if exists(pynast_failure_filtered_otu_table_fp) and\
getsize(pynast_failure_filtered_otu_table_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." %\
pynast_failure_filtered_otu_table_fp)
else:
# remove files from partially completed runs
remove_files([pynast_failure_filtered_otu_table_fp],
error_on_missing=False)
pynast_failures_fp = align_and_tree(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback)
# Build OTU table without PyNAST failures
filtered_otu_table = filter_otus_from_otu_table(
parse_biom_table(open(align_and_tree_input_otu_table,'U')),
get_seq_ids_from_fasta_file(open(pynast_failures_fp,'U')),
0,inf,0,inf,negate_ids_to_keep=True)
otu_table_f = open(pynast_failure_filtered_otu_table_fp,'w')
otu_table_f.write(format_biom_table(filtered_otu_table))
otu_table_f.close()
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
if close_logger_on_success:
logger.close()
示例7: iterative_pick_subsampled_open_reference_otus
#.........这里部分代码省略.........
# Merge OTU tables - check for existence first as this step has historically
# been a frequent failure, so is sometimes run manually in failed runs.
otu_table_fp = '%s/otu_table_mc%d.biom' % (output_dir,min_otu_size)
if not (exists(otu_table_fp) and getsize(otu_table_fp) > 0):
merge_cmd = 'merge_otu_tables.py -i %s -o %s' %\
(','.join(otu_table_fps),otu_table_fp)
commands.append([("Merge OTU tables",merge_cmd)])
# Build master rep set
final_repset_fp = '%s/rep_set.fna' % output_dir
final_repset_from_iteration_repsets_fps(repset_fasta_fps,final_repset_fp)
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
# initialize output file names - these differ based on what combination of
# taxonomy assignment and alignment/tree building is happening.
if run_assign_tax and run_align_and_tree:
tax_input_otu_table_fp = otu_table_fp
otu_table_w_tax_fp = \
'%s/otu_table_mc%d_w_tax.biom' % (output_dir,min_otu_size)
align_and_tree_input_otu_table = otu_table_w_tax_fp
pynast_failure_filtered_otu_table_fp = \
'%s/otu_table_mc%d_w_tax_no_pynast_failures.biom' % (output_dir,min_otu_size)
elif run_assign_tax:
tax_input_otu_table_fp = otu_table_fp
otu_table_w_tax_fp = \
'%s/otu_table_mc%d_w_tax.biom' % (output_dir,min_otu_size)
elif run_align_and_tree:
align_and_tree_input_otu_table = otu_table_fp
pynast_failure_filtered_otu_table_fp = \
'%s/otu_table_mc%d_no_pynast_failures.biom' % (output_dir,min_otu_size)
if run_assign_tax:
if exists(otu_table_w_tax_fp) and getsize(otu_table_w_tax_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." % otu_table_w_tax_fp)
else:
# remove files from partially completed runs
remove_files([otu_table_w_tax_fp],error_on_missing=False)
taxonomy_fp = assign_tax(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback)
# Add taxa to otu table
add_metadata_cmd = 'biom add-metadata -i %s --observation-metadata-fp %s -o %s --sc-separated taxonomy --observation-header OTUID,taxonomy' %\
(tax_input_otu_table_fp,taxonomy_fp,otu_table_w_tax_fp)
commands.append([("Add taxa to OTU table",add_metadata_cmd)])
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
if run_align_and_tree:
if exists(pynast_failure_filtered_otu_table_fp) and\
getsize(pynast_failure_filtered_otu_table_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." %\
pynast_failure_filtered_otu_table_fp)
else:
# remove files from partially completed runs
remove_files([pynast_failure_filtered_otu_table_fp],
error_on_missing=False)
pynast_failures_fp = align_and_tree(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback)
# Build OTU table without PyNAST failures
filtered_otu_table = filter_otus_from_otu_table(
parse_biom_table(open(align_and_tree_input_otu_table,'U')),
get_seq_ids_from_fasta_file(open(pynast_failures_fp,'U')),
0,inf,0,inf,negate_ids_to_keep=True)
otu_table_f = open(pynast_failure_filtered_otu_table_fp,'w')
otu_table_f.write(format_biom_table(filtered_otu_table))
otu_table_f.close()
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
logger.close()
示例8: test_filter_otus_from_otu_table
def test_filter_otus_from_otu_table(self):
"""filter_otus_from_otu_table: functions as expected
"""
actual = filter_otus_from_otu_table(self.input_otu_table1,
self.input_seqs_to_discard1)
self.assertEqual(actual,self.expected_otu_table1a)
示例9: pick_subsampled_open_reference_otus
#.........这里部分代码省略.........
otu_table_w_tax_fp = \
'%s/otu_table_mc%d_w_tax.biom' % (output_dir, min_otu_size)
index_links.append(
('OTU table exluding OTUs with fewer than %d sequences and including OTU '
'taxonomy assignments' % min_otu_size,
otu_table_w_tax_fp,
_index_headers['otu_tables']))
elif run_align_and_tree:
align_and_tree_input_otu_table = otu_table_fp
pynast_failure_filtered_otu_table_fp = \
'%s/otu_table_mc%d_no_pynast_failures.biom' % (output_dir,
min_otu_size)
index_links.append(
('OTU table exluding OTUs with fewer than %d sequences and sequences that '
'fail to align with PyNAST' % min_otu_size,
pynast_failure_filtered_otu_table_fp,
_index_headers['otu_tables']))
if run_assign_tax:
if exists(otu_table_w_tax_fp) and getsize(otu_table_w_tax_fp) > 0:
logger.write(
"Final output file exists (%s). Will not rebuild." %
otu_table_w_tax_fp)
else:
# remove files from partially completed runs
remove_files([otu_table_w_tax_fp], error_on_missing=False)
taxonomy_fp = assign_tax(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback)
index_links.append(
('OTU taxonomic assignments',
taxonomy_fp,
_index_headers['taxa_assignments']))
# Add taxa to otu table
add_metadata_cmd = 'biom add-metadata -i %s --observation-metadata-fp %s -o %s --sc-separated taxonomy --observation-header OTUID,taxonomy' %\
(tax_input_otu_table_fp, taxonomy_fp, otu_table_w_tax_fp)
commands.append([("Add taxa to OTU table", add_metadata_cmd)])
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
if run_align_and_tree:
rep_set_tree_fp = join(output_dir, 'rep_set.tre')
index_links.append(
('OTU phylogenetic tree',
rep_set_tree_fp,
_index_headers['trees']))
if exists(pynast_failure_filtered_otu_table_fp) and\
getsize(pynast_failure_filtered_otu_table_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." %
pynast_failure_filtered_otu_table_fp)
else:
# remove files from partially completed runs
remove_files([pynast_failure_filtered_otu_table_fp],
error_on_missing=False)
pynast_failures_fp = align_and_tree(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback)
# Build OTU table without PyNAST failures
table = load_table(align_and_tree_input_otu_table)
filtered_otu_table = filter_otus_from_otu_table(table,
get_seq_ids_from_fasta_file(open(pynast_failures_fp, 'U')),
0, inf, 0, inf, negate_ids_to_keep=True)
write_biom_table(filtered_otu_table,
pynast_failure_filtered_otu_table_fp)
command_handler(commands,
status_update_callback,
logger=logger,
close_logger_on_success=False)
commands = []
if close_logger_on_success:
logger.close()
if not suppress_index_page:
index_fp = '%s/index.html' % output_dir
generate_index_page(index_links, index_fp)
示例10: pick_subsampled_open_reference_otus
#.........这里部分代码省略.........
final_repset_f.write(">%s\n%s\n" % (otu_id, seq))
new_refseqs_f.close()
final_repset_f.close()
logger.write(
"# Write non-singleton otus representative sequences from "
+ "step 2 and step 4 to the final representative set and the new reference"
+ " set (%s and %s respectively)\n\n" % (final_repset_fp, new_refseqs_fp)
)
# Prep the make_otu_table.py command
otu_table_fp = "%s/otu_table_mc%d.biom" % (output_dir, min_otu_size)
make_otu_table_cmd = "make_otu_table.py -i %s -o %s" % (otu_no_singletons_fp, otu_table_fp)
commands.append([("Make the otu table", make_otu_table_cmd)])
command_handler(commands, status_update_callback, logger=logger, close_logger_on_success=False)
commands = []
# initialize output file names - these differ based on what combination of
# taxonomy assignment and alignment/tree building is happening.
if run_assign_tax and run_align_and_tree:
tax_input_otu_table_fp = otu_table_fp
otu_table_w_tax_fp = "%s/otu_table_mc%d_w_tax.biom" % (output_dir, min_otu_size)
align_and_tree_input_otu_table = otu_table_w_tax_fp
pynast_failure_filtered_otu_table_fp = "%s/otu_table_mc%d_w_tax_no_pynast_failures.biom" % (
output_dir,
min_otu_size,
)
elif run_assign_tax:
tax_input_otu_table_fp = otu_table_fp
otu_table_w_tax_fp = "%s/otu_table_mc%d_w_tax.biom" % (output_dir, min_otu_size)
elif run_align_and_tree:
align_and_tree_input_otu_table = otu_table_fp
pynast_failure_filtered_otu_table_fp = "%s/otu_table_mc%d_no_pynast_failures.biom" % (output_dir, min_otu_size)
if run_assign_tax:
if exists(otu_table_w_tax_fp) and getsize(otu_table_w_tax_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." % otu_table_w_tax_fp)
else:
# remove files from partially completed runs
remove_files([otu_table_w_tax_fp], error_on_missing=False)
taxonomy_fp = assign_tax(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback,
)
# Add taxa to otu table
add_metadata_cmd = (
"biom add-metadata -i %s --observation-metadata-fp %s -o %s --sc-separated taxonomy --observation-header OTUID,taxonomy"
% (tax_input_otu_table_fp, taxonomy_fp, otu_table_w_tax_fp)
)
commands.append([("Add taxa to OTU table", add_metadata_cmd)])
command_handler(commands, status_update_callback, logger=logger, close_logger_on_success=False)
commands = []
if run_align_and_tree:
if exists(pynast_failure_filtered_otu_table_fp) and getsize(pynast_failure_filtered_otu_table_fp) > 0:
logger.write("Final output file exists (%s). Will not rebuild." % pynast_failure_filtered_otu_table_fp)
else:
# remove files from partially completed runs
remove_files([pynast_failure_filtered_otu_table_fp], error_on_missing=False)
pynast_failures_fp = align_and_tree(
repset_fasta_fp=final_repset_fp,
output_dir=output_dir,
command_handler=command_handler,
params=params,
qiime_config=qiime_config,
parallel=parallel,
logger=logger,
status_update_callback=status_update_callback,
)
# Build OTU table without PyNAST failures
filtered_otu_table = filter_otus_from_otu_table(
parse_biom_table(open(align_and_tree_input_otu_table, "U")),
get_seq_ids_from_fasta_file(open(pynast_failures_fp, "U")),
0,
inf,
0,
inf,
negate_ids_to_keep=True,
)
otu_table_f = open(pynast_failure_filtered_otu_table_fp, "w")
otu_table_f.write(format_biom_table(filtered_otu_table))
otu_table_f.close()
command_handler(commands, status_update_callback, logger=logger, close_logger_on_success=False)
commands = []
if close_logger_on_success:
logger.close()