From 636e2166164a56cf26361dd4369526c2ac45663d Mon Sep 17 00:00:00 2001
From: Hao Chen
Date: Mon, 6 May 2019 10:45:20 -0500
Subject: three types of searches
---
.gitignore | 1 +
get_addiction_sentences.py | 92 ++++++++++++++++++++++++++++++----------------
2 files changed, 61 insertions(+), 32 deletions(-)
create mode 100644 .gitignore
mode change 100644 => 100755 get_addiction_sentences.py
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..355a0c3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.key
diff --git a/get_addiction_sentences.py b/get_addiction_sentences.py
old mode 100644
new mode 100755
index 30a8e50..e24f122
--- a/get_addiction_sentences.py
+++ b/get_addiction_sentences.py
@@ -7,29 +7,9 @@ import sys
gene=sys.argv[1]
-addiction_terms="sensitization|intake|addiction|drug abuse|relapse|self-administered|self-administration|voluntary|reinstatement|binge|intoxication|withdrawal|chronic"
-
-drugs="alcohol|alcoholism|smoking|nicotine|tobacco|methamphetamine|amphetamine|cocaine|opioid|fentanyl|oxycodone|oxycontin|heroin|morphine|marijuana|cannabinoid|tetrahydrocannabinol|thc"
-
-brain_regions="cortex|accumbens|striatum|amygadala|hippocampus|tegmental|mesolimbic|infralimbic|prelimbic"
-
-brain_d ={"cortex":"cortex|pfc|vmpfc|il|pl|prelimbic|infralimbic",
- "striatum":"striatum|STR",
- "accumbens":"shell|core|NAcc|acbs|acbc",
- "hippocampus":"hippocampus|hipp|hip|ca1|ca3|dentate|gyrus",
- "amygadala":"amygadala|cea|bla|amy",
- "ventral tegmental":"ventral tegmental|vta"
- }
-
-function="LTP|LTD|plasticity|regulate|glutamate|GABA|cholinergic|serotoninergic|synaptic|methylation|transcription|phosphorylation"
-
-drugs_d = {"alcohol":"alcohol|alcoholism",
- "nicotine":"smoking|nicotine|tobacco",
- "amphetamine":"methamphetamine|amphetamine",
- "cocaine":"cocaine",
- "opioid":"opioid|fentanyl|oxycodone|oxycontin|heroin|morphine",
- "cannabinoid":"marijuana|cannabinoid|Tetrahydrocannabinol|thc"
- }
+## turn dictionary (synonyms) to regular expression
+def undic(dic):
+ return "|".join(dic.keys())+"|"+"|".join(dic.values())
def findWholeWord(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
@@ -42,6 +22,7 @@ def getSentences(query):
pmid = tiab.pop(0)
tiab= " ".join(tiab)
sentences = sent_tokenize(tiab)
+ ## keep the sentence only if it contains the gene
for sent in sentences:
if findWholeWord(gene)(sent):
sent=re.sub(r'\b(%s)\b' % gene, r'\1', sent, flags=re.I)
@@ -49,32 +30,79 @@ def getSentences(query):
return(out)
def gene_addiction(gene):
- q="\"(" + addiction_terms.replace("|", " OR ") + ") AND (" + drugs.replace("|", " OR ", ) + ") AND " + gene + "\""
+ # search gene name & drug name in the context of addiction terms (i.e., exclude etoh affects cancer, or methods to extract cocaine)
+ q="\"(" + addiction.replace("|", " OR ") + ") AND (" + drugs.replace("|", " OR ", ) + ") AND " + gene + "\""
sents=getSentences(q)
out=str()
for sent in sents.split("\n"):
for drug0 in drugs_d:
if findWholeWord(drugs_d[drug0])(sent) :
sent=re.sub(r'\b(%s)\b' % drugs_d[drug0], r'\1', sent, flags=re.I)
- out+=gene+"\t"+drug0+"\t"+sent+"\n"
+ out+=gene+"\t"+"drug\t" + drug0+"\t"+sent+"\n"
+ for add0 in addiction.split("|"):
+ if findWholeWord(add0)(sent) :
+ sent=re.sub(r'\b(%s)\b' % add0, r'\1', sent, flags=re.I)
+ out+=gene+"\t"+"addiction\t"+add0+"\t"+sent+"\n"
return(out)
-def gene_brainRegion(gene):
- q="\"(" + brain_regions.replace("|", " OR ") + ") AND " + gene + "\""
+def gene_anatomical(gene):
+ q="\"(" + brain.replace("|", " OR ") + ") AND " + gene + "\""
sents=getSentences(q)
out=str()
for sent in sents.split("\n"):
for brain0 in brain_d:
if findWholeWord(brain_d[brain0])(sent) :
sent=re.sub(r'\b(%s)\b' % brain_d[brain0], r'\1', sent, flags=re.I)
- out+=gene+"\t"+brain0+"\t"+sent+"\n"
+ out+=gene+"\t"+"brain\t"+brain0+"\t"+sent+"\n"
+ return(out)
+
+def gene_biological(gene):
+ q="\"(" + biological.replace("|", " OR ") + ") AND " + gene + "\""
+ sents=getSentences(q)
+ out=str()
+ for sent in sents.split("\n"):
+ for bio0 in biological_d:
+ if findWholeWord(biological_d[bio0])(sent) :
+ sent=re.sub(r'\b(%s)\b' % biological_d[bio0], r'\1', sent, flags=re.I)
+ out+=gene+"\t"+"function\t"+bio0+"\t"+sent+"\n"
return(out)
+addiction="reward|reinforcement|sensitization|intake|addiction|drug abuse|relapse|self-administered|self-administration|reinstatement|binge|intoxication|withdrawal|conditioned place preference|aversion|aversive|CPP"
+
+drugs_d = {"alcohol":"alcohol|alcoholism",
+ "nicotine":"smoking|nicotine|tobacco",
+ "amphetamine":"methamphetamine|amphetamine",
+ "cocaine":"cocaine",
+ "opioid":"opioid|fentanyl|oxycodone|oxycontin|heroin|morphine",
+ "cannabinoid":"marijuana|cannabinoid|Tetrahydrocannabinol|thc"
+ }
+drugs=undic(drugs_d)
+
+brain_d ={"cortex":"cortex|pfc|vmpfc|il|pl|prelimbic|infralimbic",
+ "striatum":"striatum|STR",
+ "accumbens":"shell|core|NAcc|acbs|acbc",
+ "hippocampus":"hippocampus|hipp|hip|ca1|ca3|dentate|gyrus",
+ "amygadala":"amygadala|cea|bla|amy",
+ "vta":"ventral tegmental|vta|pvta"
+ }
+# brain region has too many short acronyms to just use the undic function, so search PubMed using the following
+brain="cortex|accumbens|striatum|amygadala|hippocampus|tegmental|mesolimbic|infralimbic|prelimbic"
+
+biological_d={"plasticity":"LTP|LTD|plasticity|synaptic|epsp|epsc",
+ "neurotransmission": "neurotransmission|glutamate|GABA|cholinergic|serotoninergic",
+ "signalling":"signalling|phosphorylation|glycosylation",
+# "regulation":"increased|decreased|regulated|inhibited|stimulated",
+ "transcription":"transcription|methylation|histone|ribosome",
+ }
+biological=undic(biological_d)
+
report=str()
-out=gene_addiction(gene)
-report+=out
-out=gene_brainRegion(gene)
-report+=out
+out0=gene_addiction(gene)
+report+=out0
+out1=gene_anatomical(gene)
+report+=out1
+out2=gene_biological(gene)
+report+=out2
with codecs.open(gene+"_addiction_sentences.tab", "w", encoding='utf8') as writer:
writer.write(report)
writer.close()
--
cgit v1.2.3