예제 #1
0
    def test_split_tax(self):
        """split_tax: Splits the tax string on comma and semicolon"""

        exp1 = ['"Root', 'Bacteria"']
        exp2 = ['Root', 'Archaea']

        obs1 = split_tax(self.taxon1)
        obs2 = split_tax(self.taxon2)

        self.assertEqual(obs1, exp1)
        self.assertEqual(obs2, exp2)
    def test_split_tax(self):
        """split_tax: Splits the tax string on comma and semicolon"""

        exp1=['"Root','Bacteria"']
        exp2=['Root','Archaea']
        
        obs1=split_tax(self.taxon1)
        obs2=split_tax(self.taxon2)
        
        self.assertEqual(obs1,exp1)
        self.assertEqual(obs2,exp2)
예제 #3
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)
    
    # process options (was originally process_options())
    filepath=opts.otu_table_fp
    filename=filepath.strip().split('/')[-1]
    filename=filename.split('.')[0]

    params={}
    params['otu_file'] = opts.otu_table_fp
    params['min_otu_count'] = opts.min_count
    params['min_otu_samples'] = opts.min_samples
    params['seqs_per_sample']=opts.seqs_per_sample
    seqs_per_sample=params['seqs_per_sample']
    otu_file=open(params['otu_file'], 'U')

    filtered_table_path=open(opts.output_otu_table_fp, 'w')
                                
    if opts.include_taxonomy:
        included_taxa = set(map(strip, split_tax(opts.include_taxonomy)))
    else:
        included_taxa = set()

    if opts.exclude_taxonomy:
        excluded_taxa = set(map(strip, split_tax(opts.exclude_taxonomy)))
    else:
        excluded_taxa=set()

    params['included_taxa']=included_taxa
    params['excluded_taxa']=excluded_taxa

    seq_sample_output=[]
    if seqs_per_sample and params['min_otu_count']==1 and \
            params['min_otu_samples']==2 and opts.include_taxonomy=='' and \
            opts.exclude_taxonomy=='':
        otu_file2=otu_file.readlines()
        filtered_table = _filter_table_samples(otu_file2,seqs_per_sample)
        filtered_table_path.write(filtered_table)
        filtered_table_path.close()
    elif seqs_per_sample and (params['min_otu_count']<>1 or \
            params['min_otu_samples']<>2 or opts.include_taxonomy<>'' or \
            opts.exclude_taxonomy<>''):
        raise ValueError, 'You cannot supply seqs per sample with other filtering options. These features are mutually exclusive.'
    else:
        filter_table(params,filtered_table_path,otu_file)