From cea42615bd0c0c02bad574db42fc7c44c5ca5c66 Mon Sep 17 00:00:00 2001 From: hakangunturkun Date: Wed, 4 Mar 2020 12:02:15 -0600 Subject: fix 0 hit history view --- server.py | 82 ++++++++++++++++++++++++----------- templates/tableview.html | 106 ++++++++++++++++++++++++---------------------- templates/tableview0.html | 17 ++++---- 3 files changed, 123 insertions(+), 82 deletions(-) diff --git a/server.py b/server.py index 9003515..90e783e 100755 --- a/server.py +++ b/server.py @@ -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=" Notes:
  • Click on the abstract count to read sentences linking the keyword and the gene.
  • Click on a gene to search its relations with top 200 addiction genes.
  • Click on a keyword to see the terms included in the search.
  • View the results in a graph." - 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=" Notes:
  • These are the words that have zero abstract counts.
  • View all the results in a graph." - return render_template('tableview0.html', num_gene=num_gene,session_path = session['path'], jedges=jedges, jnodes=jnodes,gene_name=gene_name, message4=message4) + message4=" Notes:
  • These are the keywords that have zero abstract counts.
  • View all the results in a graph." + 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=" Notes:
  • Click on the keywords to see the indicated number of abstracts
  • Click on a gene to search its relations with top 200 addiction genes
  • Click on a keyword to see the terms included in the search
  • Hover your pointer over a node will hide other links
  • Nodes can be moved around for better visibility, reload the page will restore the original layout
  • View the results in a graph." - 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+= "
  • "+ text + " PMID:"+pmid+"
    " pmid_temp = pmid pmid_list.append(pmid+cat0) - out1="

    "+gene0 + " and " + cat0 + "


    \n" + out1="

    "+gene0 + " and " + cat0 + "

    \n" if len(pmid_list)>1: out2 = str(len(pmid_list)) + ' sentences in ' + str(len(pmid_list)) + ' studies' "
    \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 @@ {%if num_gene==1%} -

    GENE(S): {{gene_name}}

    +

    GENE: {{gene_name}}

    + {%if nodata_temp==1%} + No result was found. + {%endif%} {%else%}

    GENES: {{gene_name}}

    + {%if nodata_temp==1%} + No result was found. + {%endif%} {%endif%} - +{%if nodata_temp!=1%}