aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xratspub.py8
-rwxr-xr-xs2.py112
-rwxr-xr-xserver.py81
-rw-r--r--templates/index.html8
-rw-r--r--templates/progress.html44
5 files changed, 95 insertions, 158 deletions
diff --git a/ratspub.py b/ratspub.py
index 70877b6..7916198 100755
--- a/ratspub.py
+++ b/ratspub.py
@@ -106,7 +106,7 @@ drug_d = {"alcohol":"alcohol|alcoholism|alcoholic",
"nicotine":"smoking|nicotine|tobacco",
"cocaine":"cocaine",
"opioid":"opioid|opioids|fentanyl|oxycodone|oxycontin|heroin|morphine|methadone|buprenorphine|vicodin|hydrocodone|hycodan|kadian|percoset|hydromorphone|naloxone|codeine|suboxone|tramadol|kratom",
- "amphetamine":"methamphetamine|amphetamine|METH",
+ "amphetamine":"methamphetamine|amphetamine|METH|AMPH",
"cannabinoid":"endocannabinoid|cannabinoids|endocannabinoids|marijuana|cannabidiol|cannabinoid|tetrahydrocannabinol|thc|thc 9|Oleoylethanolamide|palmitoylethanolamide|acylethanolamides"
}
drug=undic(drug_d)
@@ -121,11 +121,11 @@ brain_d ={"cortex":"cortex|prefrontal|pfc|mPFC|vmpfc|corticostriatal|cortico lim
# brain region has too many short acronyms to just use the undic function, so search PubMed using the following
brain="cortex|accumbens|striatum|amygadala|hippocampus|tegmental|mesolimbic|infralimbic|prelimbic"
-function_d={"neuroplasticity":"neuroplasticity|plasticity|long term potentiation|LTP|long term depression|LTD|synaptic|epsp|epsc|neurite|neurogenesis|boutons|mIPSC|IPSC|IPSP",
- "signalling":"signalling|signaling|phosphorylation|glycosylation",
-# "regulation":"increased|decreased|regulated|inhibited|stimulated",
+function_d={"signalling":"signalling|signaling|phosphorylation|glycosylation",
"transcription":"transcription|methylation|hypomethylation|hypermethylation|histone|ribosome",
+ "neuroplasticity":"neuroplasticity|plasticity|long term potentiation|LTP|long term depression|LTD|synaptic|epsp|epsc|neurite|neurogenesis|boutons|mIPSC|IPSC|IPSP",
"neurotransmission": "neurotransmission|neuropeptides|neuropeptide|glutamate|glutamatergic|GABA|GABAergic|dopamine|dopaminergic|DAergic|cholinergic|nicotinic|muscarinic|serotonergic|serotonin|5 ht|acetylcholine",
+# "regulation":"increased|decreased|regulated|inhibited|stimulated",
}
function=undic(function_d)
diff --git a/s2.py b/s2.py
deleted file mode 100755
index 7e2848b..0000000
--- a/s2.py
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/bin/env python3
-from flask import Flask, render_template, request, session, Response
-import tempfile
-import random
-import string
-from ratspub import *
-import time
-
-app=Flask(__name__)
-app.config['SECRET_KEY'] = '#DtfrL98G5t1dC*4'
-
-@app.route("/")
-def root():
- return render_template('index.html')
-
-@app.route('/progress')
-def progress():
- # only 1-6 terms are allowed
- genes=request.args.get('query')
- genes=genes.replace(",", " ")
- genes=genes.replace(";", " ")
- genes=genes.split()
- if len(genes)>=6:
- message="<span class='text-danger'>Up to five terms can be searched at a time</span>"
- return render_template('index.html', message=message)
- elif len(genes)==0:
- message="<span class='text-danger'>Please enter a search term </span>"
- return render_template('index.html', message=message)
- # put the query in session cookie
- session['query']=genes
- # generate a unique session ID to track the results
- tf_path=tempfile.gettempdir()
- session['path']=tf_path+"/tmp" + ''.join(random.choice(string.ascii_letters) for x in range(6))
- return render_template('progress.html')
-
-@app.route("/search")
-def search():
-# tf_path=tempfile.gettempdir()
-# tf_name=tf_path+"/tmp"+''.join(random.choice(string.ascii_letters) for x in range(6))
- genes=session['query']
- percent=round(100/(len(genes)*3), 2)
- print ("percent percent --->"+str(percent))
- cysdata=open(session['path']+"_cy","w+")
- sntdata=open(session['path']+"_snt","w+")
- def generate(genes):
- sentences=str()
- edges=str()
- nodes=default_nodes
- nodes=str()
- progress=0
- #ft_name=session['path']
- ft_name="path"
- for gene in genes:
- nodes+="{ data: { id: '" + gene + "', nodecolor:'#FADBD8', fontweight:700, url:'https://www.ncbi.nlm.nih.gov/gene/?term="+gene+"'} },\n"
- print ("xxxxxxxxxxxxxxxxxxxxxx")
- print (genes)
- sent0=gene_addiction(gene)
- progress+=percent
- print ("yyyyyyyyyyyyyx")
- print(progress)
- yield "data:"+str(progress)+"\n\n"
- e0=generate_edges(sent0, "tf_name")
- sent1=gene_functional(gene)
- progress+=percent
- yield "data:"+str(progress)+"\n\n"
- e1=generate_edges(sent1, "tf_name")
- sent2=gene_anatomical(gene)
- progress+=percent
- e2=generate_edges(sent2, "tf_name")
- edges+=e0+e1+e2
- sentences+=sent0+sent1+sent2
- #save data before the last yield
- if (progress>99):
- progress=100
- sntdata.write(sentences)
- sntdata.close()
- cysdata.write(nodes)
- cysdata.close()
- yield "data:"+str(progress)+"\n\n"
- return Response(generate(genes), mimetype='text/event-stream')
-
-@app.route('/cytoscape')
-def cytoscape():
- with open(session['path']+"_cy","r") as f:
- elements=f.read()
- return render_template('cytoscape.html', elements=elements)
-
-@app.route("/sentences")
-def sentences():
- edge=request.args.get('edgeID')
- (tf_name, gene0, cat0)=edge.split("|")
- out="<h3>"+gene0 + " and " + cat0 + "</h3><hr>\n"
- print(tf_name)
- with open(tf_name, "r") as df:
- all_sents=df.read()
- for sent in all_sents.split("\n"):
- if len(sent.strip())!=0:
- (gene,nouse,cat, pmid, text)=sent.split("\t")
- if (gene == gene0 and cat == cat0) :
- out+= "<li> "+ text + " <a href=\"https://www.ncbi.nlm.nih.gov/pubmed/?term=" + pmid +"\" target=_new>PMID:"+pmid+"<br></a>"
- return render_template('sentences.html', sentences="<ol>"+out+"</ol><p>")
-
-@app.route("/shownode")
-def shownode():
- node=request.args.get('node')
- allnodes={**brain_d, **drug_d, **function_d, **addiction_d}
- out="<p>"+node.upper()+"<hr><li>"+ allnodes[node].replace("|", "<li>")
- return render_template('sentences.html', sentences=out+"<p>")
-
-
-if __name__ == '__main__':
- app.run(debug=True)
diff --git a/server.py b/server.py
index 457a8cd..b171c1e 100755
--- a/server.py
+++ b/server.py
@@ -1,9 +1,10 @@
#!/bin/env python3
-from flask import Flask, render_template, request, redirect
+from flask import Flask, render_template, request, session, Response
import tempfile
import random
import string
from ratspub import *
+import time
app=Flask(__name__)
app.config['SECRET_KEY'] = '#DtfrL98G5t1dC*4'
@@ -12,11 +13,9 @@ app.config['SECRET_KEY'] = '#DtfrL98G5t1dC*4'
def root():
return render_template('index.html')
-@app.route("/search")
-def search():
- tf_path=tempfile.gettempdir()
- tf_name=tf_path+"/tmp"+''.join(random.choice(string.ascii_letters) for x in range(6))
- all_sentences=str()
+@app.route('/progress')
+def progress():
+ # only 1-6 terms are allowed
genes=request.args.get('query')
genes=genes.replace(",", " ")
genes=genes.replace(";", " ")
@@ -24,30 +23,64 @@ def search():
if len(genes)>=6:
message="<span class='text-danger'>Up to five terms can be searched at a time</span>"
return render_template('index.html', message=message)
- nodes=default_nodes
- edges=str()
- for gene in genes:
- nodes+="{ data: { id: '" + gene + "', nodecolor:'#FADBD8', fontweight:700, url:'https://www.ncbi.nlm.nih.gov/gene/?term="+gene+"'} },\n"
- sent0=gene_addiction(gene)
- e0=generate_edges(sent0, tf_name)
- sent1=gene_functional(gene)
- e1=generate_edges(sent1, tf_name)
- sent2=gene_anatomical(gene)
- e2=generate_edges(sent2, tf_name)
- edges+=e0+e1+e2
- all_sentences+=sent0+sent1+sent2
- #session['tmpfile']={'filename':tf_name}
- with open(tf_name,"w") as f:
- f.write(all_sentences)
- f.close()
- return render_template('cytoscape.html', elements=nodes+edges)
+ elif len(genes)==0:
+ message="<span class='text-danger'>Please enter a search term </span>"
+ return render_template('index.html', message=message)
+ # put the query in session cookie
+ session['query']=genes
+ # generate a unique session ID to track the results
+ tf_path=tempfile.gettempdir()
+ session['path']=tf_path+"/tmp" + ''.join(random.choice(string.ascii_letters) for x in range(6))
+ return render_template('progress.html')
+
+@app.route("/search")
+def search():
+ genes=session['query']
+ percent=round(100/(len(genes)*3),1)
+ snt_file=session['path']+"_snt"
+ cysdata=open(session['path']+"_cy","w+")
+ sntdata=open(snt_file,"w+")
+ def generate(genes, tf_name):
+ sentences=str()
+ edges=str()
+ nodes=default_nodes
+ progress=0
+ for gene in genes:
+ nodes+="{ data: { id: '" + gene + "', nodecolor:'#FADBD8', fontweight:700, url:'https://www.ncbi.nlm.nih.gov/gene/?term="+gene+"'} },\n"
+ sent0=gene_addiction(gene)
+ progress+=percent
+ yield "data:"+str(progress)+"\n\n"
+ e0=generate_edges(sent0, tf_name)
+ sent1=gene_functional(gene)
+ progress+=percent
+ yield "data:"+str(progress)+"\n\n"
+ e1=generate_edges(sent1, tf_name)
+ sent2=gene_anatomical(gene)
+ progress+=percent
+ e2=generate_edges(sent2, tf_name)
+ edges+=e0+e1+e2
+ sentences+=sent0+sent1+sent2
+ #save data before the last yield
+ if (progress>99):
+ progress=100
+ sntdata.write(sentences)
+ sntdata.close()
+ cysdata.write(nodes+edges)
+ cysdata.close()
+ yield "data:"+str(progress)+"\n\n"
+ return Response(generate(genes, snt_file), mimetype='text/event-stream')
+
+@app.route('/cytoscape')
+def cytoscape():
+ with open(session['path']+"_cy","r") as f:
+ elements=f.read()
+ return render_template('cytoscape.html', elements=elements)
@app.route("/sentences")
def sentences():
edge=request.args.get('edgeID')
(tf_name, gene0, cat0)=edge.split("|")
out="<h3>"+gene0 + " and " + cat0 + "</h3><hr>\n"
- print(tf_name)
with open(tf_name, "r") as df:
all_sents=df.read()
for sent in all_sents.split("\n"):
diff --git a/templates/index.html b/templates/index.html
index 6d50a63..0771787 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -3,7 +3,7 @@
<p>
<br>
{{ message | safe }}
- <form action="/search">
+ <form action="/progress">
<input name="query" class="form-control form-control-lg" type="search" placeholder="Rgma Nrxn3" aria-label="search" value="">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
@@ -13,6 +13,12 @@
<br>
Searches are conducted through PubMed to get relevant PMIDs, which are then used to retrieve the abstracts from a <a href="https://dataguide.nlm.nih.gov/edirect/archive.html">local archive</a>. The gene-keyword relationships are presented as an interactive <a href="https://js.cytoscape.org" >cytoscape</a> graph. The nodes can be moved to better reveal the connections. Tap on the links will bring up the corresponding sentences in a new browser window.
<p>
+
+ <form action="/gene_gene">
+ <input name="gene" class="form-control form-control-lg" type="search" placeholder="Rgma Nrxn3" aria-label="search" value="Nrxn1">
+ <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
+ </form>
+
<hr>
<a href="https://github.com/chen42/ratspub"> Source code </a>
diff --git a/templates/progress.html b/templates/progress.html
index 322604d..7b4a9d0 100644
--- a/templates/progress.html
+++ b/templates/progress.html
@@ -3,25 +3,35 @@
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
- <script>
- var source = new EventSource("/search");
- source.onmessage = function(event) {
- $('.progress-bar').css('width', event.data+'%').attr('aria-valuenow', event.data);
- $('.progress-bar-label').text(event.data+'%');
-
- if(event.data == 100){
- window.location.replace("/cytoscape")
- source.close()
- }
- }
- </script>
+<script>
+
+
+var r = Math.floor(Math.random() * Math.floor(125));
+var g = Math.floor(Math.random() * Math.floor(125));
+var b = Math.floor(Math.random() * Math.floor(125));
+document.body.style.backgroundColor = 'rgba('+r+','+g+','+b+',0.1)'
- <div id="progs" class="progress" style="width: 50%; margin: 50px;">
- <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
- <span class="progress-bar-label">0%</span>
- </div>
+var source = new EventSource("/search");
+source.onmessage = function(event) {
+ $('.progress-bar').css('width', event.data+'%').attr('aria-valuenow', event.data);
+ $('.progress-bar-label').text(event.data+'%');
+ var alpha = event.data/150
+ document.body.style.backgroundColor = 'rgba('+r+','+g+','+b+',0.3)'.replace(/[^,]+(?=\))/, alpha)
+
+ if(event.data == 100){
+ window.location.replace("/cytoscape")
+ source.close()
+ }
+}
+</script>
+<br>
+<b> We hope this won't take too long ... </b>
+<div id="progs" class="progress" style="width: 50%; margin: 50px;">
+ <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
+ <span class="progress-bar-label">0%</span>
</div>
-
+</div>
+
{% endblock %}