Skip to content

Commit

Permalink
BUG: Fix missing index in summarize (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clockwork-Rat authored Feb 27, 2024
1 parent 0b14bd9 commit 9c79fab
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion q2_feature_table/_summarize/_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def summarize(output_dir: str, table: biom.Table,
sample_frequencies.sort_values(inplace=True, ascending=False)

sample_frequencies_json = pd.Series(["{:,}".format(int(x)) for x in
sample_frequencies])
sample_frequencies],
index=sample_frequencies.index)

feature_frequencies.sort_values(inplace=True, ascending=False)

Expand Down
20 changes: 20 additions & 0 deletions q2_feature_table/tests/test_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
from unittest import TestCase, main
import tempfile
import re
import json

import skbio
import biom
Expand Down Expand Up @@ -383,6 +385,24 @@ def test_basic(self):
index_fp = os.path.join(output_dir, 'index.html')
self.assertTrue(os.path.exists(index_fp))

sample_frequency_fp = os.path.join(output_dir,
'sample-frequency-detail.html')
self.assertTrue(os.path.exists(sample_frequency_fp))

rx = (r'<script id="table-data" type="application/json">' +
r'\n.*[^}]*.*\n</script>')

with open(sample_frequency_fp) as fi:
text = fi.read()
tbl_rx = re.compile(rx)
tbl = tbl_rx.findall(text)[0].split('\n')[1].strip()

sample_ids = json.loads(tbl).keys()

self.assertTrue('S1' in sample_ids)
self.assertTrue('S2' in sample_ids)
self.assertTrue('S3' in sample_ids)

def test_frequency_ranges_are_zero(self):
table = biom.Table(np.array([[25, 25, 25], [25, 25, 25]]),
['O1', 'O2'],
Expand Down

0 comments on commit 9c79fab

Please sign in to comment.