Skip to content

Commit

Permalink
Merge pull request #169 from usegalaxy-au/fgenesh-rm-matrix-selection
Browse files Browse the repository at this point in the history
Remove selection from fgenesh matrix tree
  • Loading branch information
neoformit authored Nov 6, 2024
2 parents 858b78f + c394528 commit 0f0b34f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 44 deletions.
8 changes: 1 addition & 7 deletions webapp/home/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,14 @@ class FgeneshRequestForm(BaseAccessRequestForm):
"""Form to request AlphaFold access."""

RESOURCE_NAME = 'FGENESH++'
MAIL_SUCCESS_MESSAGE = (
"This request has been actioned by Galaxy Media Site and the user has"
" been assigned to the 'fgenesh' group on Galaxy AU. An admin should"
" ensure that the required matrices are installed before notifying"
" the user that the service is ready for use."
)
AUTO_ACTION = True

name = forms.CharField()
email = forms.EmailField(validators=[validators.institutional_email])
agree_terms = forms.BooleanField()
agree_acknowledge = forms.BooleanField()
research_description = forms.CharField(max_length=200, required=False)
research_topics = forms.CharField(max_length=200, required=False)
matrices = forms.MultipleChoiceField(choices=genematrix_tree.as_choices())

terms = {
'button_text': 'View terms',
Expand Down
36 changes: 22 additions & 14 deletions webapp/home/static/home/js/fgenesh-matrix-tree.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const SELECTION_ENABLED = false;

$(document).ready(function() {
setMatricesValue();
setTermsValue();
addNodeClickEvent();
// Add event handler to update "selected matrices" count
$('#taxonomy-tree input[type="checkbox"]').change(updateTreeSelection);

if (SELECTION_ENABLED) {
setMatricesValue();
// Add event handler to update "selected matrices" count
$('#taxonomy-tree input[type="checkbox"]').change(updateTreeSelection);
}
});

const debouncedSearchTree = (q) => _.debounce(
Expand Down Expand Up @@ -61,7 +66,7 @@ function showTreeMatches(matched) {
function selectTreeMatch(id) {
$('#treeSearch .dropdown').empty();
const input = $(`#taxonomy-tree input[value="${id}"]`);
input.prop('checked', true);
SELECTION_ENABLED && input.prop('checked', true);
let ul = input.closest('ul');
expandTreeBranch(ul);
updateTreeSelection();
Expand Down Expand Up @@ -94,6 +99,7 @@ function addNodeClickEvent() {
}

function setMatricesValue() {
if (!SELECTION_ENABLED) return;
const matricesValueText = $('#matricesValue').text().replaceAll("'", '"');
const selectedMatrices = JSON.parse(matricesValueText);
if (selectedMatrices.length) {
Expand All @@ -113,19 +119,21 @@ function setTermsValue() {
}

function updateTreeSelection() {
const selected = $('#taxonomy-tree input:checked');
const count = selected.length;
$('#matrixCount span').text(count);
if (count) {
$('#matrixCount').addClass('text-success');
$('#matrixCount').removeClass('text-danger');
} else {
$('#matrixCount').addClass('text-danger');
$('#matrixCount').removeClass('text-success');
}
if (!SELECTION_ENABLED) return;
const selected = $('#taxonomy-tree input:checked');
const count = selected.length;
$('#matrixCount span').text(count);
if (count) {
$('#matrixCount').addClass('text-success');
$('#matrixCount').removeClass('text-danger');
} else {
$('#matrixCount').addClass('text-danger');
$('#matrixCount').removeClass('text-success');
}
}

function clearTreeSelection() {
if (!SELECTION_ENABLED) return;
$('#treeSearch input').val('');
$('#taxonomy-tree input:checked').prop('checked', false);
updateTreeSelection();
Expand Down
37 changes: 20 additions & 17 deletions webapp/home/templates/home/requests/access/fgenesh.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,32 @@ <h3 class="mb-3">
<hr>

<div class="col-sm-12">
<h3 class="mb-3">Select matrices</h3>
<h3 class="mb-3">Locate a matrix for your analysis</h3>

<p>
An annotation matrix for your species (or a related species) may need
to be installed prior to use. This will be used as a reference to
annotate your genome, so you should nominate a matrix with the closest
taxonomic proximity to your subject species. If you have more than
one species of interest, you can select multiple matrices.
An annotation matrix for your species (or a related species) must be
selected when you run this tool. This will be used as a reference to
annotate your genome.
</p>

<div id="matricesValue" style="display: none;">{{ form.matrices.value|default_if_none:"[]" }}</div>

{{ form.matrices.errors }}
<div class="alert alert-info">
<table>
<tr>
<td>
<span class="material-icons p-3" style="opacity: 1;">info</span>
</td>
<td>
A matrix with close taxonomic proximity to your subject species
will provide higher quality gene predictions.
Please use the explorer below to ensure that a suitable matrix exists
for your analysis. Take a note of the matrix you intend to use for
when you run this tool in Galaxy.
</td>
</tr>
</table>
</div>

<p>
<button class="ga-btn btn-sm" type="button" onclick="expandTreeSelected();">Show selection</button>
<button class="ga-btn btn-sm" type="button" onclick="clearTreeSelection();">Clear selection</button>
<button class="ga-btn btn-sm" type="button" onclick="resetTreeList();">Collapse tree</button>
</p>

Expand All @@ -113,12 +122,6 @@ <h3 class="mb-3">Select matrices</h3>
</div>
</div>

<p class="lead" id="matrixCount">
<span>0</span> matrices selected
</p>

<ul id="selectedMatrices"></ul>

{{ form.render_matrix_field|safe }}

</div>
Expand Down
1 change: 0 additions & 1 deletion webapp/home/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def test_it_can_handle_request_for_fgenesh_access(self):
'email': '[email protected]',
'agree_terms': 'on',
'agree_acknowledge': 'on',
'matrices': [genematrix_tree.as_choices()[0][0]],
})
self.assert_access_form_success(response, auto_action=False)

Expand Down
16 changes: 11 additions & 5 deletions webapp/utils/data/fgenesh/genematrix_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,26 @@ def get_order(v):
keys.sort(key=lambda k: get_order(node[k]))
return keys

def render_leaf_li(key, desc):
def render_leaf_li(key, desc, checkbox=False):
"""Render a list item representing a matrix choice."""
tag = f'{" " * indent}<li>\n'
indent_str = " " * (indent + 1)
input_val = get_input_val(key, desc)
checkbox = (f'{indent_str}<input type="checkbox"'
f' name="matrices" value="{input_val}"'
f' id="{input_val}">')
checkbox_html = (
f'{indent_str}<input type="checkbox"'
f' name="matrices" value="{input_val}"'
f' id="{input_val}">'
)
if not checkbox:
icon = '<i class="fas fa-check-square" style="color: limegreen;"></i>'
checkbox_html = icon + checkbox_html.replace(
'type="checkbox"', 'type="hidden"')
text = key
if desc:
text += f' - {desc}'
return (
f'{tag}{indent_str}<span class="choice">'
f'{checkbox}'
f'{checkbox_html}'
f'<label for="{input_val}">'
f"{text}"
'</label>'
Expand Down

0 comments on commit 0f0b34f

Please sign in to comment.