diff options
-rwxr-xr-x | server.py | 82 | ||||
-rw-r--r-- | templates/tableview.html | 106 | ||||
-rw-r--r-- | templates/tableview0.html | 17 |
3 files changed, 123 insertions, 82 deletions
@@ -370,8 +370,16 @@ def search(): def tableview(): with open("json_nodes.txt") as jsonfile: jnodes = json.load(jsonfile) - with open("json_edges.txt") as edgesjsonfile: - jedges = json.load(edgesjsonfile) + jedges ='' + file_edges = open('json_edges.txt', 'r') + for line in file_edges.readlines(): + if ':' not in line: + nodata_temp = 1 + else: + nodata_temp = 0 + with open("json_edges.txt") as edgesjsonfile: + jedges = json.load(edgesjsonfile) + break genename=session['query'] if len(genename)>3: genename = genename[0:3] @@ -384,14 +392,22 @@ def tableview(): gene_name = gene_name+added num_gene = gene_name.count(',')+1 message3="<b> Notes: </b><li> Click on the abstract count to read sentences linking the keyword and the gene. <li> Click on a gene to search its relations with top 200 addiction genes. <li> Click on a keyword to see the terms included in the search. <li>View the results in <a href='cytoscape'><b> a graph.</b></a>" - return render_template('tableview.html', num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3) + return render_template('tableview.html', nodata_temp=nodata_temp, num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3) @app.route("/tableview0") def tableview0(): with open("json_nodes.txt") as jsonfile: jnodes = json.load(jsonfile) - with open("json_edges.txt") as edgesjsonfile: - jedges = json.load(edgesjsonfile) + jedges ='' + file_edges = open('json_edges.txt', 'r') + for line in file_edges.readlines(): + if ':' not in line: + nodata_temp = 1 + else: + nodata_temp = 0 + with open("json_edges.txt") as edgesjsonfile: + jedges = json.load(edgesjsonfile) + break genename=session['query'] if len(genename)>3: genename = genename[0:3] @@ -403,8 +419,8 @@ def tableview0(): gene_name=gene_name.replace("'","") gene_name = gene_name+added num_gene = gene_name.count(',')+1 - message4="<b> Notes: </b><li> These are the words that have <b>zero</b> abstract counts. <li>View all the results in <a href='cytoscape'><b> a graph.</b></a>" - return render_template('tableview0.html', num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message4=message4) + message4="<b> Notes: </b><li> These are the keywords that have <b>zero</b> abstract counts. <li>View all the results in <a href='cytoscape'><b> a graph.</b></a>" + return render_template('tableview0.html',nodata_temp=nodata_temp, num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message4=message4) @app.route("/userarchive") def userarchive(): @@ -452,6 +468,7 @@ def date(): if ('email' in session): time_extension = str(select_date) time_extension = time_extension.split('_0_')[0] + gene_name1 = str(select_date).split('_0_')[1] time_extension = time_extension.replace(':', '_') time_extension = time_extension.replace('-', '_') session['path'] = tf_path+"/"+str(session['email'])+"/"+select_date+"/"+time_extension @@ -469,24 +486,41 @@ def date(): temp_file.write(line) with open("json_nodes.txt", "r") as jsonfile: jnodes = json.load(jsonfile) - with open("json_edges.txt", "r") as edgesjsonfile: - jedges = json.load(edgesjsonfile) + + jedges ='' + file_edges = open('json_edges.txt', 'r') + for line in file_edges.readlines(): + if ':' not in line: + nodata_temp = 1 + else: + nodata_temp = 0 + with open("json_edges.txt") as edgesjsonfile: + jedges = json.load(edgesjsonfile) + break gene_list=[] - for p in jedges['data']: - if p['source'] not in gene_list: - gene_list.append(p['source']) - if len(gene_list)>3: - gene_list = gene_list[0:3] - added = ",..." - else: - added = "" - gene_name = str(gene_list)[1:] - gene_name=gene_name[:-1] - gene_name=gene_name.replace("'","") - gene_name = gene_name+added - num_gene = gene_name.count(',')+1 + if nodata_temp == 0: + for p in jedges['data']: + if p['source'] not in gene_list: + gene_list.append(p['source']) + if len(gene_list)>3: + gene_list = gene_list[0:3] + added = ",..." + else: + added = "" + gene_name = str(gene_list)[1:] + gene_name=gene_name[:-1] + gene_name=gene_name.replace("'","") + gene_name = gene_name+added + num_gene = gene_name.count(',')+1 + else: + gene_name1 = gene_name1.replace("_", ", ") + gene_name = gene_name1 + num_gene = gene_name1.count(',')+1 + for i in range(0,num_gene): + gene_list.append(gene_name1.split(',')[i]) + session['query'] = gene_list message3="<b> Notes: </b><li>Click on the keywords to see the indicated number of abstracts <li> Click on a gene to search its relations with top 200 addiction genes<li>Click on a keyword to see the terms included in the search<li>Hover your pointer over a node will hide other links <li>Nodes can be moved around for better visibility, reload the page will restore the original layout<li> View the results in <a href='cytoscape'><b>a graph.</b></a>" - return render_template('tableview.html', title='', date=select_date, num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3) + return render_template('tableview.html', title='',nodata_temp=nodata_temp, date=select_date, num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3) @app.route('/cytoscape') def cytoscape(): @@ -515,7 +549,7 @@ def sentences(): out3+= "<li> "+ text + " <a href=\"https://www.ncbi.nlm.nih.gov/pubmed/?term=" + pmid +"\" target=_new>PMID:"+pmid+"<br></a>" pmid_temp = pmid pmid_list.append(pmid+cat0) - out1="<h3>"+gene0 + " and " + cat0 + "</h3><hr>\n" + out1="<h3>"+gene0 + " and " + cat0 + "</h3>\n" if len(pmid_list)>1: out2 = str(len(pmid_list)) + ' sentences in ' + str(len(pmid_list)) + ' studies' "<hr>\n" else: diff --git a/templates/tableview.html b/templates/tableview.html index d60f435..15b39ca 100644 --- a/templates/tableview.html +++ b/templates/tableview.html @@ -4,12 +4,18 @@ <script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.6.0/cytoscape.min.js" integrity="sha256-uZV2wRlscgr52q3Wb3Oew0rKCPsM3g4aBTv46sF4qzg=" crossorigin="anonymous"></script> <head> {%if num_gene==1%} - <h2> <b>GENE(S): {{gene_name}}</b> </h2> + <h2> <b>GENE: {{gene_name}}</b> </h2> + {%if nodata_temp==1%} + <b>No result was found.</b> + {%endif%} {%else%} <h2> <b>GENES: {{gene_name}}</b> </h2> + {%if nodata_temp==1%} + <b>No result was found.</b> + {%endif%} {%endif%} </head> - +{%if nodata_temp!=1%} <style> * { box-sizing: border-box; @@ -53,54 +59,54 @@ {{ message3 |safe}} </div> </div> - -<script>{ - {} - var table = document.getElementById("myTable"); - var header = table.createTHead(); - var row = header.insertRow(0); - var cell = row.insertCell(0); - cell.innerHTML = "<b>Gene</b>"; - var cell = row.insertCell(1); - cell.innerHTML = "<b>Abstract Count</b>"; - var cell = row.insertCell(2); - cell.innerHTML = "<b>Keyword</b>"; - var cell = row.insertCell(3); - cell.innerHTML = "<b>Category</b>"; - - {%for p in jedges['data']%} - var x=document.getElementById('myTable').insertRow(1); - source = '{{p['source']}}'; - target = '{{p['target']}}'; - var y= x.insertCell(0); - {%for p1 in jnodes['data']%} - {%if p['target'] == p1['id']%} - color='{{p1['nodecolor']}}' - type='{{p1['nodetype']}}' + <script>{ + {} + var table = document.getElementById("myTable"); + var header = table.createTHead(); + var row = header.insertRow(0); + var cell = row.insertCell(0); + cell.innerHTML = "<b>Gene</b>"; + var cell = row.insertCell(1); + cell.innerHTML = "<b>Abstract Count</b>"; + var cell = row.insertCell(2); + cell.innerHTML = "<b>Keyword</b>"; + var cell = row.insertCell(3); + cell.innerHTML = "<b>Category</b>"; + + {%for p in jedges['data']%} + var x=document.getElementById('myTable').insertRow(1); + source = '{{p['source']}}'; + target = '{{p['target']}}'; + var y= x.insertCell(0); + {%for p1 in jnodes['data']%} + {%if p['target'] == p1['id']%} + color='{{p1['nodecolor']}}' + type='{{p1['nodetype']}}' + {%endif%} + {%endfor%} + {%if 'GWAS' in p['target']%} + color="#AEB6BF" + type='GWAS' + key_gwas = target.replace("_GWAS","") + this_url1 = 'sentences?edgeID=gwas_addiction.tab|'+source+'|'+target; + this_url2 = 'https://www.ebi.ac.uk/gwas/search?query='+key_gwas; + {%else%} + this_url1 = 'sentences?edgeID='+'{{session_path}}'+'_snt|'+source+'|'+target; + this_url2 = 'shownode?nodetype='+type+'&node='+target; {%endif%} - {%endfor%} - {%if 'GWAS' in p['target']%} - color="#AEB6BF" - type='GWAS' - key_gwas = target.replace("_GWAS","") - this_url1 = 'sentences?edgeID=gwas_addiction.tab|'+source+'|'+target; - this_url2 = 'https://www.ebi.ac.uk/gwas/search?query='+key_gwas; - {%else%} - this_url1 = 'sentences?edgeID='+'{{session_path}}'+'_snt|'+source+'|'+target; - this_url2 = 'shownode?nodetype='+type+'&node='+target; - {%endif%} - genegene_url = '/startGeneGene?forTopGene='+source; - y.innerHTML="<a href='"+genegene_url+"'>{{p['source']}}</a>"; - y= x.insertCell(1); - y.innerHTML="<center> <a href='"+this_url1+"'> {{p['sentCnt']}}</a> </center>"; - y= x.insertCell(2); - y.innerHTML="<a href='"+this_url2+"'>{{p['target']}}</a>"; - y= x.insertCell(3); - y.innerHTML=type; - {% endfor %} -} -</script> - -<a href="/tableview0">Check</a> for searches that has <b>zero</b> abstract counts. + genegene_url = '/startGeneGene?forTopGene='+source; + y.innerHTML="<a href='"+genegene_url+"'>{{p['source']}}</a>"; + y= x.insertCell(1); + y.innerHTML="<center> <a href='"+this_url1+"'> {{p['sentCnt']}}</a> </center>"; + y= x.insertCell(2); + y.innerHTML="<a href='"+this_url2+"'>{{p['target']}}</a>"; + y= x.insertCell(3); + y.innerHTML=type; + {% endfor %} + } + </script> +{%endif%} +<br> +<a href="/tableview0">Review</a> searches that have <b>zero</b> abstract counts. {%endblock%} diff --git a/templates/tableview0.html b/templates/tableview0.html index c0299ce..a81f412 100644 --- a/templates/tableview0.html +++ b/templates/tableview0.html @@ -2,14 +2,14 @@ {% block content %} <script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.6.0/cytoscape.min.js" integrity="sha256-uZV2wRlscgr52q3Wb3Oew0rKCPsM3g4aBTv46sF4qzg=" crossorigin="anonymous"></script> + <head> {%if num_gene==1%} - <h2> <b>GENE(S): {{gene_name}}</b> </h2> + <h2> <b>GENE: {{gene_name}}</b> </h2> {%else%} <h2> <b>GENES: {{gene_name}}</b> </h2> {%endif%} </head> - <style> * { box-sizing: border-box; @@ -70,12 +70,13 @@ var x=document.getElementById('myTable').insertRow(1); control=0; - {%for p1 in jedges['data']%} - {%if p1['target'] == p['id']%} - control=1 - {%endif%} - {%endfor%} - + {%if nodata_temp!=1%} + {%for p1 in jedges['data']%} + {%if p1['target'] == p['id']%} + control=1 + {%endif%} + {%endfor%} + {%endif%} if(control !=1){ y= x.insertCell(0); y.innerHTML='{{p['id']}}'; |