Skip to content

Commit

Permalink
Merge pull request #26 from TheJacksonLaboratory/G3-493-temporary-fix…
Browse files Browse the repository at this point in the history
…-for-threshold-page

Adding new threshold page
  • Loading branch information
bergsalex authored Nov 8, 2024
2 parents 3b16753 + 9663e4f commit 7223ef7
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-legacy"
version = "1.4.8"
version = "1.5.0"
description = ""
authors = ["Alexander Berger <[email protected]>"]
readme = "README.md"
Expand Down
65 changes: 60 additions & 5 deletions src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@
api_base_url=f'https://{config.get("auth", "domain")}/',
access_token_url=f'https://{config.get("auth", "domain")}/{config.get("auth", "token_endpoint")}',
authorize_url=f'https://{config.get("auth", "domain")}/{config.get("auth", "auth_endpoint")}',
client_kwargs={'scope': 'openid profile email'},
client_kwargs={
'scope': 'openid profile email',
},
server_metadata_url=f'https://{config.get("auth", "domain")}/.well-known/openid-configuration',
jwks_uri=f'https://{config.get("auth", "domain")}/{config.get("auth", "jwks_endpoint")}'
)
Expand Down Expand Up @@ -378,7 +380,11 @@ def login_as(as_user_id):
@app.route('/login', methods=['GET'])
@app.route('/ssologin', methods=['GET'])
def sso_login():
return auth0.authorize_redirect(redirect_uri=url_for('callback_handling', _external=True))
redirect_uri = url_for('callback_handling', _external=True)
return auth0.authorize_redirect(
redirect_uri=redirect_uri,
audience=config.get('auth', 'audience')
)

@app.route('/ssosignup', methods=['GET'])
def sso_signup():
Expand All @@ -387,9 +393,17 @@ def sso_signup():

@app.route('/callback')
def callback_handling():
response = make_response(redirect('/'))
# Handles response from token endpoint
try:
auth0.authorize_access_token()
token = auth0.authorize_access_token()
response.set_cookie(
'access_token',
token['access_token'],
httponly=False,
secure=True,
samesite='Strict'
)
except OAuthError as e:
if e.description == "Jax users must use Jax connection to log in.":
_logout()
Expand Down Expand Up @@ -437,7 +451,7 @@ def callback_handling():
flask.session['remote_addr'] = remote_addr
geneweaverdb.update_user_seen(user.user_id)

return redirect('/')
return response

@app.route('/callback/errors/email-mismatch')
def callback_error_jax_email():
Expand Down Expand Up @@ -1939,9 +1953,50 @@ def render_remove_genesets(gs_id):
gs_and_proj = geneweaverdb.get_selected_genesets_by_projects(gs_id)
return render_template('removegenesets.html', user_id=user_id, gs_and_proj=gs_and_proj)


@app.route('/setthreshold/<int:gs_id>')
def render_set_threshold(gs_id):
user_id = session['user_id'] if 'user_id' in session else 0
user_info = geneweaverdb.get_user(user_id)
geneset = geneweaverdb.get_geneset(gs_id, user_id)
if user_id != 0:
view = 'True' if user_info.is_admin or user_info.is_curator or geneset.user_id == user_id else None

if view is None and geneweaverdb.user_is_assigned_curation(user_id, gs_id):
view = 'curator'
else:
view = None
# Determine if this is bi-modal, we won't display these
is_bimodal = geneweaverdb.get_bimodal_threshold(gs_id)
gsv_values = geneweaverdb.get_all_geneset_values(gs_id)
threshold_type = geneset.threshold_type
threshold = str(geneset.threshold)
thresh = threshold.split(',')
if len(thresh) == 1:
thresh.append(str(0))
minVal = float(thresh[0])
maxVal = float(thresh[1])
if gsv_values is not None:
for k in gsv_values:
k_first_value = list(k.values())[0]
maxVal = float(k_first_value) if float(k_first_value) > maxVal else maxVal
minVal = float(k_first_value) if float(k_first_value) < minVal else minVal
score_types = {
1: "p-value",
2: "q-value",
3: "binary",
4: "correlation",
5: "effect"
}

return render_template('viewThreshold_new.html', geneset=geneset,
user_id=user_id, view=view, is_bimodal=is_bimodal,
threshold=thresh, threshold_type=threshold_type,
minVal=minVal, maxVal=maxVal,
scoreType=score_types[threshold_type])


@app.route('/setthreshold-legacy/<int:gs_id>')
def render_set_threshold_legacy(gs_id):
d3BarChart = []
user_id = session['user_id'] if 'user_id' in session else 0
user_info = geneweaverdb.get_user(user_id)
Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Auth(BaseModel):
token_endpoint: str = Field("oauth/token", validation_alias="tokenendpoint")
userinfo_endpoint: str = Field("oauth/userinfo", validation_alias="userinfoendpoint")
jwks_endpoint: str = Field(".well-known/jwks.json", validation_alias="jwksendpoint")
audience: str = "https://cube.jax.org"


class GeneweaverLegacyConfig(BaseSettings):
Expand Down
3 changes: 3 additions & 0 deletions src/templates/viewThreshold.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ <h2 class="panel-title"><strong>Set GeneSet Threshold</strong></h2>
<button type="button" class="btn btn-block btn-warning" id="viewGenesetDetails">
<i class="fa fa-arrow-left pull-left"></i> Back to GeneSet
</button>
<a class="btn btn-block btn-success" href="../setthreshold/{{ geneset.geneset_id}}" role="button">
<i class="fa fa-history pull-left"></i> New Page
</a>
{% if view is defined %}
<button type="button" class="btn btn-block btn-warning" id="saveThreshold">
<i class="fa fa-save pull-left"></i> Save Threshold
Expand Down
171 changes: 171 additions & 0 deletions src/templates/viewThreshold_new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{% set title="Set GeneSet Threshold" %}
{% include 'header.html' %}
{% import 'macros.html' as macros %}

{% if geneset.geneset_id is not defined or view is not defined %}

{% include 'htmlfragments/genesetNotFound.html' %}

{% else %}

<div class="loader"></div>


<div class="panel panel-default panel-heading bg-gray-light">
<h2 class="panel-title"><strong>Set GeneSet Threshold</strong></h2>
</div>

<div class="panel panel-default">
{% include 'htmlfragments/curIDBoxes.html' %}

<div class="panel-body">
{% set threshold_symbol = 'p' if threshold_type == 1 else 'q' %}
{% if is_bimodal == 'False' %}
<div class="row">
{% if threshold_type == 4 or threshold_type == 5 %}
{% set threshold_high = threshold[1] if threshold[1] != '0' else maxVal %}
{% set threshold_name = 'a correlation' if threshold_type == 4 else 'an effect' %}
<div><p><strong>Current Threshold Values:
</strong> {{ threshold[0] }} <i class="fa fa-arrows-h"></i>
{% if threshold[1] == '0' %}
{{ maxVal }}
{% else %}
{{ threshold[1] }}
{% endif %}
</p>
</div>
{% else %}
<div><p><strong>Current Threshold Values:
</strong> {{ threshold_symbol }} < {{ threshold[0] }}
</p>
</div>
{% endif %}
</div>
{% else %}
<div class="row">
<div class="alert bg-gray-light">
This GeneSet only contains one uniform value.
Set threshold cannot be performed.
</div>
</div>
{% endif %}
<hr>
<div class="row">
<div class="col-md-8" style="margin-bottom: 1rem;">
{% if view is defined and is_bimodal == 'False' %}
{% if threshold_type == 4 or threshold_type == 5 %}
<div class="row">
<div class="input-group">
<span class="input-group-addon">Manually enter {{ threshold_name }} threshold range.</span>
<input type="number" min="0" step="0.001" value="{{ threshold[0] }}" class="form-control threshLow">
<span class="input-group-addon"><i class="fa fa-arrows-h"></i></span>
<input type="number" min="0" step="0.001" value="{{ threshold_high }}" class="form-control threshHigh">
<div class="input-group-btn">
<button class="btn btn-default setThresh" type="button">Save</button>
</div>
</div>
</div>
{% else %}
<div class="row">
<button type="button" class="btn btn-block btn-default setThresh" id="setThresh05" value="0.05">
Save as <code> {{ threshold_symbol }} < 0.05 </code>
</button>
<button type="button" class="btn btn-block btn-default setThresh" id="setThresh01" value="0.01">
Save as <code> {{ threshold_symbol }} < 0.01 </code>
</button>
<button type="button" class="btn btn-block btn-default setThresh" id="setThresh001" value="0.001">
Save as <code> {{ threshold_symbol }} < 0.001 </code>
</button>
<button type="button" class="btn btn-block btn-default setThresh" id="setThresh0001" value="0.0001">
Save as <code> {{ threshold_symbol }} < 0.0001 </code>
</button>

<hr>

<div class="input-group">
<span class="input-group-addon">Manually enter a threshold value.</span>
<span class="input-group-addon">Set to: {{ threshold_symbol }} < </span>
<input type="number" min="0" step="0.001" value="{{ threshold[0] }}" class="form-control threshLow">
<div class="input-group-btn">
<button class="btn btn-default setThresh" type="button">Save</button>
</div>
</div>
</div>
{% endif %}
{% endif %}
</div>

{# right side menu #}
<div class="col-md-4 mb-3">
{% set return_page = 'curategeneset' if view == 'curator' else 'viewgenesetdetails' %}
<a class="btn btn-block btn-warning" href="../{{ return_page }}/{{ geneset.geneset_id}}" role="button">
<i class="fa fa-arrow-left pull-left"></i> Back to GeneSet
</a>
{% if view is defined and is_bimodal == 'False' %}
<a class="btn btn-block btn-warning" href="../setthreshold-legacy/{{ geneset.geneset_id}}" role="button">
<i class="fa fa-history pull-left"></i> Legacy Page
</a>
{% endif %}
</div>

</div>
{% if view is defined and is_bimodal == 'False' %}
<script type="text/javascript">
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
$(document).ready(function () {
$('.setThresh').on('click', function (e) {
const access_token = getCookie('access_token');
console.log(access_token);
let value = $(this).val();
let valueHigh = null;
let newTresh;
if (value === '' || value == null) {
const $parent = $(this).parent().parent();
value = $parent.find('.threshLow').val();
valueHigh = $parent.find('.threshHigh').val();
}
console.log('Clicked button with value:', value, valueHigh);
if (valueHigh === '' || valueHigh == null) {
newTresh = {
threshold: value,
score_type: '{{ scoreType }}'
};
} else {
newTresh = {
threshold_low: value,
threshold: valueHigh,
score_type: '{{ scoreType }}'
};
}
$.ajax({
type: 'PUT',
{#
Note: If you are doing local development, you will probably
need to change this url to point at the dev API:
url: 'http://geneweaver-dev.jax.org/api/genesets/{{ geneset.geneset_id }}/threshold',
#}
url: '../api/genesets/{{ geneset.geneset_id }}/threshold',
contentType: 'application/json',
data: JSON.stringify(newTresh),
dataType: 'json',
headers: {
'Authorization': `Bearer ${access_token}`
},
success: function (data) {
location.reload();
}
});
});
});
</script>
{% endif %}

</div>

{% endif %}

{% include 'footer.html' %}

0 comments on commit 7223ef7

Please sign in to comment.