aboutsummaryrefslogtreecommitdiff
path: root/ratspub.py
diff options
context:
space:
mode:
Diffstat (limited to 'ratspub.py')
-rwxr-xr-xratspub.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/ratspub.py b/ratspub.py
index 345146e..ea78d85 100755
--- a/ratspub.py
+++ b/ratspub.py
@@ -3,6 +3,8 @@ from nltk.tokenize import sent_tokenize
import os
import re
+global function_d, brain_d, drug_d, addiction_d
+
## turn dictionary (synonyms) to regular expression
def undic(dic):
return "|".join(dic.values())
@@ -67,27 +69,28 @@ def gene_functional(gene):
out+=gene+"\t"+"function\t"+bio0+"\t"+sent+"\n"
return(out)
-def generate_nodes(nodes_d, nodecolor):
+def generate_nodes(nodes_d, nodetype):
+ nodecolor={'function':"#A9CCE3", 'addiction': "#D7BDE2", 'drug': "#F9E79F", 'brain':"#A3E4D7"}
# include all search terms even if there are no edges, just to show negative result
- json0 =str() #"{ data: { id: '" + gene + "'} },\n"
+ json0 =str()
for node in nodes_d:
- json0 += "{ data: { id: '" + node + "', nodecolor: '" + nodecolor + "' } },\n"
+ json0 += "{ data: { id: '" + node + "', nodecolor: '" + nodecolor[nodetype] + "', nodetype: '"+nodetype + "', url:'/shownode?nodetype=" + nodetype + "&node="+node+"' } },\n"
return(json0)
-def generate_edges(data):
+def generate_edges(data, filename):
json0=str()
edgeCnts={}
for line in data.split("\n"):
if len(line.strip())!=0:
(source, cat, target, pmid, sent) = line.split("\t")
- edgeID=source+"|"+target
+ edgeID=filename+"|"+source+"|"+target
if edgeID in edgeCnts:
edgeCnts[edgeID]+=1
else:
edgeCnts[edgeID]=1
for edgeID in edgeCnts:
- (source,target)=edgeID.split("|")
- json0+="{ data: { id: \'" + edgeID + "\', source: \'" + source + "\', target: '" + target + "\', sentCnt: '" + str(edgeCnts[edgeID]) + "', url:'/sentences?edgeID=" + edgeID + "' } },\n"
+ (filename, source,target)=edgeID.split("|")
+ json0+="{ data: { id: '" + edgeID + "', source: '" + source + "', target: '" + target + "', sentCnt: '" + str(edgeCnts[edgeID]) + "', url:'/sentences?edgeID=" + edgeID + "' } },\n"
return(json0)
addiction_d = {"reward":"reward|hedonic|incentive|intracranial self stimulation|ICSS|reinforcement|conditioned place preference|CPP|self administration|self administered|drug reinforced|operant|instrumental response",
@@ -126,9 +129,11 @@ function_d={"neuroplasticity":"neuroplasticity|plasticity|long term potentiation
}
function=undic(function_d)
+
+
#https://htmlcolorcodes.com/
-n0=generate_nodes(function_d, "#D7BDE2")
-n1=generate_nodes(addiction_d,"#A9CCE3")
-n2=generate_nodes(drug_d, "#A3E4D7")
-n3=generate_nodes(brain_d, "#F9E79F")
+n0=generate_nodes(function_d, 'function')
+n1=generate_nodes(addiction_d, 'addiction')
+n2=generate_nodes(drug_d, 'drug')
+n3=generate_nodes(brain_d, 'brain')
default_nodes=n0+n1+n2+n3