Skip to content

Commit

Permalink
Reworking perform mapping page/submission/etc
Browse files Browse the repository at this point in the history
  • Loading branch information
danielecook committed Jan 18, 2018
1 parent e49e153 commit 5f45b7b
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 26 deletions.
2 changes: 1 addition & 1 deletion base/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def gs_static(url, prefix='static'):
from base.views.data import data_bp
app.register_blueprint(data_bp, url_prefix='/data')

# Mapping Pages -
# Mapping Pages -
from base.views.mapping import mapping_bp
app.register_blueprint(mapping_bp, url_prefix='/mapping')

Expand Down
30 changes: 28 additions & 2 deletions base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,44 @@ def total(self):
total_price += price
return total_price

import json
import pandas as pd
from base.views.api.api_strain import query_strains
def process_phenotype_data(input_data):
try:
data = json.loads(input_data)
except ValueError as e:
raise ValidationError(e.msg)
# Read in data
headers = data.pop(0)
df = pd.DataFrame(data, columns=headers) \
.dropna(thresh=1) \
.dropna(thresh=1, axis=1)
rows, columns = df.shape
if rows < 30:
raise ValidationError("A minimum of 30 strains are required.")

# Resolve isotypes
#print(df)
#print(query_strains(df[['STRAIN']], list_only=True, as_scaler=True))
df = df.assign(isotype=[query_strains(x, resolve_isotype=True) for x in df.STRAIN])
print(df)




class mapping_submission_form(Form):
"""
Form for mapping submission
"""
report_name = StringField('Report Name', [Required(), Length(min=1, max=50)])
is_public = RadioField('Release', choices=[("True", 'public'), ("False", 'private')])
description = TextAreaField('Description', [Length(min=1, max=1000)])
description = TextAreaField('Description', [Length(min=0, max=1000)])
phenotype_data = HiddenField()

def validate_phenotype_data(form, field):
pass
phenotype_data = form.phenotype_data.data
data = process_phenotype_data(phenotype_data)



6 changes: 3 additions & 3 deletions base/templates/mapping.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ <h4>DISCLAIMER</h4>
<div class='row'>
<br />
<div class='col-md-10'>
<div class='well well-compact'><strong>If you are not redirected to a reports page after clicking the submit button, please notify us of the issue via the feedback form.</strong>
</div>
<br />
<strong>If you are not redirected to a reports page after clicking the submit button, please notify us of the issue via the feedback form.</strong>
</div>
<div class='col-md-2'>

<button type="submit" style="margin-top: 15px;" class="btn btn-primary btn-lg submit" disabled>Submit</button>
<button type="submit" style="margin-top: 15px;" class="btn btn-primary btn-lg btn-block submit" disabled>Submit</button>


</div>
Expand Down
2 changes: 1 addition & 1 deletion base/utils/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import werkzeug
from functools import wraps
from flask import request, jsonify
from logzero import logger


def jsonify_request(func):
Expand Down
2 changes: 1 addition & 1 deletion base/utils/gcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def store_item(kind, name, **kwargs):
ds = google_datastore()
m = datastore.Entity(key=ds.key(kind, name))
for key, value in kwargs.items():
if type(value) == dict:
if isinstance(value, dict):
m[key] = 'JSON:' + json.dumps(value)
else:
m[key] = value
Expand Down
34 changes: 28 additions & 6 deletions base/views/api/api_strain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,59 @@
from base.models2 import strain_m
from base.application import app
from base.utils.decorators import jsonify_request
from sqlalchemy import or_


@app.route('/api/strain/')
@app.route('/api/strain/<string:strain_name>')
@app.route('/api/strain/isotype/<string:isotype_name>')
@jsonify_request
def query_strains(strain_name=None, isotype_name=None, release=None, list_only=False):
def query_strains(strain_name=None, isotype_name=None, release=None, all_strain_names=False, resolve_isotype=False):
"""
Return the full strain database set
strain_name - Returns data for only one strain
isotype_name - Returns data for all strains of an isotype
release - Filters results released prior to release data
list_only - Return list of strains only (internal use).
all_strain_names - Return list of all possible strain names (internal use).
resolve_isotype - Use to search for strains and return their isotype
"""
base_query = strain_m.query
if release:
base_query = base_query.filter(strain_m.release <= release)

if strain_name:
results = base_query.filter(strain_m.strain == strain_name).first()
results = base_query.filter(or_(strain_m.previous_names.like(f"%{strain_name}|%"),
strain_m.previous_names.like(f"%,{strain_name}|"),
strain_m.previous_names.like(f"%{strain_name}"),
strain_m.previous_names == strain_name,
strain_m.strain == strain_name)).first()
elif isotype_name:
results = base_query.filter(strain_m.isotype == isotype_name).all()
else:
results = base_query.all()

if list_only:
results = [x.strain for x in results]
if all_strain_names:
previous_strain_names = sum([x.previous_names.split("|") for x in results if x.previous_names], [])
results = [x.strain for x in results] + previous_strain_names
if resolve_isotype:
if results:
print(results, "RESULTS")
return results.isotype
return results


def resolve_strain(query):
"""
Resolve train name
"""

base_query.query.filter(or_(strain_m.previous_names.like(f"%{strain_name},%"),
strain_m.previous_names.like(f"%,{strain_name},"),
strain_m.previous_names.like(f"%{strain_name}",
strain_m.previous_names == strain_name,
strain_m.strain == strain_name))).first()


@app.route('/api/isotype')
@jsonify_request
def get_isotypes(known_origin=False, list_only=False):
Expand Down
4 changes: 1 addition & 3 deletions base/views/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
import time

from base.application import app, cache

from base.utils.email import send_email, MAPPING_SUBMISSION_EMAIL

from base.application import autoconvert
Expand Down Expand Up @@ -52,7 +50,7 @@ def mapping():
form = mapping_submission_form(request.form)

VARS = {'title': 'Perform Mapping',
'strain_list': query_strains(list_only=True),
'strain_list': query_strains(all_strain_names=True),
'form': form}

if form.validate_on_submit():
Expand Down
20 changes: 12 additions & 8 deletions base/views/primary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"""
import os
from flask import render_template, url_for, request, redirect, Blueprint, session
from flask import render_template, url_for, request, redirect, Blueprint
from base.utils.text_utils import render_markdown
from base.utils.data_utils import sorted_files
from datetime import datetime
Expand All @@ -18,14 +17,17 @@
primary_bp = Blueprint('primary',
__name__)

# Homepage

@primary_bp.route('/')
def primary():
"""
The home page
"""
page_title = "Caenorhabditis elegans Natural Diversity Resource"
files = sorted_files("base/static/content/news/")
VARS = {'page_title': page_title,
'files': files}
#latest_mappings = list(report.filter(report.release == 0, trait.status == "complete").join(trait).order_by(
# latest_mappings = list(report.filter(report.release == 0, trait.status == "complete").join(trait).order_by(
# trait.submission_complete.desc()).limit(5).select(report, trait).distinct().dicts().execute())
return render_template('primary/home.html', **VARS)

Expand All @@ -39,9 +41,10 @@ def reroute_software():
@primary_bp.route("/news/")
@primary_bp.route("/news/<filename>/")
def news_item(filename=""):
"""
News
"""
files = sorted_files("base/static/content/news/")
# sorts the thing in the right order on the webpage
# after clicking on the server
if not filename:
filename = files[0].strip(".md")
title = filename[11:].strip(".md").replace("-", " ")
Expand All @@ -51,14 +54,16 @@ def news_item(filename=""):
@primary_bp.route("/help/")
@primary_bp.route("/help/<filename>/")
def help_item(filename=""):
"""
Help
"""
files = ["FAQ", "Variant-Browser", "Variant-Prediction", "Methods", "Software", "Change-Log"]
if not filename:
filename = "FAQ"
title = filename.replace("-", " ")
return render_template('help_item.html', **locals())



@primary_bp.route('/feed.atom')
def feed():
"""
Expand Down Expand Up @@ -90,4 +95,3 @@ def outreach():
def contact():
title = "Contact Us"
return render_template('contact.html', **locals())

2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
from base.views.api import *


def test_one():
def test_function():
assert 1 == 1

0 comments on commit 5f45b7b

Please sign in to comment.