Skip to content

Commit 50910c5

Browse files
committed
copy develop to master working tree
1 parent a277f3d commit 50910c5

File tree

10 files changed

+102442
-310
lines changed

10 files changed

+102442
-310
lines changed

LICENSE.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Mann Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

docs/getting_started/create-new-project.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ This will print some warnings, which should be okay
4747

4848
Project creation
4949
----------------
50+
5051
**Browser**
5152

52-
Go to ``http://localhost:5000/apps/projectCreation``
53+
Navigate to project creation from the front page by pressing the button "PROJECT CREATION"
54+
or go to ``http://localhost:5000/apps/projectCreation``
5355

54-
This will direct you to the project creation page.
5556
Fill in your project information.
56-
Remember to press "Add" after selecting items from the drop-down menu (the page will update every time).
5757
Press "Create Project" (you will now be able to find your project in the neo4j database)
58-
Download the "Clinical Data template" and proceed to the 'Upload project experimental data'_.
58+
Download the "Clinical Data template" and proceed to 'Upload project experimental data'_.
5959

6060

6161
Other

docs/getting_started/upload-data.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ Follow this link to search for 'SNOWMED'_ terms:
3636
.. _SNOWMED: https://browser.ihtsdotools.org/?perspective=full&conceptId1=734000001&edition=MAIN/2019-07-31&release=&languages=en
3737
Example: To add a column with "Age" search for "age". This gives multiple matches, with the first one being: "Age (qualifier value), SCTID:397669002". Please enter this information as column header with the SCTID in brackets: Age (qualifier value) (397669002)
3838

39-
If you can't find your header in SNOWMED????
39+
If you can't find your header in SNOWMED you should contact annelaura.bach@cpr.ku.dk, put "Header Creation, CKG" in the subject.
40+
In the email please provide your "missing" header and a description of what it is.
4041

4142
**Proteomic data**
42-
43-
Do not perform any imputations or similar methods on your data before uploading it. This will be carried out in the CKG.
43+
Do not perform any imputations or similar on your data before uploading it. This will be carried out by the CKG.
4444

4545
Data from MaxQuant(DDA):
4646
Upload the proteinGroups.txt
47+
Upload
4748

4849
Data from Spectronaut(DIA):
4950
?

requirements.txt

+4-7
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ cvxpy==1.0.24
2727
cycler==0.10.0
2828
cyjupyter==0.2.0
2929
dabest==0.2.4
30+
dash-bio==0.4.5
3031
dash==1.2.0
3132
dash-auth==1.3.2
32-
dash-bio==0.1.1
33-
dash-bootstrap-components==0.7.1
34-
dash-core-components==1.1.2
3533
dash-cytoscape==0.1.1
36-
dash-html-components==1.0.1
37-
dash-renderer==1.0.1
38-
dash-table==4.2.0
39-
dask==2.0.0
4034
decorator==4.4.0
4135
defusedxml==0.6.0
4236
dill==0.2.9
@@ -211,3 +205,6 @@ bcrypt==3.1.7
211205
et-xmlfile==1.0.1
212206
jdcal==1.4.1
213207
openpyxl==3.0.1
208+
watchdog>=0.8.3
209+
sphinx-rtd-theme>=0.4.3
210+
recommonmark>=0.6.0

src/analytics_core/utils.py

+41-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def generate_html(network):
4545
conf=network.conf,
4646
tooltip_link=use_link_template)
4747

48-
def neoj_path_to_networkx(paths, key='path'):
48+
def neo4j_path_to_networkx(paths, key='path'):
4949
regex = r"\(?(.+)\)\<?\-\>?\[\:(.+)\s\{.*\}\]\<?\-\>?\((.+)\)?"
5050
nodes = set()
5151
rels = set()
5252
for r in paths:
53-
path = str(r[key])
53+
if key is not None:
54+
path = str(r[key])
5455
matches = re.search(regex, path)
5556
if matches:
5657
source = matches.group(1)
@@ -73,6 +74,37 @@ def neoj_path_to_networkx(paths, key='path'):
7374

7475
return G
7576

77+
def neo4j_schema_to_networkx(schema):
78+
regex = r"\(?(.+)\)\<?\-\>?\[\:(.+)\s\{.*\}\]\<?\-\>?\((.+)\)"
79+
nodes = set()
80+
rels = set()
81+
if 'relationships' in schema[0]:
82+
relationships = schema[0]['relationships']
83+
for relationship in relationships:
84+
matches = re.search(regex, str(relationship))
85+
if matches:
86+
source = matches.group(1)
87+
source_match = re.search(regex, source)
88+
if source_match:
89+
source = source_match.group(1)
90+
relationship = source_match.group(2)
91+
target = source_match.group(3)
92+
nodes.update([source, target])
93+
rels.add((source, target, relationship))
94+
source = target
95+
relationship = matches.group(2)
96+
target = matches.group(3)
97+
nodes.update([source, target])
98+
rels.add((source, target, relationship))
99+
G = nx.Graph()
100+
G.add_nodes_from(nodes)
101+
colors = dict(zip(nodes, get_hex_colors(len(nodes))))
102+
nx.set_node_attributes(G, colors, 'color')
103+
for s,t,label in rels:
104+
G.add_edge(s,t,label=label)
105+
106+
return G
107+
76108
def networkx_to_cytoscape(graph):
77109
cy_graph = json_graph.cytoscape_data(graph)
78110
cy_nodes = cy_graph['elements']['nodes']
@@ -83,6 +115,13 @@ def networkx_to_cytoscape(graph):
83115

84116
return cy_elements, mouseover_node
85117

118+
def networkx_to_gml(graph, path):
119+
nx.write_gml(graph, path)
120+
121+
def json_network_to_gml(graph_json, path):
122+
graph = json_network_to_networkx(graph_json)
123+
nx.write_gml(graph, path)
124+
86125
def json_network_to_networkx(graph_json):
87126
graph = json_graph.node_link_graph(graph_json)
88127

src/analytics_core/viz/viz.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ def get_network(data, identifier, args):
10741074
Example::
10751075
10761076
result = get_network(data, identifier='network', args={'source':'node1', 'target':'node2', 'cutoff':0.5, 'cutoff_abs':True, 'values':'weight', \
1077-
'node_size':'ev_centrality', 'title':'Network Figure', 'color_weight': True})
1077+
'node_size':'degree', 'title':'Network Figure', 'color_weight': True})
10781078
"""
10791079
net = None
10801080
if 'cutoff_abs' not in args:
@@ -1094,9 +1094,11 @@ def get_network(data, identifier, args):
10941094
data[args["values"]] = 1
10951095

10961096
data = data.rename(index=str, columns={args['values']: "width"})
1097-
data['edge_width'] = data['width'].apply(np.abs)
1098-
min_edge_value = data['edge_width'].min()
1099-
max_edge_value = data['edge_width'].max()
1097+
data = data.fillna('null')
1098+
data.columns = [c.replace('_', '') for c in data.columns]
1099+
data['edgewidth'] = data['width'].apply(np.abs)
1100+
min_edge_value = data['edgewidth'].min()
1101+
max_edge_value = data['edgewidth'].max()
11001102
graph = nx.from_pandas_edgelist(data, args['source'], args['target'], edge_attr=True)
11011103

11021104
degrees = dict(graph.degree())
@@ -1154,7 +1156,7 @@ def get_network(data, identifier, args):
11541156
edges_fig_table = get_table(edges_table, identifier=identifier+"_edges_table", title=args['title']+" edges table")
11551157

11561158
stylesheet, layout = get_network_style(colors, args['color_weight'])
1157-
stylesheet.append({'selector':'edge','style':{'width':'mapData(edge_width,'+ str(min_edge_value) +','+ str(max_edge_value) +', .5, 8)'}})
1159+
stylesheet.append({'selector':'edge','style':{'width':'mapData(edgewidth,'+ str(min_edge_value) +','+ str(max_edge_value) +', .5, 8)'}})
11581160
if min_node_size > 0 and max_node_size >0:
11591161
mapper = 'mapData(radius,'+ str(min_node_size) +','+ str(max_node_size) +', 15, 50)'
11601162
stylesheet.append({'selector':'node','style':{'width':mapper, 'height':mapper}})
@@ -1181,15 +1183,22 @@ def get_network_style(node_colors, color_edges):
11811183
'''
11821184

11831185
color_selector = "{'selector': '[name = \"KEY\"]', 'style': {'background-color': 'VALUE'}}"
1184-
stylesheet=[{'selector': 'node', 'style': {'label': 'data(name)'}},
1185-
{'selector':'edge','style':{'curve-style': 'bezier'}}]
1186+
stylesheet=[{'selector': 'node', 'style': {'label': 'data(name)',
1187+
'text-valign': 'center',
1188+
'text-halign': 'center',
1189+
'border-color':'gray',
1190+
'border-width': '1px',
1191+
'font-size': '12',
1192+
'opacity':0.75}},
1193+
{'selector':'edge','style':{'label':'data(label)',
1194+
'curve-style': 'bezier',
1195+
'opacity':0.7,
1196+
'font-size': '4'}}]
11861197

11871198
layout = {'name': 'cose',
11881199
'idealEdgeLength': 100,
11891200
'nodeOverlap': 20,
11901201
'refresh': 20,
1191-
#'fit': True,
1192-
#'padding': 30,
11931202
'randomize': False,
11941203
'componentSpacing': 100,
11951204
'nodeRepulsion': 400000,
@@ -1970,14 +1979,20 @@ def get_cytoscape_network(net, identifier, args):
19701979
* **layout** (dict) -- specifies how the nodes should be positioned on the screen.
19711980
:return: network figure within <div id="_dash-app-content">.
19721981
"""
1982+
height = '700px'
1983+
width = '100%'
1984+
if 'height' in args:
1985+
height = args['height']
1986+
if 'width' in args:
1987+
width = args['width']
19731988
cytonet = html.Div([html.H2(args['title']), cyto.Cytoscape(id=identifier,
19741989
stylesheet=args['stylesheet'],
19751990
elements=net,
19761991
layout=args['layout'],
19771992
minZoom = 0.2,
19781993
maxZoom = 1.5,
19791994
#mouseoverNodeData=args['mouseover_node'],
1980-
style={'width': '100%', 'height': '700px'}
1995+
style={'width': width, 'height': height}
19811996
)
19821997
])
19831998

src/graphdb_builder/builder/builder_config.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ experimentsDirectory: '../../../data/imports/experiments'
1212
databasesDirectory: '../../../data/imports/databases'
1313
#ontologies import diretory
1414
ontologiesDirectory: '../../../data/imports/ontologies'
15-
#users import directory
16-
usersDirectory: '../../../data/imports/users'
15+
#users directory
16+
usersDirectory: '../../../data/users'
17+
usersImportDirectory: '../../../data/imports/users'
1718

1819
download: True
1920

2021
cypher_queries_file: 'cypher.yml'
2122

23+
usersFile: 'CKG_users.xlsx'
24+
2225
statsFile: 'stats.hdf'
2326
statsCols:
2427
- 'date'
@@ -52,14 +55,14 @@ graph:
5255
- functional_regions
5356
- side effects
5457
- metabolite
58+
- protein_structure
5559
- food
5660
- gwas
5761
- pathway
5862
- published
5963
- user
6064
- project
6165
- experiment
62-
- protein_structure
6366

6467
#Imports
6568
ontology_entities:

src/graphdb_builder/builder/cypher.yml

+7
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,13 @@ IMPORT_DATASETS:
654654
'name': 'import clinical data'
655655
'description': 'Loads into the database all the clinical variables measured in a project'
656656
'query': >
657+
USING PERIODIC COMMIT 10000
658+
LOAD CSV WITH HEADERS FROM "file:///IMPORTDIR/PROJECTID_subject_had_intervention.tsv" AS line
659+
FIELDTERMINATOR '\t'
660+
MATCH (subject:Subject {id:line.START_ID})
661+
MATCH (intervention:Clinical_variable {id:line.END_ID})
662+
MERGE (subject)-[r:HAD_INTERVENTION{type:line.type, in_combination:line.in_combination, response:line.response}]->(intervention)
663+
RETURN COUNT(r) AS interventions;
657664
USING PERIODIC COMMIT 10000
658665
LOAD CSV WITH HEADERS FROM "file:///IMPORTDIR/PROJECTID_clinical_state.tsv" AS line
659666
FIELDTERMINATOR '\t'

src/graphdb_connector/query_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def find_queries_involving_nodes(queries, nodes, print_pretty=False):
3434
print("Query Name: ", query["name"])
3535
print("Description: ", query["description"])
3636
print("Involves nodes:", ",".join(query['involved_nodes']))
37-
print("Involves relationships:", ",".join(query['involved_nodes']))
37+
print("Involves relationships:", ",".join(query['involved_rels']))
3838
print("Query:\n", query["query"])
3939
if "example" in query:
40-
print("How to use it:\n", "\n".join(query["example"]))
40+
print("How to use it:\n", "\n".join(query["example"]), "\n")
4141

4242
return valid_queries
4343

src/notebooks/reporting/Urachal Carcinoma Case Study.ipynb

+102,328-279
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)