• BIOM Table-codes


    import numpy

    from biom.table import Table

    ============================================================================================================

    # 10*4 matrix, [0, 39]

    data = numpy.arange(40).reshape(10, 4)

    sample_ids = ['S%d' % i for i in range(4)]

    observ_ids = ['O%d' % i for i in range(10)]

    sample_metadata = [{'environment': 'A'}, {'environment': 'B'},

    {'environment': 'A'}, {'environment': 'B'}]

    observ_metadata = [{'taxonomy': ['Bacteria', 'Firmicutes']},

    {'taxonomy': ['Bacteria', 'Firmicutes']},

    {'taxonomy': ['Bacteria', 'Proteobacteria']},

    {'taxonomy': ['Bacteria', 'Proteobacteria']},

    {'taxonomy': ['Bacteria', 'Proteobacteria']},

    {'taxonomy': ['Bacteria', 'Bacteroidetes']},

    {'taxonomy': ['Bacteria', 'Bacteroidetes']},

    {'taxonomy': ['Bacteria', 'Firmicutes']},

    {'taxonomy': ['Bacteria', 'Firmicutes']},

    {'taxonomy': ['Bacteria', 'Firmicutes']}]

    # construct table

    table = Table(data, observ_ids, sample_ids, observ_metadata, sample_metadata, table_id='myTestTable')

    # use add_metadata. This is ADD, NOT CONSTRUCT!

    #table.add_metadata(sample_metadata, axis='sample')

    # print info of table

    table

    print(table)


    # print column names

    print(table.ids())

    print(table.ids(axis='sample'))

    # print row names

    print(table.ids(axis='observation'))

    # print number of non-zero entries. Now it’s 39.

    print(table.nnz)

    ============================================================================================================

    data = numpy.asarray([[2, 0], [6, 1]])

    table = Table(data, ['O1', 'O2'], ['S1', 'S2'])

    # normalize by ‘sample’(column)

    new_table = table.norm(inplace=False)


    # normalize by row

    new_table = table.norm(axis='observation', inplace=False)

    # if inplace=True, table will change too. Now it stay unchanged. If set table1 = table before norm, and change table1 now, then table will change, too(shallow copy).

    ============================================================================================================

    # filter with a function

    filter_f = lambda values, id_, md: md['environment'] == 'A'

    env_a = normed.filter(filter_f, axis='sample', inplace=False)

    ============================================================================================================

    # divide by 'environment'

    part_f = lambda id_, md: md['environment']
    env_tables = table.partition(part_f, axis='sample')

    # make a sum
    for partition, env_table in env_tables:

        print(partition, env_table.sum('sample'))

    ============================================================================================================

    # add-metadata

    ============================================================================================================

    biom convert -i table.biom -o table.from_biom_w_consensuslineage.txt --to-tsv --header-key taxonomy --output-metadata-id "ConsensusLineage"

    # 1. convert .biom to .txt

    # special header-key

    biom convert -i otu_table.biom -o otu_table.txt --to-tsv --header-key taxonomy

    # 2. fix in excel

    # 3. convert back

    biom convert -i otu_table.txt -o new_otu_table.biom --to-hdf5 --table-type="OTU table" --process-obs-metadata taxonomy

    ============================================================================================================

    biom summarize-table -i INPUT.biom --qualitative -o OUTPUT.txt

  • 相关阅读:
    蜗牛爱课 -- iOS 设计模式之模板模式
    蜗牛爱课- iOS中plist的创建,数据写入与读取
    蜗牛爱课 - iOS7、8模态半透明弹出框
    UIScrollView的属性总结
    简述UITextField的属性和用法
    IOS开发 统计XCODE 代码行数
    当xcode里点运行出现treating unicode character as whites
    Your build settings specify a provisioning profile with the UUID, no such provisioning profile was found的解决方案
    CocoaPods安装和使用教程
    蜗牛爱课- CGAffineTransformMakeRotation 实现一张图片的自动旋转
  • 原文地址:https://www.cnblogs.com/pxy7896/p/6386892.html
Copyright © 2020-2023  润新知