def test_process_extract_samples(self): """process_extract_samples: parses the cmd line and determines which samples should be removed""" self.sample_to_extract='SampleA,SampleB' exp1={'0':'SampleA','1':'SampleB'} obs1=process_extract_samples(self.sample_to_extract) self.assertEqual(obs1,exp1)
def test_process_extract_samples(self): """process_extract_samples: parses the cmd line and determines which samples should be removed""" self.sample_to_extract = "SampleA,SampleB" exp1 = {"0": "SampleA", "1": "SampleB"} obs1 = process_extract_samples(self.sample_to_extract) self.assertEqual(obs1, exp1)
def main(): """opens files as necessary based on prefs""" option_parser, opts, args = parse_command_line_parameters(**script_info) data = {} fasta_file = opts.input_fasta_fp # load the input alignment data['aln'] = SequenceCollection.from_fasta_records( parse_fasta(open(fasta_file)), DNA) # Load the otu file otu_path = opts.otu_map_fp otu_f = open(otu_path, 'U') otus = fields_to_dict(otu_f) otu_f.close() data['otus'] = otus # Determine which which samples to extract from representative seqs # and from otus file if opts.samples_to_extract: prefs = process_extract_samples(opts.samples_to_extract) filepath = opts.input_fasta_fp filename = filepath.strip().split('/')[-1] filename = filename.split('.')[0] if opts.output_dir: if os.path.exists(opts.output_dir): dir_path = opts.output_dir else: try: os.mkdir(opts.output_dir) dir_path = opts.output_dir except OSError: pass else: dir_path = './' try: action = filter_samples except NameError: action = None # Place this outside try/except so we don't mask NameError in action if action: action(prefs, data, dir_path, filename)