-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidationLevelW.py
103 lines (88 loc) · 3.46 KB
/
validationLevelW.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# **************************************************************************
# *
# * Authors: Carlos Oscar Sorzano ([email protected])
# *
# * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# * 02111-1307 USA
# *
# * All comments concerning this program package may be sent to the
# * e-mail address '[email protected]'
# *
# **************************************************************************
import graphviz
import json
import os
import urllib.request
from validationReport import calculateSha256
def levelW(project, report, WORKFLOW, skipAnalysis=False):
secLabel = "sec:workflow"
if WORKFLOW.startswith("http"):
msgWorkflow = "\\url{%s}" % WORKFLOW
else:
# Get file basename to write it in the report
basenameWORKFLOW = os.path.basename(WORKFLOW)
msgWorkflow = basenameWORKFLOW.replace('_', '\_').replace('/', '/\-')
if WORKFLOW.startswith("http://nolan.cnb.csic.es"):
fnWorkflow = os.path.join(report.getReportDir(),"workflow.json")
urlWorkflow = WORKFLOW
if not urlWorkflow.endswith('.json'):
urlWorkflow="http://nolan.cnb.csic.es/cryoemworkflowviewer/static/uploadedFiles/%s/workflow.json"%\
WORKFLOW.split('/')[-1]
urllib.request.urlretrieve(urlWorkflow, fnWorkflow)
else:
fnWorkflow = WORKFLOW
msg = \
"""
\\section{Workflow}
\\label{%s}
Workflow file: %s \\\\
SHA256 hash: %s \\\\
\\\\
""" % (secLabel, msgWorkflow, calculateSha256(fnWorkflow))
report.write(msg)
fh = open(fnWorkflow)
workflow = json.load(fh)
fh.close()
dot = graphviz.Digraph()
# create nodes
for protocol in workflow:
dot.node(protocol['object.id'], protocol['object.label'])
# create edges
for protocol in workflow:
for key in protocol:
if 'input' in key:
source = protocol[key]
if isinstance(source, str):
source = source.split('.')[0]
dot.edge(source, protocol['object.id'])
if isinstance(source, list):
for s in source:
source = s.split('.')[0]
dot.edge(source, protocol['object.id'])
fnGraph = os.path.join(report.getReportDir(),"workflow.png")
dot.render(outfile=fnGraph, view=False)
msg=\
"""Fig. \\ref{fig:workflow} shows the image processing workflow followed in Scipion to achieve these results.
\\begin{figure}[H]
\centering
\includegraphics[width=15cm]{%s}
\\caption{Image processing workflow in Scipion to achieve these results.}
\\label{fig:workflow}
\\end{figure}
"""%fnGraph
report.write(msg)
report.writeWarningsAndSummary(None, "W Workflow", secLabel)