本文整理汇总了Python中biom.Table.add_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python Table.add_metadata方法的具体用法?Python Table.add_metadata怎么用?Python Table.add_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类biom.Table
的用法示例。
在下文中一共展示了Table.add_metadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rename_deblur_biom
# 需要导入模块: from biom import Table [as 别名]
# 或者: from biom.Table import add_metadata [as 别名]
def rename_deblur_biom(biom, name_stub='deblur', metadata_name='deblurred_seq'):
seqs = biom.ids(axis='observation')
seqnames = ['{0}{1}'.format(name_stub, x) for x in range(len(seqs))]
seq_metadata = {seqname: {metadata_name: seq} for seq, seqname in zip(seqs, seqnames)}
renamed_biom = Table(biom.matrix_data,
seqnames,
biom.ids(axis='sample'),
biom.metadata(axis='observation'),
biom.metadata(axis='sample'),
table_id = biom.table_id + ' renamed')
renamed_biom.add_metadata(seq_metadata, axis='observation')
return(renamed_biom)
示例2: main
# 需要导入模块: from biom import Table [as 别名]
# 或者: from biom.Table import add_metadata [as 别名]
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
otu_table = load_table(opts.input_otu_fp)
ids_to_load = otu_table.ids(axis="observation")
if opts.input_count_fp is None:
# precalc file has specific name (e.g. 16S_13_5_precalculated.tab.gz)
precalc_file_name = "_".join(["16S", opts.gg_version, "precalculated.tab.gz"])
input_count_table = join(get_picrust_project_dir(), "picrust", "data", precalc_file_name)
else:
input_count_table = opts.input_count_fp
if opts.verbose:
print "Loading trait table: ", input_count_table
ext = path.splitext(input_count_table)[1]
if ext == ".gz":
count_table_fh = gzip.open(input_count_table, "rb")
else:
count_table_fh = open(input_count_table, "U")
if opts.load_precalc_file_in_biom:
count_table = load_table(count_table_fh)
else:
count_table = convert_precalc_to_biom(count_table_fh, ids_to_load)
# Need to only keep data relevant to our otu list
ids = []
for x in otu_table.iter(axis="observation"):
ids.append(str(x[1]))
ob_id = count_table.ids(axis="observation")[0]
filtered_otus = []
filtered_values = []
for x in ids:
if count_table.exists(x, axis="sample"):
filtered_otus.append(x)
filtered_values.append(otu_table.data(x, axis="observation"))
filtered_otu_table = Table(filtered_values, filtered_otus, otu_table.ids())
copy_numbers_filtered = {}
for x in filtered_otus:
value = count_table.get_value_by_ids(ob_id, x)
try:
# data can be floats so round them and make them integers
value = int(round(float(value)))
except ValueError:
raise ValueError, "Invalid type passed as copy number for OTU ID %s. Must be int-able." % (value)
if value < 1:
raise ValueError, "Copy numbers must be greater than or equal to 1."
copy_numbers_filtered[x] = {opts.metadata_identifer: value}
filtered_otu_table.add_metadata(copy_numbers_filtered, axis="observation")
def metadata_norm(v, i, md):
return v / float(md[opts.metadata_identifer])
normalized_table = filtered_otu_table.transform(metadata_norm, axis="observation")
# move Observation Metadata from original to filtered OTU table
normalized_table = transfer_observation_metadata(otu_table, normalized_table, "observation")
make_output_dir_for_file(opts.output_otu_fp)
write_biom_table(normalized_table, opts.output_otu_fp)