-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (68 loc) · 3.49 KB
/
Copy pathmain.py
File metadata and controls
86 lines (68 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from dash import Dash, Input, Output, State, html, dcc, dash_table, callback
import webbrowser
app = Dash(__name__, title='COST Pubmed Customizer')
app.layout = html.Div(id = 'div1'
,children = [
html.H1("COST Homecage Pubmed Search Customizer")
, html.Br()
, dcc.Checklist(id="checkboxes",
options=[
{'label': 'Homecage', 'value': 'home'},
{'label': 'Automated', 'value': 'auto'},
{'label': 'Activity', 'value': 'activity'},
{'label': 'Behavior', 'value': 'behav'},
{'label': 'Phenotype', 'value': 'pheno'},
],
value=['home'])
, html.Br()
, html.P("Custom terms", style={'display': 'inline-block'})
, dcc.Input(id="custom", type="text", value="", style={'marginLeft':'10px', 'display': 'inline-block'})
, html.Br()
, html.P("Search string")
# , dcc.Input(id='searchstring', type="text", value="", style={'display': 'inline-block'})
, html.Div(id='searchstring', children="", style={'display': 'inline-block'})
, dcc.Clipboard(target_id="searchstring", style={'marginLeft':'10px', 'display': 'inline-block'})
, html.Br()
, html.Br()
, html.Button('Open Pubmed', id='pubmed_btn', n_clicks=0)
, html.Div(id='btn_pressed', children="")
]
)
@app.callback(Output('searchstring', 'children'),
Input('checkboxes', 'value'),
Input('custom', 'value')
)
def render_searchstring(checkboxes, custom):
return generate_searchstring(checkboxes, custom)
@app.callback(Output('btn_pressed', 'children'),
Input('pubmed_btn', 'n_clicks'),
State('checkboxes', 'value'),
State('custom', 'value'))
def open_pubmed(nclicks, checkboxes, custom):
if nclicks > 0:
webbrowser.open(generate_searchstring(checkboxes, custom))
return "Pubmed search opened in different tab"
def generate_searchstring(checkboxes, custom):
combiner = ' AND '
substrings = {}
if 'auto' in checkboxes:
substrings["auto"] = 'automat*'
if 'home' in checkboxes:
substrings["homecage"] = '("home cage" OR "homecage" OR "home-cage")'
if 'activity' in checkboxes:
substrings["activity"] = '(activity OR monitoring)'
if 'behav' in checkboxes:
substrings["behavior"] = '("behavior" OR "behaviour")'
if 'pheno' in checkboxes:
substrings["pheno"] = 'phenotyping'
pubmed_search_string = 'https://pubmed.ncbi.nlm.nih.gov/?term='
for substring in substrings.values():
pubmed_search_string = pubmed_search_string + substring + combiner
pubmed_search_string = pubmed_search_string.strip("AND ")
# need to try removing trailing ANDs, could consider mocing custom to end if easier
if len(custom) > 0:
pubmed_search_string = pubmed_search_string + combiner + custom
return pubmed_search_string
if __name__ == '__main__':
# app.run_server(host='0.0.0.0', port=8080, debug=True)
app.run_server(debug=True, dev_tools_hot_reload=True)