From fd0d852cc46ae5e23341358682e7d8e682c81414 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 22 Jun 2024 04:27:44 -0500 Subject: Add footer and version info --- server.py | 136 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 73 insertions(+), 63 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index 9d34bf9..191bebd 100755 --- a/server.py +++ b/server.py @@ -1,4 +1,7 @@ #!/bin/env python3 +# +# This is the main flask server + from __future__ import print_function import hashlib @@ -50,6 +53,14 @@ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+datadir+'userspub.sqlite' db = SQLAlchemy(app) nltk.data.path.append("./nlp/") +VERSION=None + +def version(): + if not VERSION: + with open("VERSION", 'r') as file: + VERSION = file.read() + return VERSION + # Sqlite database class users(db.Model): __tablename__='user' @@ -63,8 +74,8 @@ class users(db.Model): def clean_doc(doc, vocab): doc = doc.lower() tokens = doc.split() - re_punc = re.compile('[%s]' % re.escape(string.punctuation)) - tokens = [re_punc.sub('' , w) for w in tokens] + re_punc = re.compile('[%s]' % re.escape(string.punctuation)) + tokens = [re_punc.sub('' , w) for w in tokens] tokens = [word for word in tokens if len(word) > 1] stop_words = set(stopwords.words('english')) tokens = [w for w in tokens if not w in stop_words] @@ -109,7 +120,7 @@ def root(): ontoarchive() onto_len_dir = session['onto_len_dir'] onto_list = session['onto_list'] - else: + else: onto_len_dir = 0 onto_list = '' @@ -161,13 +172,13 @@ def signup(): if (found_user and (bcrypt.checkpw(password.encode('utf8'), found_user.password)==False)): flash("Already registered, but wrong password!", "inval") - return render_template('signup.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('signup.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) session['email'] = email session['hashed_email'] = hashlib.md5(session['email'] .encode('utf-8')).hexdigest() session['name'] = name password = bcrypt.hashpw(password.encode('utf8'), bcrypt.gensalt()) - user = users(name=name, email=email, password = password) + user = users(name=name, email=email, password = password) if found_user: session['email'] = found_user.email session['hashed_email'] = hashlib.md5(session['email'] .encode('utf-8')).hexdigest() @@ -219,10 +230,10 @@ def signin(): return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) else: flash("Invalid username or password!", "inval") - return render_template('signup.html') + return render_template('signup.html') return render_template('signin.html') -# change password +# change password @app.route("/", methods=["POST", "GET"]) def profile(nm_passwd): try: @@ -259,7 +270,7 @@ def profile(nm_passwd): return render_template("/passwd_change.html", name=user_name) else: return "This url does not exist" - else: + else: return "This url does not exist" except (AttributeError): return "This url does not exist" @@ -276,7 +287,7 @@ def logout(): global user1 if session['name'] != '': user1 = session['name'] - else: + else: user1 = session['email'] flash("You have been logged out, {user1}", "inval") session.pop('email', None) @@ -286,8 +297,7 @@ def logout(): @app.route("/about") def about(): - return render_template('about.html') - + return render_template('about.html',version=version()) # Ontology selection @app.route("/index_ontology", methods=["POST", "GET"]) @@ -376,7 +386,7 @@ def ontology(): keycat = keycat.replace('| ', '|') namecat=re.sub('[^,a-zA-Z0-9 \n]', '', namecat) - # Generate a unique session ID depending on timestamp to track the results + # Generate a unique session ID depending on timestamp to track the results timestamp = datetime.utcnow().replace(microsecond=0) timestamp = timestamp.replace(tzinfo=pytz.utc) timestamp = timestamp.astimezone(pytz.timezone("America/Chicago")) @@ -409,8 +419,8 @@ def ontology(): with open("addiction.onto","r") as f1: with open(session['namecat']+".onto", "w") as f2: for line in f1: - f2.write(line) - else: + f2.write(line) + else: f= open(session['namecat']+".onto","w") dict_onto={} else: @@ -425,8 +435,8 @@ def ontology(): flag_kw=0 if (',' in maincat) or (',' in subcat): flash("Only one word can be added to the category and subcategory at a time.","inval") - elif maincat in dict_onto.keys(): # Layer 2, main category - if subcat in dict_onto[maincat].keys(): # Layer 3, keywords shown in results + elif maincat in dict_onto.keys(): # Layer 2, main category + if subcat in dict_onto[maincat].keys(): # Layer 3, keywords shown in results keycat_ls = keycat.split('|') for kw in str.split(next(iter(dict_onto[maincat][subcat])), '|'): # Layer 4, synonyms for keycat_word in keycat_ls: @@ -462,7 +472,7 @@ def ontology(): flash("You must login to change the addiction ontology.") else: flash("You must login to create a new ontology.") - + if request.form['submit'] == 'remove': if ('email' in session): session['namecat']=namecat @@ -485,8 +495,8 @@ def ontology(): with open("addiction.onto","r") as f1: with open(session['namecat']+".onto", "w") as f2: for line in f1: - f2.write(line) - else: + f2.write(line) + else: f= open(session['namecat']+".onto","w") dict_onto={} @@ -498,10 +508,10 @@ def ontology(): dict_onto={} else: dict_onto=ast.literal_eval(onto_cont) - + flag_kw=0 - if maincat in dict_onto.keys(): # Layer 2, main category - if subcat in dict_onto[maincat].keys(): # Layer 3, keywords shown in results + if maincat in dict_onto.keys(): # Layer 2, main category + if subcat in dict_onto[maincat].keys(): # Layer 3, keywords shown in results for kw in str.split(next(iter(dict_onto[maincat][subcat])), '|'): keycat_ls = keycat.split('|') for keycat_word in keycat_ls: # Layer 4, synonyms @@ -516,11 +526,11 @@ def ontology(): dict_onto[maincat]=re.sub(r'\''+subcat+'\': \'{}\', ', '', str(dict_onto[maincat])) dict_onto[maincat]=re.sub(r'\''+subcat+'\': \'{}\'', '', str(dict_onto[maincat])) if '{}' in dict_onto[maincat]: - dict_onto=re.sub(r', \''+maincat+'\': \'{}\'', '', str(dict_onto)) + dict_onto=re.sub(r', \''+maincat+'\': \'{}\'', '', str(dict_onto)) dict_onto=str(dict_onto).replace('\"{','{') dict_onto=str(dict_onto).replace('}\"','}') dict_onto=str(dict_onto).replace('\'{','{') - dict_onto=str(dict_onto).replace('}\'','}') + dict_onto=str(dict_onto).replace('}\'','}') with open(session['namecat']+'.onto', 'w') as file3: file3.write(str(dict_onto)) if flag_kw==0: @@ -528,12 +538,12 @@ def ontology(): else: flash("\""+subcat+"\" is not a subcategory.","inval") else: - flash("\""+subcat+"\" is not a category.","inval") + flash("\""+subcat+"\" is not a category.","inval") else: if namecat=='addiction': flash("You must login to change the addiction ontology.") else: - flash("You must login to create a new ontology.") + flash("You must login to create a new ontology.") if 'namecat' in session: file2 = open(session['namecat']+".onto","r") @@ -570,7 +580,7 @@ def ontoarchive(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) else: session['user_folder'] = datadir+"/user/"+str(session['hashed_email']) else: @@ -584,10 +594,10 @@ def ontoarchive(): session_id=session['id'] def sorted_alphanumeric(data): convert = lambda text: int(text) if text.isdigit() else text.lower() - alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] + alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] return sorted(data, key=alphanum_key) - dirlist = sorted_alphanumeric(os.listdir(session['user_folder']+"/ontology/")) + dirlist = sorted_alphanumeric(os.listdir(session['user_folder']+"/ontology/")) onto_folder_list = [] onto_directory_list = [] onto_list=[] @@ -645,26 +655,26 @@ def progress(): if ('email' in session): onto_len_dir = session['onto_len_dir'] onto_list = session['onto_list'] - else: + else: onto_len_dir = 0 onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) message="Up to 200 terms can be searched at a time" return render_template('index.html' ,onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto, message=message) - + if len(genes)==0: if ('email' in session): onto_len_dir = session['onto_len_dir'] onto_list = session['onto_list'] - else: + else: onto_len_dir = 0 onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) message="Please enter a search term " return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto, message=message) - + tf_path=tempfile.gettempdir() genes_for_folder_name ="" if len(genes) == 1: @@ -680,7 +690,7 @@ def progress(): genes_for_folder_name =str(genes[0])+"_"+str(genes[1])+"_"+str(genes[2]) marker="_m" - # Generate a unique session ID depending on timestamp to track the results + # Generate a unique session ID depending on timestamp to track the results timestamp = datetime.utcnow().replace(microsecond=0) timestamp = timestamp.replace(tzinfo=pytz.utc) timestamp = timestamp.astimezone(pytz.timezone("America/Chicago")) @@ -737,7 +747,7 @@ def progress(): session['rnd'] = timeextension+"_0_"+genes_for_folder_name+marker+"_0_"+onto_name_archive rnd = session['rnd'] else: - rnd = "tmp" + ''.join(random.choice(string.ascii_letters) for x in range(6)) + rnd = "tmp" + ''.join(random.choice(string.ascii_letters) for x in range(6)) session['path']=tf_path+ "/" + rnd os.makedirs(session['path']) search_type = request.args.getlist('type') @@ -778,7 +788,7 @@ def search(): search_type = session['search_type'] temp_nodes = "" json_nodes = "{\"data\":[" - + n_num=0 d={} nodecolor={} @@ -817,7 +827,7 @@ def search(): nodes_list.append(nd) json_nodes += generate_nodes_json(dictionary[ky],str(ky),nodecolor[ky]) d["nj{0}".format(n_num)]='' - + json_nodes = json_nodes[:-2] json_nodes =json_nodes+"]}" def generate(genes, tf_name): @@ -828,7 +838,7 @@ def search(): progress=0 searchCnt=0 nodesToHide=str() - json_edges = str() + json_edges = str() #genes_or = ' [tiab] or '.join(genes) all_d='' @@ -864,7 +874,7 @@ def search(): sent_tok = pmid + ' ' + sent_tok sentences_ls.append(sent_tok) gene=gene.replace("-"," ") - + geneEdges = "" if namecat_flag==1: @@ -890,7 +900,7 @@ def search(): if namecat_flag==1: onto_cont = open(ses_namecat+".onto","r").read() dict_onto=ast.literal_eval(onto_cont) - #ky_d=undic(list(dict_onto[ky].values())) + #ky_d=undic(list(dict_onto[ky].values())) sent=gene_category(gene,ky,str(ky), sentences_ls, addiction_flag,dict_onto) else: #ky_d=undic(list(dict_onto[ky].values())) @@ -898,9 +908,9 @@ def search(): sent=gene_category(gene,ky,str(ky), sentences_ls, addiction_flag,dict_onto) #print(sent) yield "data:"+str(progress)+"\n\n" - + geneEdges += generate_edges(sent, tf_name) - json_edges += generate_edges_json(sent, tf_name) + json_edges += generate_edges_json(sent, tf_name) sentences+=sent if ("GWAS" in search_type): gwas_sent=[] @@ -909,7 +919,7 @@ def search(): | (datf["REPORTED GENE(S)"].str.contains('(?:\s|^)'+gene+'(?:\s|$)', flags=re.IGNORECASE))] print (datf_sub1) for nd2 in dict_onto['GWAS'].keys(): - for nd1 in dict_onto['GWAS'][nd2]: + for nd1 in dict_onto['GWAS'][nd2]: for nd in nd1.split('|'): gwas_text='' datf_sub = datf_sub1[datf_sub1['DISEASE/TRAIT'].str.contains('(?:\s|^)'+nd+'(?:\s|$)', flags=re.IGNORECASE)] @@ -925,11 +935,11 @@ def search(): with open(path_user+"gwas_results.tab", "a") as gwas_edges: gwas_edges.write(sn_file) geneEdges += cys - json_edges += gwas_json + json_edges += gwas_json # report progress immediately progress+=percent yield "data:"+str(progress)+"\n\n" - + if len(geneEdges) >0: edges+=geneEdges nodes+="{ data: { id: '" + gene + "', nodecolor:'#E74C3C', fontweight:700, url:'/synonyms?node="+gene+"'} },\n" @@ -941,7 +951,7 @@ def search(): progress=100 sntdata.write(sentences) sntdata.close() - cysdata.write(nodes+edges) + cysdata.write(nodes+edges) cysdata.close() zeroLinkNode.write(nodesToHide) zeroLinkNode.close() @@ -954,7 +964,7 @@ def search(): # Write edges to txt file in json format also in user folder with open(path_user+"edges.json", "w") as temp_file_edges: - temp_file_edges.write(json_edges) + temp_file_edges.write(json_edges) with open(path_user+"nodes.json", "w") as temp_file_nodes: temp_file_nodes.write(json_nodes) return Response(generate(genes, snt_file), mimetype='text/event-stream') @@ -987,7 +997,7 @@ def tableview(): for line in file_edges.readlines(): if ':' not in line: nodata_temp = 1 - else: + else: nodata_temp = 0 with open(datadir+gene_url_tmp +"/edges.json") as edgesjsonfile: jedges = json.load(edgesjsonfile) @@ -1010,7 +1020,7 @@ def tableview(): for line in file_edges.readlines(): if ':' not in line: nodata_temp = 1 - else: + else: nodata_temp = 0 with open(gene_url_tmp +"/edges.json") as edgesjsonfile: jedges = json.load(edgesjsonfile) @@ -1058,7 +1068,7 @@ def tableview0(): for line in file_edges.readlines(): if ':' not in line: nodata_temp = 1 - else: + else: nodata_temp = 0 with open(datadir+gene_url_tmp+"/edges.json") as edgesjsonfile: jedges = json.load(edgesjsonfile) @@ -1082,7 +1092,7 @@ def tableview0(): for line in file_edges.readlines(): if ':' not in line: nodata_temp = 1 - else: + else: nodata_temp = 0 with open(gene_url_tmp+"/edges.json") as edgesjsonfile: jedges = json.load(edgesjsonfile) @@ -1129,9 +1139,9 @@ def userarchive(): session_id=session['id'] def sorted_alphanumeric(data): convert = lambda text: int(text) if text.isdigit() else text.lower() - alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] + alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ] return sorted(data, key=alphanum_key) - dirlist = sorted_alphanumeric(os.listdir(session['user_folder'])) + dirlist = sorted_alphanumeric(os.listdir(session['user_folder'])) folder_list = [] directory_list = [] gene_list=[] @@ -1243,7 +1253,7 @@ def cytoscape(): genes_session_tmp=tf_path + "/" + genes_url rnd_url_tmp=tf_path +"/" + rnd_url message2="".format(rnd_url,genes_url) - + if ('email' in session): filename = rnd_url.split("_0_")[0] rnd_url_tmp = datadir+"/user/"+str(session['hashed_email'])+"/"+rnd_url+"/"+filename @@ -1293,7 +1303,7 @@ def sentences(): line = ' '.join(tokens) line = [line] tokenized_sent = tokenizer.texts_to_sequences(line) - tokenized_sent = pad_sequences(tokenized_sent, maxlen=max_length, padding='post') + tokenized_sent = pad_sequences(tokenized_sent, maxlen=max_length, padding='post') predict_sent = model.predict(tokenized_sent, verbose=0) percent_sent = predict_sent[0,0] if round(percent_sent) == 0: @@ -1329,10 +1339,10 @@ def sentences(): if(cat0=='stress'): out4 = predict_sent(text) if(out4 == 'pos'): - out_pred_pos = "
  • "+ text + " PMID:"+pmid+"
    " + out_pred_pos = "
  • "+ text + " PMID:"+pmid+"
    " out_pos += out_pred_pos else: - out_pred_neg = "
  • "+ text + " PMID:"+pmid+"
    " + out_pred_neg = "
  • "+ text + " PMID:"+pmid+"
    " out_neg += out_pred_neg out1="

    "+gene0 + " and " + cat0 + "

    \n" if len(pmid_list)>1: @@ -1383,18 +1393,18 @@ def synonyms(): node=node.upper() allnodes={**genes} try: - synonym_list = list(allnodes[node].split("|")) + synonym_list = list(allnodes[node].split("|")) session['synonym_list'] = synonym_list session['main_gene'] = node.upper() out="
  • "+ allnodes[node].replace("|", "
  • ") - synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) + synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) synonym_list_str +=';' + node case = 1 return render_template('genenames.html', case = case, gene = node.upper(), synonym_list = synonym_list, synonym_list_str=synonym_list_str) except: try: synonym_list = session['synonym_list'] - synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) + synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) synonym_list_str +=';' + node case = 1 return render_template('genenames.html', case=case, gene = session['main_gene'] , synonym_list = synonym_list, synonym_list_str=synonym_list_str) @@ -1443,7 +1453,7 @@ def gene_gene(): pmid = tiab.pop(0) tiab= " ".join(tiab) sentences = sent_tokenize(tiab) - ## keep the sentence only if it contains the gene + ## keep the sentence only if it contains the gene for sent in sentences: if findWholeWord(query)(sent): sent=re.sub(r'\b(%s)\b' % query, r'\1', sent, flags=re.I) @@ -1472,7 +1482,7 @@ def gene_gene(): sentword="sentences" topGeneHits[ "
  • " + "Show " + str(hitGenes[key]) + " " + sentword +" about "+query+" and "+key+"" ]=hitGenes[key] topSorted = [(k, topGeneHits[k]) for k in sorted(topGeneHits, key=topGeneHits.get, reverse=True)] - + for k,v in topSorted: results+=k saveResult=open(result_file, "w+") @@ -1480,7 +1490,7 @@ def gene_gene(): saveResult.close() progress=100 yield "data:"+str(progress)+"\n\n" - + # Start the run query=session['forTopGene'] return Response(generate(query), mimetype='text/event-stream') -- cgit 1.4.1 From ed6bc08db4a7d7d34d793ab7e3a5ba5bf02f6c4d Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 22 Jun 2024 04:58:01 -0500 Subject: Try smaller font for footer --- server.py | 2 +- templates/layout.html | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'server.py') diff --git a/server.py b/server.py index 191bebd..cd58c7e 100755 --- a/server.py +++ b/server.py @@ -56,7 +56,7 @@ nltk.data.path.append("./nlp/") VERSION=None def version(): - if not VERSION: + if VERSION is None: with open("VERSION", 'r') as file: VERSION = file.read() return VERSION diff --git a/templates/layout.html b/templates/layout.html index 814e5b6..ebae849 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -96,12 +96,17 @@ + -- cgit 1.4.1 From cd3746df84899720312aea1c3af833aa79ad1df6 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 22 Jun 2024 05:01:19 -0500 Subject: Make VERSION global --- server.py | 1 + 1 file changed, 1 insertion(+) (limited to 'server.py') diff --git a/server.py b/server.py index cd58c7e..331bb60 100755 --- a/server.py +++ b/server.py @@ -56,6 +56,7 @@ nltk.data.path.append("./nlp/") VERSION=None def version(): + global VERSION if VERSION is None: with open("VERSION", 'r') as file: VERSION = file.read() -- cgit 1.4.1 From e9438ef321c47409d47bbd0c363998094726b1b9 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 22 Jun 2024 05:23:42 -0500 Subject: Bulk add version info to template renderer --- server.py | 94 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index 331bb60..3cdb307 100755 --- a/server.py +++ b/server.py @@ -127,7 +127,7 @@ def root(): onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) @app.route("/login", methods=["POST", "GET"]) @@ -154,8 +154,8 @@ def login(): onto_list = session['onto_list'] else: flash("Invalid username or password!", "inval") - return render_template('signup.html') - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('signup.html',version=version()) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) @app.route("/signup", methods=["POST", "GET"]) @@ -173,7 +173,7 @@ def signup(): if (found_user and (bcrypt.checkpw(password.encode('utf8'), found_user.password)==False)): flash("Already registered, but wrong password!", "inval") - return render_template('signup.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('signup.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) session['email'] = email session['hashed_email'] = hashlib.md5(session['email'] .encode('utf-8')).hexdigest() @@ -199,12 +199,12 @@ def signup(): os.makedirs(session['user_folder']+"/ontology/") flash("Login Succesful!") - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) else: if 'email' in session: flash("Already Logged In!") - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) - return render_template('signup.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) + return render_template('signup.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) @app.route("/signin", methods=["POST", "GET"]) @@ -228,11 +228,11 @@ def signin(): onto_len_dir = session['onto_len_dir'] onto_list = session['onto_list'] dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) else: flash("Invalid username or password!", "inval") - return render_template('signup.html') - return render_template('signin.html') + return render_template('signup.html',version=version()) + return render_template('signin.html',version=version()) # change password @app.route("/", methods=["POST", "GET"]) @@ -258,7 +258,7 @@ def profile(nm_passwd): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) # remove reserved characters from the hashed passwords reserved = (";", "/", "?", ":", "@", "=", "&", ".") def replace_reserved(fullstring): @@ -268,7 +268,7 @@ def profile(nm_passwd): replaced_passwd = replace_reserved(str(found_user.password)) if replaced_passwd == user_passwd: - return render_template("/passwd_change.html", name=user_name) + return render_template("/passwd_change.html", name=user_name,version=version()) else: return "This url does not exist" else: @@ -293,12 +293,12 @@ def logout(): flash("You have been logged out, {user1}", "inval") session.pop('email', None) session.clear() - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) @app.route("/about") def about(): - return render_template('about.html',version=version()) + return render_template('about.html',version=version) # Ontology selection @app.route("/index_ontology", methods=["POST", "GET"]) @@ -319,7 +319,7 @@ def index_ontology(): dict_onto=ast.literal_eval(onto_cont) onto_len_dir = session['onto_len_dir'] onto_list = session['onto_list'] - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = session['namecat'], dict_onto=dict_onto ) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = session['namecat'], dict_onto=dict_onto ,version=version()) @app.route("/ontology", methods=["POST", "GET"]) @@ -567,7 +567,7 @@ def ontology(): else: onto_len_dir=0 onto_list='' - return render_template('ontology.html',dict_onto=dict_onto, namecat=name_to_html, onto_len_dir=onto_len_dir, onto_list=onto_list) + return render_template('ontology.html',dict_onto=dict_onto, namecat=name_to_html, onto_len_dir=onto_len_dir, onto_list=onto_list,version=version()) @app.route("/ontoarchive") @@ -581,7 +581,7 @@ def ontoarchive(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) else: session['user_folder'] = datadir+"/user/"+str(session['hashed_email']) else: @@ -590,7 +590,7 @@ def ontoarchive(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) session_id=session['id'] def sorted_alphanumeric(data): @@ -616,7 +616,7 @@ def ontoarchive(): session['onto_len_dir'] = onto_len_dir session['onto_list'] = onto_list message3="
    • Click on the Date/Time to view archived results.
    • The Date/Time are based on US Central time zone.
    " - return render_template('ontoarchive.html', onto_len_dir=onto_len_dir, onto_list = onto_list, onto_folder_list=onto_folder_list, onto_directory_list=onto_directory_list, session_id=session_id, message3=message3) + return render_template('ontoarchive.html', onto_len_dir=onto_len_dir, onto_list = onto_list, onto_folder_list=onto_folder_list, onto_directory_list=onto_directory_list, session_id=session_id, message3=message3,version=version()) # Remove an ontology folder @@ -632,7 +632,7 @@ def removeonto(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) @app.route('/progress') @@ -662,7 +662,7 @@ def progress(): onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) message="Up to 200 terms can be searched at a time" - return render_template('index.html' ,onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto, message=message) + return render_template('index.html' ,onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto, message=message,version=version()) if len(genes)==0: if ('email' in session): @@ -674,7 +674,7 @@ def progress(): onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) message="Please enter a search term " - return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto, message=message) + return render_template('index.html',onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto, message=message,version=version()) tf_path=tempfile.gettempdir() genes_for_folder_name ="" @@ -762,7 +762,7 @@ def progress(): genes_session += str(gen) + "_" genes_session = genes_session[:-1] session['query']=genes - return render_template('progress.html', url_in="search", url_out="cytoscape/?rnd="+rnd+"&genequery="+genes_session) + return render_template('progress.html', url_in="search", url_out="cytoscape/?rnd="+rnd+"&genequery="+genes_session,version=version()) @app.route("/search") @@ -991,7 +991,7 @@ def tableview(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) jedges ='' file_edges = open(datadir+gene_url_tmp +'/edges.json', 'r') @@ -1015,7 +1015,7 @@ def tableview(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) jedges ='' file_edges = open(gene_url_tmp +'/edges.json', 'r') for line in file_edges.readlines(): @@ -1039,7 +1039,7 @@ def tableview(): num_gene = gene_name.count(',')+1 message3="
    • Click on the abstract count to read sentences linking the keyword and the gene
    • Click on a keyword to see the terms included in the search.
    • View the results in a graph.
    Links will be preserved when the table is copy-n-pasted into a spreadsheet.".format(rnd_url,genes_url) - return render_template('tableview.html', genes_session_tmp = genes_session_tmp, nodata_temp=nodata_temp, num_gene=num_gene, jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3, rnd_url=rnd_url, genes_url=genes_url) + return render_template('tableview.html', genes_session_tmp = genes_session_tmp, nodata_temp=nodata_temp, num_gene=num_gene, jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3, rnd_url=rnd_url, genes_url=genes_url,version=version()) # Table for the zero abstract counts @@ -1062,7 +1062,7 @@ def tableview0(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) jedges ='' file_edges = open(datadir+gene_url_tmp+'/edges.json', 'r') @@ -1086,7 +1086,7 @@ def tableview0(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) jedges ='' file_edges = open(gene_url_tmp+'/edges.json', 'r') @@ -1112,7 +1112,7 @@ def tableview0(): gene_name = gene_name+added num_gene = gene_name.count(',')+1 message4=" Notes:
  • These are the keywords that have zero abstract counts.
  • View all the results in a graph. ".format(rnd_url,genes_url) - return render_template('tableview0.html',nodata_temp=nodata_temp, num_gene=num_gene, jedges=jedges, jnodes=jnodes,gene_name=gene_name, message4=message4) + return render_template('tableview0.html',nodata_temp=nodata_temp, num_gene=num_gene, jedges=jedges, jnodes=jnodes,gene_name=gene_name, message4=message4,version=version()) @app.route("/userarchive") @@ -1125,7 +1125,7 @@ def userarchive(): if ('email' in session): if os.path.exists(datadir+"/user/"+str(session['hashed_email'])) == False: flash("Search history doesn't exist!") - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) else: session['user_folder'] = datadir+"/user/"+str(session['hashed_email']) else: @@ -1135,7 +1135,7 @@ def userarchive(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) session_id=session['id'] def sorted_alphanumeric(data): @@ -1165,7 +1165,7 @@ def userarchive(): directory_list.append(filename) len_dir = len(directory_list) message3=" " - return render_template('userarchive.html', len_dir=len_dir, gene_list = gene_list, onto_list = onto_list, folder_list=folder_list, directory_list=directory_list, session_id=session_id, message3=message3) + return render_template('userarchive.html', len_dir=len_dir, gene_list = gene_list, onto_list = onto_list, folder_list=folder_list, directory_list=directory_list, session_id=session_id, message3=message3,version=version()) # Remove the search directory @@ -1181,7 +1181,7 @@ def remove(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) @app.route('/date', methods=['GET', 'POST']) @@ -1242,9 +1242,9 @@ def date(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) message3=" Links will be preserved when the table is copy-n-pasted into a spreadsheet.".format(select_date,genes_session) - return render_template('tableview.html',nodata_temp=nodata_temp, num_gene=num_gene,genes_session_tmp = genes_session_tmp, rnd_url=select_date ,jedges=jedges, jnodes=jnodes,gene_name=gene_name, genes_url=genes_session, message3=message3) + return render_template('tableview.html',nodata_temp=nodata_temp, num_gene=num_gene,genes_session_tmp = genes_session_tmp, rnd_url=select_date ,jedges=jedges, jnodes=jnodes,gene_name=gene_name, genes_url=genes_session, message3=message3,version=version()) @app.route('/cytoscape/') def cytoscape(): @@ -1267,7 +1267,7 @@ def cytoscape(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) with open(rnd_url_tmp+"_0link","r") as z: zeroLink=z.read() @@ -1285,13 +1285,13 @@ def cytoscape(): onto_list = '' onto_cont=open("addiction.onto","r").read() dict_onto=ast.literal_eval(onto_cont) - return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto) + return render_template('index.html', onto_len_dir=onto_len_dir, onto_list=onto_list, ontol = 'addiction', dict_onto = dict_onto,version=version()) with open(rnd_url_tmp+"_0link","r") as z: zeroLink=z.read() if (len(zeroLink)>0): message2+="No result was found for these genes: " + zeroLink + "" - return render_template('cytoscape.html', elements=elements, message2=message2) + return render_template('cytoscape.html', elements=elements, message2=message2,version=version()) @app.route("/sentences") @@ -1359,7 +1359,7 @@ def sentences(): elif(out_neg != "" and out_pos == ""): out = out1 +out2+stress_cellular+out_neg K.clear_session() - return render_template('sentences.html', sentences="
      "+out+"

    ") + return render_template('sentences.html', sentences="

      "+out+"

    ",version=version()) # Show the cytoscape graph for one gene from the top gene list @@ -1368,7 +1368,7 @@ def showTopGene(): query=request.args.get('topGene') nodesEdges=searchArchived('topGene',query, 'cys','','')[0] message2="

  • "+query + " is one of the top addiction genes.
  • An archived search is shown. Click on the blue circle to update the results and include keywords for brain region and gene function. The update may take a long time to finish. " - return render_template("cytoscape.html", elements=nodesEdges, message="Top addiction genes", message2=message2) + return render_template("cytoscape.html", elements=nodesEdges, message="Top addiction genes", message2=message2,version=version()) @app.route("/shownode") @@ -1385,7 +1385,7 @@ def shownode(): for ky in dictionary.keys(): if node in dictionary[ky].keys(): out="

    "+node.upper()+"


  • "+ next(iter(dictionary[ky][node])).replace("|", "
  • ") - return render_template('sentences.html', sentences=out+"

    ") + return render_template('sentences.html', sentences=out+"

    ",version=version()) @app.route("/synonyms") @@ -1401,23 +1401,23 @@ def synonyms(): synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) synonym_list_str +=';' + node case = 1 - return render_template('genenames.html', case = case, gene = node.upper(), synonym_list = synonym_list, synonym_list_str=synonym_list_str) + return render_template('genenames.html', case = case, gene = node.upper(,version=version()), synonym_list = synonym_list, synonym_list_str=synonym_list_str) except: try: synonym_list = session['synonym_list'] synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) synonym_list_str +=';' + node case = 1 - return render_template('genenames.html', case=case, gene = session['main_gene'] , synonym_list = synonym_list, synonym_list_str=synonym_list_str) + return render_template('genenames.html', case=case, gene = session['main_gene'] , synonym_list = synonym_list, synonym_list_str=synonym_list_str,version=version()) except: case = 2 - return render_template('genenames.html', gene = node, case = case) + return render_template('genenames.html', gene = node, case = case,version=version()) @app.route("/startGeneGene") def startGeneGene(): session['forTopGene']=request.args.get('forTopGene') - return render_template('progress.html', url_in="searchGeneGene", url_out="showGeneTopGene") + return render_template('progress.html', url_in="searchGeneGene", url_out="showGeneTopGene",version=version()) @app.route("/searchGeneGene") @@ -1501,13 +1501,13 @@ def gene_gene(): def showGeneTopGene (): with open(session['path']+"_ggResult", "r") as result_f: results=result_f.read() - return render_template('sentences.html', sentences=results+"


    ") + return render_template('sentences.html', sentences=results+"


    ",version=version()) # 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") + return render_template("topAddictionGene.html",version=version()) if __name__ == '__main__': -- cgit 1.4.1 From 7ea75737fb14cf7b5a57bc951916a42b0fe3562c Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 22 Jun 2024 05:26:14 -0500 Subject: Fix syntax --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server.py') diff --git a/server.py b/server.py index 3cdb307..ae9ffc3 100755 --- a/server.py +++ b/server.py @@ -1401,7 +1401,7 @@ def synonyms(): synonym_list_str = ';'.join([str(syn) for syn in synonym_list]) synonym_list_str +=';' + node case = 1 - return render_template('genenames.html', case = case, gene = node.upper(,version=version()), synonym_list = synonym_list, synonym_list_str=synonym_list_str) + return render_template('genenames.html', case = case, gene = node.upper(), version=version(), synonym_list = synonym_list, synonym_list_str=synonym_list_str) except: try: synonym_list = session['synonym_list'] -- cgit 1.4.1 From 3f1cdf10c4b986d0ac9b0d0eaf4cc0312eeba063 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 23 Jun 2024 04:12:40 -0500 Subject: Working footer - but still overlapping body --- .gitignore | 1 + VERSION | 2 +- server.py | 3 ++- static/style.css | 33 +++++++++++++++++++++++++++++++++ templates/layout.html | 18 ++++++------------ 5 files changed, 43 insertions(+), 14 deletions(-) (limited to 'server.py') diff --git a/.gitignore b/.gitignore index 355a0c3..eb52520 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .key +minipubmed/ diff --git a/VERSION b/VERSION index a7ee35a..65d5469 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.3 +1.8.4-pre1 diff --git a/server.py b/server.py index ae9ffc3..d691dd9 100755 --- a/server.py +++ b/server.py @@ -24,7 +24,8 @@ from flask import (Flask, Response, flash, jsonify, redirect, render_template, from flask_sqlalchemy import SQLAlchemy from numpy import array -nltk.download('punkt') +# nltk.download('punkt') -- let's not just download data + import pickle from collections import Counter from datetime import datetime diff --git a/static/style.css b/static/style.css index d4cc2ee..47b0e22 100644 --- a/static/style.css +++ b/static/style.css @@ -72,3 +72,36 @@ a:active { ul { margin-left:40px; } + +.main { + flex: 1; + padding: 30px 0; +} + +body +{ + display: flex; + min-height: 80vh; + flex-direction: column; + padding-bottom: 40px; +} + +footer { + color: white; + font-size: small; + padding: 3px 0; + position: absolute; + left: 0; + bottom: 0; + width: 100%; +} + +.footer a { + color: yellow; + text-decoration: none; + transition: color 0.3s ease; +} + +.footer a:hover { + color: #adb5bd; +} diff --git a/templates/layout.html b/templates/layout.html index fafbae9..ba064e1 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -91,30 +91,24 @@ {% endwith %}
    -

    +
    {% block content %}{% endblock %}
    - -- cgit 1.4.1 From 5b6f0991a24836a9d1b0eec90c0bc11a331c3b2a Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 23 Jun 2024 05:22:03 -0500 Subject: Disable footer for long pages --- server.py | 8 ++++---- templates/layout.html | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'server.py') diff --git a/server.py b/server.py index d691dd9..c0e734c 100755 --- a/server.py +++ b/server.py @@ -568,7 +568,7 @@ def ontology(): else: onto_len_dir=0 onto_list='' - return render_template('ontology.html',dict_onto=dict_onto, namecat=name_to_html, onto_len_dir=onto_len_dir, onto_list=onto_list,version=version()) + return render_template('ontology.html',no_footer=True, dict_onto=dict_onto, namecat=name_to_html, onto_len_dir=onto_len_dir, onto_list=onto_list,version=version()) @app.route("/ontoarchive") @@ -1040,7 +1040,7 @@ def tableview(): num_gene = gene_name.count(',')+1 message3="
    • Click on the abstract count to read sentences linking the keyword and the gene
    • Click on a keyword to see the terms included in the search.
    • View the results in a graph.
    Links will be preserved when the table is copy-n-pasted into a spreadsheet.".format(rnd_url,genes_url) - return render_template('tableview.html', genes_session_tmp = genes_session_tmp, nodata_temp=nodata_temp, num_gene=num_gene, jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3, rnd_url=rnd_url, genes_url=genes_url,version=version()) + return render_template('tableview.html', no_footer=True, genes_session_tmp = genes_session_tmp, nodata_temp=nodata_temp, num_gene=num_gene, jedges=jedges, jnodes=jnodes,gene_name=gene_name, message3=message3, rnd_url=rnd_url, genes_url=genes_url,version=version()) # Table for the zero abstract counts @@ -1360,7 +1360,7 @@ def sentences(): elif(out_neg != "" and out_pos == ""): out = out1 +out2+stress_cellular+out_neg K.clear_session() - return render_template('sentences.html', sentences="
      "+out+"

    ",version=version()) + return render_template('sentences.html', no_footer=True, sentences="

      "+out+"

    ",version=version()) # Show the cytoscape graph for one gene from the top gene list @@ -1508,7 +1508,7 @@ def showGeneTopGene (): # 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",version=version()) + return render_template("topAddictionGene.html",no_footer=True,version=version()) if __name__ == '__main__': diff --git a/templates/layout.html b/templates/layout.html index 951c950..3160de5 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -94,6 +94,7 @@ {% block content %}{% endblock %}

    +{% if not no_footer %}
    @@ -108,6 +109,7 @@
    +{% endif %} -- cgit 1.4.1