diff options
author | gunturkunhakan | 2021-06-30 23:23:58 -0500 |
---|---|---|
committer | gunturkunhakan | 2021-06-30 23:23:58 -0500 |
commit | eec87541da723543cfafe6f5b7cff1ec5774ba2e (patch) | |
tree | dfd6dfef9cee9bf80c8a24af9e9f4cd4da731f96 | |
parent | e4c91a690078535deb3f55cee3e20dcb229dd267 (diff) | |
download | genecup-eec87541da723543cfafe6f5b7cff1ec5774ba2e.tar.gz |
fixed a bug in search
-rwxr-xr-x | more_functions.py | 32 | ||||
-rwxr-xr-x | server.py | 4 |
2 files changed, 19 insertions, 17 deletions
diff --git a/more_functions.py b/more_functions.py index cb070d9..21d6cbc 100755 --- a/more_functions.py +++ b/more_functions.py @@ -23,21 +23,10 @@ def findWholeWord(w): return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search def getabstracts(gene,query): - if query[-1] =='s': - query2 = query+"*" - else: - query2 = query+"s*" - query3 = query2.replace("s|", "s* OR ") - query4 = query3.replace("|", "s* OR ") - - #query4=query - #query="\"(" + query4 + ") AND ((" + gene + "[tiab]) or (" + gene + "[meSH]))\"" - query="\"(" + query4 + ") AND (" + gene + " [tiab])\"" - #query = "neurons* AND (penk [tiab])" + query="\"(" + query + ") AND (" + gene + " [tiab])\"" abstracts = os.popen("esearch -db pubmed -query " + query \ + " | efetch -format uid |fetch-pubmed -path "+ pubmed_path \ + " | xtract -pattern PubmedArticle -element MedlineCitation/PMID,ArticleTitle,AbstractText|sed \"s/-/ /g\"").read() - #print(abstracts) return(abstracts) sentences_ls=[] @@ -57,6 +46,7 @@ def getSentences(gene, sentences_ls): def gene_category(gene, cat_d, cat, abstracts,addiction_flag,dictn): # e.g. BDNF, addiction_d, undic(addiction_d) "addiction" sents=getSentences(gene, abstracts) + #print(sents) #print(abstracts) out=str() if (addiction_flag==1): @@ -66,7 +56,12 @@ def gene_category(gene, cat_d, cat, abstracts,addiction_flag,dictn): key_ad = key+"*" else: key_ad = key+"s*" - if findWholeWord(key_ad)(sent) : + key_ad = key_ad.replace("s|", "s*|") + key_ad = key_ad.replace("|", "s*|") + key_ad = key_ad.replace("s*s*", "s*") + #if findWholeWord(key_ad)(sent) : + re_find = re.compile(r'\b{}\b'.format(key_ad), re.IGNORECASE) + if re_find.findall(sent): sent=sent.replace("<b>","").replace("</b>","") # remove other highlights sent=re.sub(r'\b(%s)\b' % key_ad, r'<b>\1</b>', sent, flags=re.I) # highlight keyword out+=gene+"\t"+ cat + "\t"+key+"\t"+sent+"\n" @@ -77,11 +72,17 @@ def gene_category(gene, cat_d, cat, abstracts,addiction_flag,dictn): key_2 = key_2+"*" else: key_2 = key_2+"s*" + key_2 = key_2.replace("s|", "s*|") + key_2 = key_2.replace("|", "s*|") + key_2 = key_2.replace("s*s*", "s*") for sent in sents.split("\n"): - if findWholeWord(key_2)(sent) : + re_find = re.compile(r'\b{}\b'.format(key_2), re.IGNORECASE) + #if findWholeWord(key_2)(sent) : + #if re.compile(r'\b(%s)\b' %key_2,sent, re.IGNORECASE): + if re_find.findall(sent): sent=sent.replace("<b>","").replace("</b>","") # remove other highlights sent=re.sub(r'\b(%s)\b' % key_2, r'<b>\1</b>', sent, flags=re.I) # highlight keyword - out+=gene+"\t"+ cat + "\t"+key_1+"\t"+sent+"\n" + out+=gene+"\t"+ cat + "\t"+key_1+"\t"+sent+"\n" return(out) def generate_nodes(nodes_d, nodetype,nodecolor): @@ -134,7 +135,6 @@ def generate_edges_json(data, filename): elif (edgeID not in edgeCnts) and (pmid+target not in pmid_list): edgeCnts[edgeID]=1 pmid_list.append(pmid+target) - for edgeID in edgeCnts: (filename, source,target)=edgeID.split("|") edges_json0+="{ \"id\": \"" + edgeID + "\", \"source\": \"" + source + "\", \"target\": \"" + target + "\", \"sentCnt\": \"" + str(edgeCnts[edgeID]) + "\", \"url\":\"/sentences?edgeID=" + edgeID + "\" },\n" @@ -851,6 +851,7 @@ def search(): yield "data:"+str(progress)+"\n\n" for gene in genes: abstracts_raw = getabstracts(gene,all_d) + #print(abstracts_raw) sentences_ls=[] for row in abstracts_raw.split("\n"): @@ -890,10 +891,11 @@ def search(): dict_onto=ast.literal_eval(onto_cont) #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())) + #print(sentences_ls) 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) |