Skip to content

Commit

Permalink
Merge pull request #176 from AmpliconSuite/issue_170
Browse files Browse the repository at this point in the history
Issue 170
  • Loading branch information
liefeld authored Aug 16, 2023
2 parents 354a28d + 09fbc33 commit da7eef2
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 97 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pyvenv.cfg
/ampliconenv
# pycharm IDE
.idea/
tmp/
tmp/
.env
11 changes: 6 additions & 5 deletions caper/caper/StackedBarChart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import defaultdict
import logging
import time

import pandas as pd
Expand All @@ -25,14 +26,14 @@ def StackedBarChart(sample, fa_cmap):
df2.loc[len(df2)] = [x, "None", 0]

class_count_per_sample = defaultdict(lambda: defaultdict(int))
for _, row in df2.iterrows():
for _, row in df2.iterrows(): # 1 loop
class_count_per_sample[row['Sample_name']][row['Classification']] = row['Count']

# df2['Sample_name_trunc'] = df2['Sample_name'].apply(lambda x: x[0:10] + "..." if len(x) > 10 else x)
cc_tuples = {x: [-y[c] for c in classes] for x, y in class_count_per_sample.items()}
sort_col = [(corder[row['Classification']], cc_tuples[row['Sample_name']], row['Sample_name']) for _, row in df2.iterrows()]
cc_tuples = {x: [-y[c] for c in classes] for x, y in class_count_per_sample.items()}
sort_col = [(corder[row['Classification']], cc_tuples[row['Sample_name']], row['Sample_name']) for _, row in df2.iterrows()] # 1 loop
df2['sort_order_col'] = sort_col
df2.sort_values(inplace=True, by=['sort_order_col'])
df2.sort_values(inplace=True, by=['sort_order_col']) # 1 loop
ordered_name_set = df2['Sample_name'].unique()

if len(df2['Sample_name']) < 10:
Expand Down Expand Up @@ -68,6 +69,6 @@ def StackedBarChart(sample, fa_cmap):

end_time = time.time()
elapsed_time = end_time - start_time
print(f"Created project barchart plot in {elapsed_time} seconds")
logging.info(f"Created project barchart plot in {elapsed_time} seconds")
return fig.to_html(full_html=False, config={'displayModeBar': ['True']}, #'modeBarButtonsToRemove': ['zoom'],
div_id="project_bar_plotly_div")
Loading

0 comments on commit da7eef2

Please sign in to comment.