From d453c78f6d7e65667d8cbeabcdafd36ce1a9a475 Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Mon, 13 May 2019 10:29:50 -0500 Subject: all links work now --- ratspub.py | 7 +- server.py | 32 +++++++- templates/topAddictionGene.html | 158 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+), 7 deletions(-) create mode 100644 templates/topAddictionGene.html diff --git a/ratspub.py b/ratspub.py index 355679c..79abc87 100755 --- a/ratspub.py +++ b/ratspub.py @@ -70,7 +70,6 @@ def gene_functional(gene): return(out) 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() for node in nodes_d: @@ -93,6 +92,7 @@ def generate_edges(data, filename): json0+="{ data: { id: '" + edgeID + "', source: '" + source + "', target: '" + target + "', sentCnt: " + str(edgeCnts[edgeID]) + ", url:'/sentences?edgeID=" + edgeID + "' } },\n" return(json0) +nodecolor={'function':"#A9CCE3", 'addiction': "#D7BDE2", 'drug': "#F9E79F", 'brain':"#A3E4D7"} addiction_d = {"reward":"reward|hedonic|incentive|intracranial self stimulation|ICSS|reinforcement|reinforcing|conditioned place preference|CPP|self administration|self administered|drug reinforced|operant|instrumental response", "aversion":"aversion|aversive|CTA|withdrawal|conditioned taste aversion", "relapse":"relapse|reinstatement|craving|drug seeking|seeking", @@ -101,7 +101,6 @@ addiction_d = {"reward":"reward|hedonic|incentive|intracranial self stimulation| "intoxication":"intoxication|binge" } addiction=undic(addiction_d) - drug_d = {"alcohol":"alcohol|alcoholism|alcoholic|alcoholics", "nicotine":"smoking|nicotine|tobacco|smoker|smokers", "cocaine":"cocaine", @@ -110,7 +109,6 @@ drug_d = {"alcohol":"alcohol|alcoholism|alcoholic|alcoholics", "cannabinoid":"endocannabinoid|cannabinoids|cannabis|endocannabinoids|marijuana|cannabidiol|cannabinoid|tetrahydrocannabinol|thc|thc 9|Oleoylethanolamide|palmitoylethanolamide|acylethanolamides" } drug=undic(drug_d) - brain_d ={"cortex":"cortex|prefrontal|pfc|mPFC|vmpfc|corticostriatal|cortico limbic|corticolimbic|prl|prelimbic|infralimbic|orbitofrontal|cingulate|cerebral|insular|insula", "striatum":"striatum|STR|striatal|caudate|putamen|basal ganglia|globus pallidus|GPI", "accumbens":"accumbens|accumbal|shell|core|Nacc|NacSh|acbs|acbc", @@ -120,7 +118,6 @@ 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={"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", @@ -129,8 +126,6 @@ function_d={"signalling":"signalling|signaling|phosphorylation|glycosylation", } function=undic(function_d) - - #https://htmlcolorcodes.com/ n0=generate_nodes(function_d, 'function') n1=generate_nodes(addiction_d, 'addiction') diff --git a/server.py b/server.py index 286f071..29aa66c 100755 --- a/server.py +++ b/server.py @@ -91,6 +91,32 @@ def sentences(): out+= "
") +## show the cytoscape graph for one gene from the top gene list +@app.route("/showTopGene") +def showTopGene(): + topGene=request.args.get('topGene') + topGeneSentFile="gene_addiction_sentences_cnt.tab" + with open(topGeneSentFile, "r") as sents: + catCnt={} + for sent in sents: + (symb, cat0, cat1, pmid, sent)=sent.split("\t") + if (symb == topGene) : + if cat1 in catCnt.keys(): + catCnt[cat1]+=1 + else: + catCnt[cat1]=1 + nodes= "{ data: { id: '" + topGene + "', nodecolor: '" + "#2471A3" + "', fontweight:700, url:'/progress?query="+topGene+"' } },\n" + edges=str() + for key in catCnt.keys(): + if ( key in drug_d.keys()): + nc=nodecolor["drug"] + else: + nc=nodecolor["addiction"] + nodes += "{ data: { id: '" + key + "', nodecolor: '" + nc + "', nodetype: 'top150', url:'/shownode?node="+key+"' } },\n" + edgeID=topGeneSentFile+"|"+topGene+"|"+key + edges+="{ data: { id: '" + edgeID+ "', source: '" + topGene + "', target: '" + key + "', sentCnt: " + str(catCnt[key]) + ", url:'/sentences?edgeID=" + edgeID + "' } },\n" + return render_template("cytoscape.html", elements=nodes+edges) + @app.route("/shownode") def shownode(): node=request.args.get('node') @@ -139,11 +165,15 @@ def gene_gene(): edges=str() for key in hitGenes.keys(): #nodes += "{ data: { id: '" + key + "', nodecolor: '" + nodecolor['top150'] + "', nodetype: 'top150', fontcolor:'#F2D7D5', url:'/shownode?nodetype=top150&node="+key+"' } },\n" - nodes += "{ data: { id: '" + key + "', nodecolor: '" + nodecolor['top150'] + "', nodetype: 'top150', url:'/shownode?nodetype=top150&node="+key+"' } },\n" + nodes += "{ data: { id: '" + key + "', nodecolor: '" + nodecolor['top150'] + "', nodetype: 'top150', url:'/showTopGene?topGene="+key+"' } },\n" edgeID=gg_file+"|"+query+"|"+key edges+="{ data: { id: '" + edgeID+ "', source: '" + query + "', target: '" + key + "', sentCnt: " + str(hitGenes[key]) + ", url:'/sentences?edgeID=" + edgeID + "' } },\n" return render_template("cytoscape.html", elements=nodes+edges) +## generate a page that lists all the top 150 addiction genes with links to cytoscape graph. +@app.route("/allTopGenes") +def top150genes(): + return render_template("topAddictionGene.html") if __name__ == '__main__': app.run(debug=True) diff --git a/templates/topAddictionGene.html b/templates/topAddictionGene.html new file mode 100644 index 0000000..0608378 --- /dev/null +++ b/templates/topAddictionGene.html @@ -0,0 +1,158 @@ +{% extends "layout.html" %} +{% block content %} + + + + +