当前位置: 首页>>代码示例>>Python>>正文


Python format.format_biom_table函数代码示例

本文整理汇总了Python中qiime.format.format_biom_table函数的典型用法代码示例。如果您正苦于以下问题:Python format_biom_table函数的具体用法?Python format_biom_table怎么用?Python format_biom_table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了format_biom_table函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: equalize_tables_at_rarefaction_point

def equalize_tables_at_rarefaction_point(otu_table_p,name_otu_table,reference_table_p,name_reference_table,seq_number,output_p):

	sample_de_novo = subset_samples_by_seq_number(biom_stats(reference_table_p),seq_number)
	sample_ref = subset_samples_by_seq_number(biom_stats(otu_table_p),seq_number)
	common_sample_ids = sample_de_novo.intersection(sample_ref)


	#filtering from otu table 
	new_otu_table = filter_samples(otu_table_p,common_sample_ids,0,np.inf)
	new_reference_table = filter_samples(reference_table_p,common_sample_ids,0,np.inf)
	
	doc1 = open(output_p+"/"+name_otu_table.replace("/","_")+"_equalized_"+str(seq_number)+'.biom',"w")
	doc1.write(format_biom_table(new_otu_table))
	doc1.close()



	doc2 = open(output_p+"/"+name_reference_table.replace("/","_")+"_equalized_"+str(seq_number)+'.biom',"w")
	doc2.write(format_biom_table(new_reference_table))
	doc2.close()

	print " \nPercentage of Samples  : {}/{} , {}\n".format(
															len(new_otu_table.SampleIds) ,
															len(otu_table_p.SampleIds) ,
															(len(new_otu_table.SampleIds)/len(otu_table_p.SampleIds)) * 100
															)


	return
开发者ID:maxrbc,项目名称:daedalus,代码行数:29,代码来源:utils.py

示例2: setUp

    def setUp(self):
        """Define some test data."""
        self.qiime_config = load_qiime_config()
        self.dirs_to_remove = []

        self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/'
        if not exists(self.tmp_dir):
            makedirs(self.tmp_dir)
            # if test creates the temp dir, also remove it
            self.dirs_to_remove.append(self.tmp_dir)

        self.otu_table1 = table_factory(data=array([[2, 0, 0, 1],
                                                   [1, 1, 1, 1],
                                                   [0, 0, 0, 0]]).T,
                                        sample_ids=list('XYZ'),
                                        observation_ids=list('abcd'),
                                        constructor=DenseOTUTable)
        fd, self.otu_table1_fp = mkstemp(dir=self.tmp_dir,
                                              prefix='alpha_diversity_tests',
                                              suffix='.biom')
        close(fd)
        open(self.otu_table1_fp, 'w').write(
            format_biom_table(self.otu_table1))

        self.otu_table2 = table_factory(data=array([[2, 0, 0, 1],
                                                   [1, 1, 1, 1],
                                                   [0, 0, 0, 0]]).T,
                                        sample_ids=list('XYZ'),
                                        observation_ids=['a', 'b', 'c', 'd_'],
                                        constructor=DenseOTUTable)
        fd, self.otu_table2_fp = mkstemp(dir=self.tmp_dir,
                                              prefix='alpha_diversity_tests',
                                              suffix='.biom')
        close(fd)
        open(self.otu_table2_fp, 'w').write(
            format_biom_table(self.otu_table2))

        self.single_sample_otu_table = table_factory(
            data=array([[2, 0, 0, 1]]).T,
            sample_ids=list('X'),
            observation_ids=list(
                'abcd'),
            constructor=DenseOTUTable)
        fd, self.single_sample_otu_table_fp = mkstemp(
            dir=self.tmp_dir,
            prefix='alpha_diversity_tests',
            suffix='.biom')
        close(fd)
        open(self.single_sample_otu_table_fp, 'w').write(
            format_biom_table(self.single_sample_otu_table))

        self.tree1 = parse_newick('((a:2,b:3):2,(c:1,d:2):7);')
        self.tree2 = parse_newick("((a:2,'b':3):2,(c:1,'d_':2):7);")

        self.files_to_remove = [self.otu_table1_fp, self.otu_table2_fp,
                                self.single_sample_otu_table_fp]
开发者ID:Bonder-MJ,项目名称:qiime,代码行数:56,代码来源:test_alpha_diversity.py

示例3: setUp

    def setUp(self):
        self.qiime_config = load_qiime_config()
        self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/'

        self.l19_data = numpy.array([
            [7, 1, 0, 0, 0, 0, 0, 0, 0],
            [4, 2, 0, 0, 0, 1, 0, 0, 0],
            [2, 4, 0, 0, 0, 1, 0, 0, 0],
            [1, 7, 0, 0, 0, 0, 0, 0, 0],
            [0, 8, 0, 0, 0, 0, 0, 0, 0],
            [0, 7, 1, 0, 0, 0, 0, 0, 0],
            [0, 4, 2, 0, 0, 0, 2, 0, 0],
            [0, 2, 4, 0, 0, 0, 1, 0, 0],
            [0, 1, 7, 0, 0, 0, 0, 0, 0],
            [0, 0, 8, 0, 0, 0, 0, 0, 0],
            [0, 0, 7, 1, 0, 0, 0, 0, 0],
            [0, 0, 4, 2, 0, 0, 0, 3, 0],
            [0, 0, 2, 4, 0, 0, 0, 1, 0],
            [0, 0, 1, 7, 0, 0, 0, 0, 0],
            [0, 0, 0, 8, 0, 0, 0, 0, 0],
            [0, 0, 0, 7, 1, 0, 0, 0, 0],
            [0, 0, 0, 4, 2, 0, 0, 0, 4],
            [0, 0, 0, 2, 4, 0, 0, 0, 1],
            [0, 0, 0, 1, 7, 0, 0, 0, 0]
        ])
        self.l19_sample_names = [
            'sam1', 'sam2', 'sam3', 'sam4', 'sam5', 'sam6',
            'sam7', 'sam8', 'sam9', 'sam_middle', 'sam11', 'sam12', 'sam13',
            'sam14', 'sam15', 'sam16', 'sam17', 'sam18', 'sam19']
        self.l19_taxon_names = ['tax1', 'tax2', 'tax3', 'tax4', 'endbigtaxon',
                                'tax6', 'tax7', 'tax8', 'tax9']
        self.l19_taxon_names_w_underscore = ['ta_x1', 'tax2', 'tax3', 'tax4',
                                             'endbigtaxon', 'tax6', 'tax7', 'tax8', 'tax9']

        l19_str = format_biom_table(DenseOTUTable(self.l19_data.T,
                                                  self.l19_sample_names,
                                                  self.l19_taxon_names))
        fd, self.l19_fp = mkstemp(dir=self.tmp_dir,
                                prefix='test_bdiv_otu_table', suffix='.blom')
        close(fd)
        open(self.l19_fp, 'w').write(l19_str)

        l19_str_w_underscore = format_biom_table(DenseOTUTable(self.l19_data.T,
                                                               self.l19_sample_names,
                                                               self.l19_taxon_names_w_underscore))
        fd, self.l19_str_w_underscore_fp = mkstemp(dir=self.tmp_dir,
                                                  prefix='test_bdiv_otu_table', suffix='.blom')
        close(fd)
        open(self.l19_str_w_underscore_fp, 'w').write(l19_str_w_underscore)

        self.l19_tree_str = '((((tax7:0.1,tax3:0.2):.98,tax8:.3, tax4:.3):.4,\
 ((tax1:0.3, tax6:.09):0.43,tax2:0.4):0.5):.2, (tax9:0.3, endbigtaxon:.08));'
        self.l19_tree = parse_newick(self.l19_tree_str, PhyloNode)

        self.files_to_remove = [self.l19_fp, self.l19_str_w_underscore_fp]
        self.folders_to_remove = []
开发者ID:ajaykshatriya,项目名称:qiime,代码行数:56,代码来源:test_beta_diversity.py

示例4: test_split_otu_table_on_sample_metadata_extra_mapping_entries

    def test_split_otu_table_on_sample_metadata_extra_mapping_entries(self):
        """ split_otu_table_on_sample_metadata functions as expected with extra mapping data """
        actual = list(split_otu_table_on_sample_metadata(self.otu_table_f1,
                                                         self.mapping_f2,
                                                         "Treatment"))

        actual = [(id_, parse_biom_table(e)) for id_, e in actual]
        exp = [(id_, parse_biom_table(e)) for id_, e in otu_table_exp1]

        actual.sort()
        exp.sort()

        for a, e in zip(actual, exp):
            self.assertEqual(a, e, "OTU tables are not equal:\n%s\n%s" %
                             (format_biom_table(a[1]), format_biom_table(e[1])))
开发者ID:MicrobiomeResearch,项目名称:qiime,代码行数:15,代码来源:test_split.py

示例5: main

def main():
    option_parser, opts, args =\
      parse_command_line_parameters(**script_info)

    otu_table_data = parse_biom_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:
        result = sort_otu_table(otu_table_data,
                        natsort_case_insensitive(otu_table_data.SampleIds))
    
    # format and write the otu table
    result_str = format_biom_table(result)
    of = open(opts.output_fp,'w')
    of.write(result_str)
    of.close()
开发者ID:rob-knight,项目名称:qiime,代码行数:27,代码来源:sort_otu_table.py

示例6: make_otu_table

def make_otu_table(otu_map_f,
                   otu_to_taxonomy=None,
                   delim='_',
                   table_id=None,
                   sample_metadata=None,
                   constructor=SparseOTUTable):

    data, sample_ids, otu_ids = parse_otu_map(otu_map_f, delim)

    if otu_to_taxonomy is not None:
        otu_metadata = []
        for o in otu_ids:
            try:
                otu_metadata.append({'taxonomy': otu_to_taxonomy[o]})
            except KeyError:
                otu_metadata.append({'taxonomy': ["None"]})
    else:
        otu_metadata = None

    if sample_metadata is not None:
        raise NotImplementedError(
            "Passing of sample metadata to make_otu_table is not currently supported.")
    try:
        otu_table = table_factory(data, sample_ids, otu_ids,
                                  sample_metadata=sample_metadata,
                                  observation_metadata=otu_metadata,
                                  table_id=table_id,
                                  constructor=constructor,
                                  dtype=int)
    except ValueError as e:
        raise ValueError("Couldn't create OTU table. Is your OTU map empty?"
                         " Original error message: %s" % (str(e)))
    return format_biom_table(otu_table)
开发者ID:Bonder-MJ,项目名称:qiime,代码行数:33,代码来源:make_otu_table.py

示例7: main

def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)
    
    labels = opts.labels.split(',')
    if opts.all_strings:
        process_fs = [str] * len(labels)
        observation_metadata = parse_taxonomy_to_otu_metadata(\
                            open(opts.taxonomy_fp,'U'),labels=labels,process_fs=process_fs)
    else:
        observation_metadata = parse_taxonomy_to_otu_metadata(\
                            open(opts.taxonomy_fp,'U'),labels=labels)
    

    otu_table = parse_biom_table(open(opts.input_fp,'U'))
    
    if otu_table.ObservationMetadata != None:
        # if there is already metadata associated with the 
        # observations, confirm that none of the metadata names
        # are already present
        existing_keys = otu_table.ObservationMetadata[0].keys()
        for label in labels:
            if label in existing_keys:
                option_parser.error(\
                 "%s is already an observation metadata field." 
                 " Can't add it, so nothing is being added." % label)
    
    otu_table.addObservationMetadata(observation_metadata)
    
    output_f = open(opts.output_fp,'w')
    output_f.write(format_biom_table(otu_table))
    output_f.close()
开发者ID:DDomogala3,项目名称:qiime,代码行数:31,代码来源:add_taxa.py

示例8: main

def main():
    option_parser, opts, args =\
        parse_command_line_parameters(**script_info)

    input_table = parse_biom_table(open(opts.input_otu_table_fp, 'U'))
    output_table_f = open(opts.output_otu_table_fp, 'w')
    metadata_field = opts.metadata_field
    positive_taxa = opts.positive_taxa
    negative_taxa = opts.negative_taxa

    if positive_taxa is not None:
        positive_taxa = positive_taxa.split(',')
    else:
        positive_taxa = None

    if negative_taxa is not None:
        negative_taxa = negative_taxa.split(',')
    else:
        negative_taxa = None

    filter_fn = get_otu_ids_from_taxonomy_f(
        positive_taxa,
        negative_taxa,
        metadata_field)
    output_table = input_table.filterObservations(filter_fn)
    output_table_f.write(format_biom_table(output_table))
    output_table_f.close()
开发者ID:Bonder-MJ,项目名称:qiime,代码行数:27,代码来源:filter_taxa_from_otu_table.py

示例9: generate_full_otu_table

def generate_full_otu_table(study, study_input_dir, zip_fname, files_to_remove,
                            biom_files,output_dir):
    """ Merge OTU tables """
    
    master = parse_biom_table(open(biom_files[0],'U'))
    # only merge if there is more than 1 biom file
    if len(biom_files) > 1:
        for input_fp in biom_files[1:]:
            master = master.merge(parse_biom_table(open(input_fp,'U')))
        
    # write full biom-table
    full_biom_table_fname='study_%s_closed_reference_otu_table.biom' % \
                                                              (str(study))
    full_biom_table_fp=join(output_dir,full_biom_table_fname)
    # add to list of files to remove
    files_to_remove.append(full_biom_table_fp)
    
    biom_f = open(join(full_biom_table_fp),'w')
    biom_f.write(format_biom_table(master))
    biom_f.close()
    
    # zip the full biom-table file
    #cmd_call='cd %s; tar rzvf %s %s' % (study_input_dir,zip_fname,
    #                               full_biom_table_fname)
    #system(cmd_call)
    
    return files_to_remove
开发者ID:ElDeveloper,项目名称:qiime_web_app,代码行数:27,代码来源:collate_per_study_seqs_lib.py

示例10: split_otu_table_on_taxonomy_to_files

def split_otu_table_on_taxonomy_to_files(otu_table_fp,
                                         level,
                                         output_dir,
                                         md_identifier='taxonomy',
                                         md_processor=process_md_as_list):
    """ Split OTU table by taxonomic level, writing otu tables to output dir
    """
    results = []
    otu_table = parse_biom_table(open(otu_table_fp,'U'))
    create_dir(output_dir)
    
    def split_f(obs_md):
        try:
            result = md_processor(obs_md,md_identifier,level)
        except KeyError:
            raise KeyError,\
             "Metadata identifier (%s) is not associated with all (or any) observerations. You can modify the key with the md_identifier parameter." % md_identifier
        except TypeError:
            raise TypeError,\
             "Can't correctly process the metadata string. If your input file was generated from QIIME 1.4.0 or earlier you may need to pass --md_as_string."
        except AttributeError:
            raise AttributeError,\
             "Metadata category not found. If your input file was generated from QIIME 1.4.0 or earlier you may need to pass --md_identifier \"Consensus Lineage\"."
    
        return result
    
    for bin, sub_otu_table in otu_table.binObservationsByMetadata(split_f):
        output_fp = '%s/otu_table_%s.biom' % (output_dir,bin)
        output_f = open(output_fp,'w')
        output_f.write(format_biom_table(sub_otu_table))
        output_f.close()
        results.append(output_fp)
    return results
开发者ID:Jorge-C,项目名称:qiime,代码行数:33,代码来源:split_otu_table_by_taxonomy.py

示例11: _write_rarefaction

 def _write_rarefaction(self, fname, sub_otu_table):
     """ depth and rep can be numbers or strings
     """
     if sub_otu_table.isEmpty():
         return
     f = open(fname, 'w')
     f.write(format_biom_table(sub_otu_table))
     f.close()
开发者ID:rob-knight,项目名称:qiime,代码行数:8,代码来源:rarefaction.py

示例12: setUp

    def setUp(self):
        """Define some test data."""
        self.qiime_config = load_qiime_config()
        self.dirs_to_remove = []

        self.tmp_dir = self.qiime_config["temp_dir"] or "/tmp/"
        if not exists(self.tmp_dir):
            makedirs(self.tmp_dir)
            # if test creates the temp dir, also remove it
            self.dirs_to_remove.append(self.tmp_dir)

        self.otu_table1 = table_factory(
            data=array([[2, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 0]]).T,
            sample_ids=list("XYZ"),
            observation_ids=list("abcd"),
            constructor=DenseOTUTable,
        )
        self.otu_table1_fp = get_tmp_filename(
            tmp_dir=self.tmp_dir, prefix="alpha_diversity_tests", suffix=".biom", result_constructor=str
        )
        open(self.otu_table1_fp, "w").write(format_biom_table(self.otu_table1))

        self.otu_table2 = table_factory(
            data=array([[2, 0, 0, 1], [1, 1, 1, 1], [0, 0, 0, 0]]).T,
            sample_ids=list("XYZ"),
            observation_ids=["a", "b", "c", "d_"],
            constructor=DenseOTUTable,
        )
        self.otu_table2_fp = get_tmp_filename(
            tmp_dir=self.tmp_dir, prefix="alpha_diversity_tests", suffix=".biom", result_constructor=str
        )
        open(self.otu_table2_fp, "w").write(format_biom_table(self.otu_table2))

        self.single_sample_otu_table = table_factory(
            data=array([[2, 0, 0, 1]]).T, sample_ids=list("X"), observation_ids=list("abcd"), constructor=DenseOTUTable
        )
        self.single_sample_otu_table_fp = get_tmp_filename(
            tmp_dir=self.tmp_dir, prefix="alpha_diversity_tests", suffix=".biom", result_constructor=str
        )
        open(self.single_sample_otu_table_fp, "w").write(format_biom_table(self.single_sample_otu_table))

        self.tree1 = parse_newick("((a:2,b:3):2,(c:1,d:2):7);")
        self.tree2 = parse_newick("((a:2,'b':3):2,(c:1,'d_':2):7);")

        self.files_to_remove = [self.otu_table1_fp, self.otu_table2_fp, self.single_sample_otu_table_fp]
开发者ID:ranjit58,项目名称:qiime,代码行数:45,代码来源:test_alpha_diversity.py

示例13: main

def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    sample_mapping_fp = opts.sample_mapping_fp
    output_fp = opts.output_fp
    verbose = opts.verbose
    
    sample_mapping_file = open(sample_mapping_fp, 'U')
    result = sample_mapping_to_biom_table(sample_mapping_file)
    open(output_fp, 'w').write(format_biom_table(result))
开发者ID:Jorge-C,项目名称:qiime,代码行数:10,代码来源:convert_unifrac_sample_mapping_to_otu_table.py

示例14: test_split_otu_table_on_sample_metadata

 def test_split_otu_table_on_sample_metadata(self):
     """ split_otu_table_on_sample_metadata functions as expected with valid input """
     actual = list(split_otu_table_on_sample_metadata(self.otu_table_f1,
                                                      self.mapping_f1,
                                                      "Treatment"))
     for id_, e in actual:
         try:
             parse_biom_table(e)
         except:
             print e
     actual = [(id_,parse_biom_table(e)) for id_, e in actual]
     exp = [(id_,parse_biom_table(e)) for id_, e in otu_table_exp1]
     
     actual.sort()
     exp.sort()
     
     for a,e in zip(actual,exp):
         self.assertEqual(a,e,"OTU tables are not equal:\n%s\n%s" % \
          (format_biom_table(a[1]),format_biom_table(e[1])))
开发者ID:Jorge-C,项目名称:qiime,代码行数:19,代码来源:test_split.py

示例15: setUp

    def setUp(self):

        self.qiime_config = load_qiime_config()
        self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/'

        self.otu_table_data = numpy.array([[2,1,0],
                                      [0,5,0],
                                      [0,3,0],
                                      [1,2,0]])
        self.sample_names = list('YXZ')
        self.taxon_names = list('bacd')
        self.otu_metadata = [{'domain':'Archaea'},
                          {'domain':'Bacteria'},
                          {'domain':'Bacteria'},
                          {'domain':'Bacteria'}]


        self.otu_table = table_factory(self.otu_table_data,
                                        self.sample_names,
                                        self.taxon_names)
        self.otu_table_meta = table_factory(self.otu_table_data,
          self.sample_names, self.taxon_names, 
          observation_metadata=self.otu_metadata)

        self.otu_table_str = format_biom_table(self.otu_table)
        self.otu_table_meta_str = format_biom_table(self.otu_table_meta)

        self.otu_table_fp = get_tmp_filename(tmp_dir=self.tmp_dir,
          prefix='test_rarefaction',suffix='.biom')
        self.otu_table_meta_fp = get_tmp_filename(tmp_dir=self.tmp_dir,
          prefix='test_rarefaction',suffix='.biom')

        self.rare_dir = get_tmp_filename(tmp_dir=self.tmp_dir,
         prefix='test_rarefaction_dir',suffix='',result_constructor=str)
        os.mkdir(self.rare_dir)

        open(self.otu_table_fp,'w').write(self.otu_table_str)
        open(self.otu_table_meta_fp,'w').write(self.otu_table_meta_str)


        self._paths_to_clean_up=[self.otu_table_fp,self.otu_table_meta_fp]
        self._dirs_to_clean_up=[self.rare_dir]
开发者ID:DDomogala3,项目名称:qiime,代码行数:42,代码来源:test_rarefaction.py


注:本文中的qiime.format.format_biom_table函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。