From cd948b1ccf6781c17c9e4b4899ada9d654f16e83 Mon Sep 17 00:00:00 2001
From: Hao Chen
Date: Wed, 8 May 2019 09:18:21 -0500
Subject: showing sentences
---
ratspub.py | 8 ++--
server.py | 29 ++++++++++++---
templates/cytoscape.html | 97 ++++++++++++++++++++++++++++++------------------
templates/index.html | 4 +-
templates/layout.html | 2 +-
templates/sentences.html | 9 +++++
6 files changed, 99 insertions(+), 50 deletions(-)
create mode 100644 templates/sentences.html
diff --git a/ratspub.py b/ratspub.py
index c853fd2..0670726 100755
--- a/ratspub.py
+++ b/ratspub.py
@@ -26,7 +26,7 @@ def getSentences(query, gene):
for sent in sentences:
if findWholeWord(gene)(sent):
sent=re.sub(r'\b(%s)\b' % gene, r'\1', sent, flags=re.I)
- out+=pmid+"\t"+sent+"
\n"
+ out+=pmid+"\t"+sent+"\n"
return(out)
def gene_addiction(gene):
@@ -87,7 +87,7 @@ def generate_edges(data):
edgeCnts[edgeID]=1
for edgeID in edgeCnts:
(source,target)=edgeID.split("|")
- json0+="{ data: { id: \'" + edgeID + "\', source: \'" + source + "\', target: '" + target + "\', sentCnt: '" + str(edgeCnts[edgeID]) + "' } },\n"
+ json0+="{ data: { id: \'" + edgeID + "\', source: \'" + source + "\', target: '" + target + "\', sentCnt: '" + str(edgeCnts[edgeID]) + "', url:'/sentences?edgeID=" + edgeID + "' } },\n"
return(json0)
@@ -103,9 +103,9 @@ addiction=undic(addiction_d)
drug_d = {"alcohol":"alcohol|alcoholism",
"nicotine":"smoking|nicotine|tobacco",
- "amphetamine":"methamphetamine|amphetamine|METH",
"cocaine":"cocaine",
"opioid":"opioid|fentanyl|oxycodone|oxycontin|heroin|morphine",
+ "amphetamine":"methamphetamine|amphetamine|METH",
"cannabinoid":"marijuana|cannabinoid|tetrahydrocannabinol|thc|thc-9"
}
drug=undic(drug_d)
@@ -121,10 +121,10 @@ brain_d ={"cortex":"cortex|pfc|vmpfc|il|pl|prelimbic|infralimbic",
brain="cortex|accumbens|striatum|amygadala|hippocampus|tegmental|mesolimbic|infralimbic|prelimbic"
function_d={"plasticity":"LTP|LTD|plasticity|synaptic|epsp|epsc",
- "neurotransmission": "neurotransmission|glutamate|GABA|cholinergic|serotoninergic",
"signalling":"signalling|phosphorylation|glycosylation",
# "regulation":"increased|decreased|regulated|inhibited|stimulated",
"transcription":"transcription|methylation|histone|ribosome",
+ "neurotransmission": "neurotransmission|glutamate|GABA|cholinergic|serotoninergic",
}
function=undic(function_d)
diff --git a/server.py b/server.py
index 6a28e0b..4eaf911 100644
--- a/server.py
+++ b/server.py
@@ -15,6 +15,8 @@ def home():
@app.route("/search")
def search():
+ global all_sentences
+ all_sentences=str()
genes=request.args.get('query')
genes=genes.replace(",", " ")
genes=genes.replace(";", " ")
@@ -23,14 +25,29 @@ def search():
edges=str()
for gene in genes:
nodes+="{ data: { id: '" + gene + "', nodecolor:'#FADBD8', fontweight:700} },\n"
- tmp0=gene_addiction(gene)
- e0=generate_edges(tmp0)
- tmp1=gene_functional(gene)
- e1=generate_edges(tmp1)
- tmp2=gene_anatomical(gene)
- e2=generate_edges(tmp2)
+ sent0=gene_addiction(gene)
+ e0=generate_edges(sent0)
+ sent1=gene_functional(gene)
+ e1=generate_edges(sent1)
+ sent2=gene_anatomical(gene)
+ e2=generate_edges(sent2)
edges+=e0+e1+e2
+ all_sentences+=sent0+sent1+sent2
return render_template('cytoscape.html', elements=nodes+edges)
+@app.route("/sentences")
+def sentences():
+ edge=request.args.get('edgeID')
+ (gene0, cat0)=edge.split("|")
+ print (gene0 + cat0)
+ out=str()
+ for sent in all_sentences.split("\n"):
+ #print (sent)
+ if len(sent.strip())!=0:
+ (gene,nouse,cat, pmid, text)=sent.split("\t")
+ if (gene == gene0 and cat == cat0) :
+ out+= "