From eec87541da723543cfafe6f5b7cff1ec5774ba2e Mon Sep 17 00:00:00 2001 From: gunturkunhakan Date: Wed, 30 Jun 2021 23:23:58 -0500 Subject: fixed a bug in search --- more_functions.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'more_functions.py') 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("","").replace("","") # remove other highlights sent=re.sub(r'\b(%s)\b' % key_ad, r'\1', 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("","").replace("","") # remove other highlights sent=re.sub(r'\b(%s)\b' % key_2, r'\1', 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" -- cgit v1.2.3 From c08a7a39a6703422e94c6217fd8b19403f6010ab Mon Sep 17 00:00:00 2001 From: gunturkunhakan Date: Thu, 1 Jul 2021 22:03:04 -0500 Subject: fixed a bug --- more_functions.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'more_functions.py') diff --git a/more_functions.py b/more_functions.py index 21d6cbc..7c21c2a 100755 --- a/more_functions.py +++ b/more_functions.py @@ -59,12 +59,13 @@ def gene_category(gene, cat_d, cat, abstracts,addiction_flag,dictn): 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("","").replace("","") # remove other highlights - sent=re.sub(r'\b(%s)\b' % key_ad, r'\1', sent, flags=re.I) # highlight keyword - out+=gene+"\t"+ cat + "\t"+key+"\t"+sent+"\n" + key_ad_ls = key_ad.split('|') + for key_ad in key_ad_ls: + re_find = re.compile(r'\b{}\b'.format(key_ad), re.IGNORECASE) + if re_find.findall(sent): + sent=sent.replace("","").replace("","") # remove other highlights + sent=re.sub(r'\b(%s)\b' % key_ad, r'\1', sent, flags=re.I) # highlight keyword + out+=gene+"\t"+ cat + "\t"+key+"\t"+sent+"\n" else: for key_1 in dictn[cat_d].keys(): for key_2 in dictn[cat_d][key_1]: @@ -75,14 +76,14 @@ def gene_category(gene, cat_d, cat, abstracts,addiction_flag,dictn): key_2 = key_2.replace("s|", "s*|") key_2 = key_2.replace("|", "s*|") key_2 = key_2.replace("s*s*", "s*") + key_2_ls = key_2.split('|') for sent in sents.split("\n"): - 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("","").replace("","") # remove other highlights - sent=re.sub(r'\b(%s)\b' % key_2, r'\1', sent, flags=re.I) # highlight keyword - out+=gene+"\t"+ cat + "\t"+key_1+"\t"+sent+"\n" + for key_2 in key_2_ls: + re_find = re.compile(r'\b{}\b'.format(key_2), re.IGNORECASE) + if re_find.findall(sent): + sent=sent.replace("","").replace("","") # remove other highlights + sent=re.sub(r'\b(%s)\b' % key_2, r'\1', sent, flags=re.I) # highlight keyword + out+=gene+"\t"+ cat + "\t"+key_1+"\t"+sent+"\n" return(out) def generate_nodes(nodes_d, nodetype,nodecolor): -- cgit v1.2.3