about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHao Chen2019-05-08 09:18:21 -0500
committerHao Chen2019-05-08 09:18:21 -0500
commitcd948b1ccf6781c17c9e4b4899ada9d654f16e83 (patch)
treedd49109cf838756a925c98e9207fada06d26792d
parent30a9a40ae3170f0a13efd394ac12e297d3eda03d (diff)
downloadgenecup-cd948b1ccf6781c17c9e4b4899ada9d654f16e83.tar.gz
showing sentences
-rwxr-xr-xratspub.py8
-rw-r--r--server.py29
-rw-r--r--templates/cytoscape.html97
-rw-r--r--templates/index.html4
-rw-r--r--templates/layout.html2
-rw-r--r--templates/sentences.html9
6 files changed, 99 insertions, 50 deletions
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'<b>\1</b>', sent, flags=re.I)
-                out+=pmid+"\t"+sent+"<br>\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+= "<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=out)
+
 if __name__ == '__main__':
     app.run(debug=True)
diff --git a/templates/cytoscape.html b/templates/cytoscape.html
index 24c18c1..ab30562 100644
--- a/templates/cytoscape.html
+++ b/templates/cytoscape.html
@@ -2,45 +2,68 @@
 {% block content %}
 
 <script type="text/javascript" src="{{ url_for('static', filename='cytoscape.min.js') }}"></script>
-
-
-    <div id="cy"></div>
-    <script>
-      var cy = cytoscape({
-        container: document.getElementById('cy'),
-
-		style: [
-			{ selector: 'node',
-			  css: {
-				'content': 'data(id)',
-				'text-valign': 'center',
-				'text-halign': 'center',
-                'background-color': 'data(nodecolor)',
-				'font-weight': 'data(fontweight)'
-			  }
-			},
-		
-			{ selector: 'edge',
-			  css: {
-				'content': 'data(sentCnt)',
-				'curve-style': 'bezier',
-    			"opacity": "0.4",
-			  }
+	<div id="cy"></div>
+	<script>
+		var cy = cytoscape({
+			container: document.getElementById('cy'),
+			style: [
+				{ selector: 'node',
+					css: {
+						'content': 'data(id)',
+						'text-valign': 'center',
+						'text-halign': 'center',
+						'background-color': 'data(nodecolor)',
+						'font-weight': 'data(fontweight)',
+						'font-size': '20%'
+					}
+				},
+				{ selector: 'edge',
+					css: {
+						'content': 'data(sentCnt)',
+						'curve-style': 'bezier'
+					}
+				},
+			{ selector: 'node.highlight',
+            style: {
+                'border-color': '#FFF',
+                'border-width': '2px'
+            }
+        },
+        {
+            selector: 'node.semitransp',
+            style:{ 'opacity': '0.5' }
+        },
+        {
+            selector: 'edge.highlight',
+            style: { 'mid-target-arrow-color': '#FFF' }
+        },
+        {
+            selector: 'edge.semitransp',
+            style:{ 'opacity': '0.2' }
+        }
+			],
+			elements:[ {{ elements | safe }} ], 
+			layout: {
+				name: 'circle'
 			}
-		],
-	    elements:[ {{ elements | safe }} ], 
-	
-	    layout: {
-			name: 'concentric',
-			concentric: function( node ){
-			  return node.degree();
-        	},
-			levelWidth: function( nodes ){
-			  return 2;
+		});
+		cy.on('tap', 'edge', function(){
+			try { // your browser may block popups
+				window.open( this.data('url') );
+			} catch(e){ // fall back on url change
+				window.location.href = this.data('url');
 			}
-      	},
-
-	  });
+	  	});
+		cy.on('mouseover', 'node', function(e){
+			var sel = e.target;
+			cy.elements().difference(sel.outgoers()).not(sel).addClass('semitransp');
+			sel.addClass('highlight').outgoers().addClass('highlight');
+		});
+		cy.on('mouseout', 'node', function(e){
+			var sel = e.target;
+			cy.elements().removeClass('semitransp');
+			sel.removeClass('highlight').outgoers().removeClass('highlight');
+		});
     </script>
 
 {% endblock %}
diff --git a/templates/index.html b/templates/index.html
index c7bafcd..4f19269 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -3,8 +3,8 @@
 
 
 <h3> Searching PubMed to find sentences related to addiction</h3>
-    <form class="form-inline my-2 my-lg-0" action="/network" method="POST">
-      <input name="query" class="form-control mr-sm-2" type="search" placeholder="Nrxn1" aria-label="search" value="Nrxn1">
+    <form class="form-inline my-2 my-lg-0" action="/search">
+      <input name="query" class="form-control mr-sm-2" type="search" placeholder="Rgma Nrxn3" aria-label="search" value="Rgma Nrxn3">
       <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
     </form>
 
diff --git a/templates/layout.html b/templates/layout.html
index 2887e2f..421798e 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -15,7 +15,7 @@
 <body>
 
 <nav class="navbar navbar-expand-lg navbar-light bg-light">
-  <a class="navbar-brand" href="#">GatPub</a>
+  <a class="navbar-brand" href="#">RatsPub</a>
   <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
     <span class="navbar-toggler-icon"></span>
   </button>
diff --git a/templates/sentences.html b/templates/sentences.html
new file mode 100644
index 0000000..c481817
--- /dev/null
+++ b/templates/sentences.html
@@ -0,0 +1,9 @@
+{% extends "layout.html" %}
+{% block content %}
+
+{{ sentences | safe }}
+    
+{% endblock %}
+
+
+