Skip to content

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
gregcaporaso committed Jun 16, 2020
1 parent 298f430 commit 6d1d733
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions q2_types/feature_data/tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,55 @@ def test_aligned_dnafasta_format_to_metadata(self):

self.assertEqual(exp, obs)

def test_aligned_dnafasta_format_to_series(self):
_, obs = self.transform_format(AlignedDNAFASTAFormat, pd.Series,
'aligned-dna-sequences.fasta')

obs = obs.astype(str)

index = pd.Index(['SEQUENCE1', 'SEQUENCE2'])
exp = pd.Series(['------------------------ACGTACGTACGTACGTACGTAC'
'GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT',
'ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTAC'
'GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT'],
index=index, dtype=object)

assert_series_equal(exp, obs)

def test_series_to_aligned_dnafasta_format(self):
transformer = self.get_transformer(pd.Series, AlignedDNAFASTAFormat)

index = pd.Index(['SEQUENCE1', 'SEQUENCE2'])
input = pd.Series(['------------------------ACGTACGTACGTACGTACGTAC'
'GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT',
'ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTAC'
'GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT'],
index=index, dtype=object)

obs = transformer(input)

self.assertIsInstance(obs, AlignedDNAFASTAFormat)

obs_lines = list(open(str(obs)))
self.assertEqual(obs_lines[0], '>SEQUENCE1\n')
self.assertEqual(obs_lines[1],
'------------------------ACGTACGTACGTACGTACGTAC'
'GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT\n')
self.assertEqual(obs_lines[2], '>SEQUENCE2\n')
self.assertEqual(obs_lines[3],
'ACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGTAC'
'GTACGTACGTACGTACGTACGTACGTACGTACGTACGTACGT\n')

def test_aligned_dna_fasta_format_to_dna_iterator(self):
input, obs = self.transform_format(
AlignedDNAFASTAFormat, DNAIterator,
filename='aligned-dna-sequences.fasta')

exp = skbio.read(str(input), format='fasta', constructor=skbio.DNA)

for observed, expected in zip(obs, exp):
self.assertEqual(observed, expected)


class TestDifferentialTransformer(TestPluginBase):
package = 'q2_types.feature_data.tests'
Expand Down

0 comments on commit 6d1d733

Please sign in to comment.