Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add formatting #295

Merged
merged 9 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions q2_feature_table/_summarize/_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def summarize(output_dir: str, table: biom.Table,

sample_summary, sample_frequencies = _frequency_summary(
table, axis='sample')

if number_of_samples > 1:

# Calculate the bin count, with a minimum of 5 bins
Expand Down Expand Up @@ -166,6 +167,10 @@ def summarize(output_dir: str, table: biom.Table,

feature_qualitative_data = _compute_qualitative_summary(table)
sample_frequencies.sort_values(inplace=True, ascending=False)

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

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

feature_frequencies = feature_frequencies.astype(int) \
Expand All @@ -190,7 +195,7 @@ def summarize(output_dir: str, table: biom.Table,

# Create a JSON object containing the Sample Frequencies to build the
# table in sample-frequency-detail.html
sample_frequencies_json = sample_frequencies.to_json()
sample_frequencies_json = sample_frequencies_json.to_json()

templates = [index, sample_frequency_template, feature_frequency_template]
context.update({'frequencies_list':
Expand Down Expand Up @@ -356,12 +361,21 @@ def _frequencies(table, axis):
return pd.Series(data=table.sum(axis=axis), index=table.ids(axis=axis))


def _frequency_summary(table, axis='sample'):
def _frequency_summary(table: biom.Table, axis='sample'):
frequencies = _frequencies(table, axis=axis)

summary = pd.Series([frequencies.min(), frequencies.quantile(0.25),
frequencies.median(), frequencies.quantile(0.75),
frequencies.max(), frequencies.mean()],
first = frequencies.quantile(0.25)
Clockwork-Rat marked this conversation as resolved.
Show resolved Hide resolved
third = frequencies.quantile(0.75)
_fst = round(first, 1)
_min = round(frequencies.min(), 1)
_thd = round(third, 1)
_med = round(frequencies.median(), 1)
_max = round(frequencies.max(), 1)
mean = round(frequencies.mean(), 1)

summary = pd.Series([_min, _fst,
_med, _thd,
_max, mean],
index=['Minimum frequency', '1st quartile',
'Median frequency', '3rd quartile',
'Maximum frequency', 'Mean frequency'])
Expand Down
6 changes: 2 additions & 4 deletions q2_feature_table/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@

plugin.visualizers.register_function(
function=q2_feature_table.summarize,
inputs={'table': FeatureTable[Frequency | RelativeFrequency |
PresenceAbsence]},
inputs={'table': FeatureTable[Frequency | PresenceAbsence]},
parameters={'sample_metadata': Metadata},
input_descriptions={'table': 'The feature table to be summarized.'},
parameter_descriptions={'sample_metadata': 'The sample metadata.'},
Expand Down Expand Up @@ -694,8 +693,7 @@

plugin.pipelines.register_function(
function=q2_feature_table.summarize_plus,
inputs={'table': FeatureTable[Frequency | RelativeFrequency |
PresenceAbsence]},
inputs={'table': FeatureTable[Frequency | PresenceAbsence]},
parameters={'metadata': Metadata},
outputs={'feature_frequencies': ImmutableMetadata,
'sample_frequencies': ImmutableMetadata,
Expand Down