# Dead code removed from server.py -- gene-gene search routes # These routes were not referenced from any template. @app.route("/startGeneGene") def startGeneGene(): session['forTopGene']=request.args.get('forTopGene') return render_template('progress.html', url_in="searchGeneGene", url_out="showGeneTopGene",version=version()) @app.route("/searchGeneGene") def gene_gene(): if 'path' not in session: if 'email' not in session : tf_path_gg=tempfile.gettempdir() rnd_gg = "tmp_gg" + ''.join(random.choice(string.ascii_letters) for x in range(6)) session['path'] = tf_path_gg + "/" + rnd_gg os.makedirs(session['path'], exist_ok=True) else: if 'path_user' in session: session['path'] = session['path_user'] else: return "Error: User session path not found.", 500 tmp_ggPMID=session['path']+"_ggPMID" gg_file=session['path']+"_ggSent" result_file=session['path']+"_ggResult" def findWholeWord(w): return re.compile(r'(? \"{tmp_ggPMID}\"") top_gene_pmid_file = "topGene_uniq.pmid" if not os.path.exists(top_gene_pmid_file): print(f"Warning: {top_gene_pmid_file} not found. Gene-gene search might be affected.") open(top_gene_pmid_file, 'a').close() abstracts_cmd = f"comm -1 -2 \"{top_gene_pmid_file}\" \"{tmp_ggPMID}\" | fetch-pubmed -path \"{pubmed_path}\" | xtract -pattern PubmedArticle -element MedlineCitation/PMID,ArticleTitle,AbstractText | sed \"s/-/ /g\"" try: abstracts_process = os.popen(abstracts_cmd) abstracts = abstracts_process.read() abstracts_process.close() except Exception as e_abs: print(f"Error getting abstracts for gene-gene search: {e_abs}") abstracts = "" if os.path.exists(tmp_ggPMID): os.system(f"rm \"{tmp_ggPMID}\"") progress=10 yield "data:"+str(progress)+"\n\n" topGenes=dict() out_str=str() hitGenes=dict() top_gene_alias_file = "topGene_symb_alias.txt" if os.path.exists(top_gene_alias_file): with open(top_gene_alias_file, "r") as top_f: for line in top_f: parts = line.strip().split("\t") if len(parts) == 2: symb, alias = parts topGenes[symb]=alias.replace("; ","|") else: print(f"Warning: {top_gene_alias_file} not found. Top gene list will be empty.") allAbstracts= abstracts.split("\n") abstractCnt=len(allAbstracts) if abstracts else 0 rowCnt=0 for row in allAbstracts: if not row.strip(): continue rowCnt+=1 if abstractCnt > 0 and rowCnt % 10 == 0 : progress=10+round(rowCnt/abstractCnt,2)*80 yield "data:"+str(progress)+"\n\n" tiab_parts=row.split("\t", 1) if len(tiab_parts) < 2: continue pmid = tiab_parts[0] tiab_text_gg = tiab_parts[1] sentences_gg = sent_tokenize(tiab_text_gg) for sent_item in sentences_gg: if findWholeWord(query)(sent_item): sent_item=re.sub(r'\b(%s)\b' % query, r'\1', sent_item, flags=re.I) for symb_item in topGenes: allNames=symb_item+"|"+topGenes[symb_item] if findWholeWord(allNames)(sent_item) : sent_item=sent_item.replace("","").replace("","") sent_item=re.sub(r'\b(%s)\b' % allNames, r'\1', sent_item, flags=re.I) out_str+=query+"\t"+"gene\t" + symb_item+"\t"+pmid+"\t"+sent_item+"\n" if symb_item in hitGenes: hitGenes[symb_item]+=1 else: hitGenes[symb_item]=1 progress=95 yield "data:"+str(progress)+"\n\n" with open(gg_file, "w+") as gg: gg.write(out_str) results_html="
No results found.
" result_file_path = session.get('path', '') + "_ggResult" if result_file_path and os.path.exists(result_file_path): with open(result_file_path, "r") as result_f: results_content=result_f.read() else: print(f"Warning: Result file {result_file_path} not found for showGeneTopGene.") return render_template('sentences.html', sentences=results_content+"
",no_footer=True,version=version())