Skip to content
Open
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
4 changes: 2 additions & 2 deletions .idea/Lexos.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 5 additions & 44 deletions lexos/models/bct_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,53 +175,14 @@ def _get_bootstrap_consensus_tree(self) -> Phylo:
cutoff=self._bct_option.cutoff
)

def _get_bootstrap_consensus_tree_plot(self) -> plt:
# Draw the consensus tree as a MatPlotLib object.
Phylo.draw(
self._get_bootstrap_consensus_tree(),
do_show=False,
branch_labels=lambda clade: "{0:.4f}\n".format(clade.branch_length)
if clade.branch_length is not None else ""
)

# Set labels for the plot.
plt.xlabel("Branch Length")
plt.ylabel("Documents")

# Hide the two unused border.
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)

# Extend x-axis to the right to fit longer labels.
x_left, x_right, y_low, y_high = plt.axis()
plt.axis((x_left, x_right * 1.25, y_low, y_high))

# Set graph size, title and tight layout.
plt.gcf().set_size_inches(
w=9.5,
h=(len(self._id_temp_label_map) * 0.3 + 1)
)
plt.title("Bootstrap Consensus Tree Result")
plt.gcf().tight_layout()

# Change line spacing
for text in plt.gca().texts:
text.set_linespacing(spacing=0.1)

return plt

def get_bootstrap_consensus_tree_plot_decoded(self) -> str:
def get_newick_consensus_tree(self) -> str:
"""Render the bootstrap consensus tree result and save it to images.

:return: The rendered BCT result file name.
"""
# Get the matplotlib plot for bootstrap consensus tree result.
bct_plot = self._get_bootstrap_consensus_tree_plot()

# Create a bytes IO image holder and save figure to it.
image_holder = BytesIO()
bct_plot.savefig(image_holder)
image_holder.seek(0)
consensus_tree_holder = StringIO()
consensus_tree = self._get_bootstrap_consensus_tree()
Phylo.write(consensus_tree, consensus_tree_holder, format="newick")

# Decode image to utf-8 string.
return base64.b64encode(b''.join(image_holder)).decode('utf-8')
return consensus_tree_holder.getvalue()
2 changes: 1 addition & 1 deletion lexos/models/dendro_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def extend_bottom_figure(self, figure: Figure) -> Figure:
for file_id in self._doc_term_matrix.index.values])

# Extend the bottom margin to fit all labels.
figure.layout.update({'margin': {'b': max_label_len * 4.5}})
figure.layout.update({'margin': {'b': max_label_len * 5}})
# Calculate the space right most label needs.
right_margin = len(figure.layout.xaxis.ticktext[-1]) * 4 \
if len(figure.layout.xaxis.ticktext[-1]) * 4 > 100 else 100
Expand Down
9 changes: 9 additions & 0 deletions lexos/static/js/phylotree.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lexos/static/js/scripts_bct.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function generateBCT () {
utility.sendAjaxRequest('/bct_analysis_result', form)
.done(
function (response) {
$('#bct-result').html(`<img src="data:image/png;base64,${response}">`)
$('#bct-result').html(response)
})
.fail(
function () {
Expand Down
6 changes: 5 additions & 1 deletion lexos/templates/bct_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@


{% block results %}
<div id="bct-result" class="row" style="text-align: center"></div>
<div id="var"></div>
<div class="row submit-button-row">
<div class="col-md-12 col-lg-12">
<input class="btn btn-success" id="get-bct" name="get-bct"
type="button" value="Get Bootstrap Consensus Tree"/>
</div>
<div class="col-md-12 col-lg-12">
{% include 'phylotree.html' %}
</div>
</div>
<div id="bct-result" class="row" style="text-align: center"></div>
{% endblock %}

{% block submit %}
Expand Down
Loading