From ae27a5c9996f34487ee0f2669104b30dee263189 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Mon, 24 Aug 2020 16:02:32 +0530 Subject: [PATCH] added pubmed search --- README.md | 3 +++ app/forms.py | 5 +++- app/templates/search.html | 50 +++++++++++++++++++++++++++++++++++++++ app/views.py | 27 +++++++++++++++++++-- requirements.txt | 9 +++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 app/templates/search.html diff --git a/README.md b/README.md index 231bbec..232e35e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ [![DeepSource](https://static.deepsource.io/deepsource-badge-dark-mini.svg)](https://deepsource.io/gh/navanchauhan/Curie-Web/?ref=repository-badge) +**Do Not Forget To Change DB Host configuration!** + + ``` export PATH=$PATH:/home/pi/Desktop/Curie-Web/app/src/scripts diff --git a/app/forms.py b/app/forms.py index 44dadfc..975b3ad 100644 --- a/app/forms.py +++ b/app/forms.py @@ -36,4 +36,7 @@ class statusForm(FlaskForm): class generateSMILES(FlaskForm): n = IntegerField('Number of Molecules to Generate',default=1,validators=[DataRequired()]) - #modelSelection = SelectField('Model',choices=[("alpha","Alpha"),("beta","Beta")]) \ No newline at end of file + #modelSelection = SelectField('Model',choices=[("alpha","Alpha"),("beta","Beta")]) + +class PyMedSearch(FlaskForm): + query = StringField('Search Query for PubMed',default="Covid-19",validators=[DataRequired()]) \ No newline at end of file diff --git a/app/templates/search.html b/app/templates/search.html new file mode 100644 index 0000000..1faf151 --- /dev/null +++ b/app/templates/search.html @@ -0,0 +1,50 @@ +{% extends 'base.html' %} + +{% block main %} +

Curie Search

+

Search PubMed articles.

+
+ {% include 'flash_messages.html' %} + {{ form.csrf_token }} +
+ {{ form.query.label }} + {{ form.query(class="form-control")}} +
+ +
+
+ +
+
+ + {% if result %} +

Search Results

+ {% for x in range(result|length) %} + + +
+
+
+
+

DOI: {{result[x]['doi']}}

+

PubMed ID: {{result[x]['pubmed_id']}}

+

Download: Sci-Hub

+

Journal: {{result[x]['journal']}}

+
+
+
+
+
{{result[x]["title"]}}
+

Abstract: {{result[x]["abstract"]}}

+

Published on {{result[x]['publication_date']}}

+
+
+
+
+ {% endfor %} + {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index 0f544b1..89b0374 100644 --- a/app/views.py +++ b/app/views.py @@ -9,10 +9,13 @@ from flask import render_template, request, flash from werkzeug.utils import secure_filename from random import choice, shuffle from string import digits, ascii_lowercase +from pymed import PubMed +from datetime import datetime +import json # Note: that when using Flask-WTF we need to import the Form Class that we created # in forms.py -from .forms import MyForm, curieForm, statusForm, generateSMILES +from .forms import MyForm, curieForm, statusForm, generateSMILES, PyMedSearch def gen_word(N, min_N_dig, min_N_low): choose_from = [digits]*min_N_dig + [ascii_lowercase]*min_N_low @@ -47,6 +50,26 @@ def visualise(): """Render visualisation page.""" return render_template('visualise.html') +@app.route('/Search',methods=['GET','POST']) +def pubmed(): + """Query PubMed""" + form = PyMedSearch() + pubmed = PubMed(tool="Curie", email="navanchauhan@gmail.com") + + if request.method == 'POST' and form.validate_on_submit(): + q = form.query.data + print(form) + print(pubmed) + results = pubmed.query(q,max_results=100) + search = [] + for x in results: + search.append(x.toDict()) + + return render_template('search.html',result=search,form=form) + + flash_errors(form) + return render_template('search.html',form=form) + @app.route('/Status',methods=['GET','POST']) def status(): taskStatusForm = statusForm() @@ -110,7 +133,7 @@ def wtform(): flash_errors(myform) return render_template('wtform.html', form=myform) -tfWorking = -1 +tfWorking = 0 if tfWorking == -1: try: diff --git a/requirements.txt b/requirements.txt index d031e0e..8fb62fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,12 @@ uvicorn tensorflow-cpu==2.2.0 bunch tqdm +prettytable +gradio +git+https://github.com/bp-kelley/descriptastorus +pandas_flavor +subword_nmt +wget +lifelines +scikit-plot +pymed \ No newline at end of file