def test_directory_format_wrong_filename(self): filepath = self.get_data_path('qiime1-demux-format/short.fna') shutil.copy(filepath, self.temp_dir.name) with self.assertRaisesRegex(ValidationError, r'QIIME1DemuxDirFmt.*seqs\.fna'): QIIME1DemuxDirFmt(self.temp_dir.name, mode='r').validate()
def test_directory_format_validate_negative(self): for file in self.negatives: filepath = self.get_data_path('qiime1-demux-format/%s' % file) shutil.copy(filepath, os.path.join(self.temp_dir.name, 'seqs.fna')) with self.assertRaisesRegex(ValidationError, 'QIIME1DemuxFormat'): QIIME1DemuxDirFmt(self.temp_dir.name, mode='r').validate()
def test_dereplicate_sequences_prefix(self): input_sequences_fp = self.get_data_path('seqs-1') input_sequences = QIIME1DemuxDirFmt(input_sequences_fp, 'r') exp_table = biom.Table(np.array([[2, 2], [2, 0]]), ['4574b947a0159c0da35a1f30f989681a1d9f64ef', '16a1263bde4f2f99422630d1bb87935c4236d1ba'], ['s2', 'sample1']) with redirected_stdio(stderr=os.devnull): obs_table, obs_sequences = dereplicate_sequences( sequences=input_sequences, derep_prefix=True) # order of identifiers is important for biom.Table equality obs_table = \ obs_table.sort_order(exp_table.ids(axis='observation'), axis='observation') self.assertEqual(obs_table, exp_table) # sequences are reverse-sorted by abundance in output obs_seqs = list(skbio.io.read(str(obs_sequences), constructor=skbio.DNA, format='fasta')) exp_seqs = [skbio.DNA('AAACGTTACGGTTAACTATACATGCAGAAGACTAATCGG', metadata={'id': ('4574b947a0159c0da35a1f30f' '989681a1d9f64ef'), 'description': 's2_1'}), skbio.DNA('ACGTACGTACGTACGTACGTACGTACGTACGTGCATGGTGCGACCG', metadata={'id': ('16a1263bde4f2f99422630d1bb' '87935c4236d1ba'), 'description': 's2_42'})] self.assertEqual(obs_seqs, exp_seqs)
def test_directory_format_validate_positive(self): for file in self.positives: filepath = self.get_data_path('qiime1-demux-format/%s' % file) shutil.copy(filepath, os.path.join(self.temp_dir.name, 'seqs.fna')) QIIME1DemuxDirFmt(self.temp_dir.name, mode='r').validate()