Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 143 additions & 142 deletions flame/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,149 +401,146 @@ def dumpYAML (self):

return (yaml_out)

def dumpExcel (self,oname):

# openpyxl should be installed in the environment
# pip install openpyxl

from openpyxl import Workbook
from openpyxl.styles import Font,NamedStyle,Alignment
# from openpyxl.comments import Comment

wb = Workbook()
ws = wb.active
ws.title = f"Model {self.model} documentation"
alignment_style = Alignment(vertical='top',wrapText=True)

# Label Style
Label = NamedStyle(name="Label")
Label.font = Font(name='Calibri',size=11,bold=True)
Label.alignment = alignment_style

ws.column_dimensions['A'].width = 25.10
ws.column_dimensions['B'].width = 28.00
ws.column_dimensions['C'].width = 60.00
ws.column_dimensions['D'].width = 60.00
def dumpExcel(self,oname):


# sections of the document, specifying the document keys which will be listed
sections = [('General model information',['ID', 'Version', 'Model_title', 'Model_description', 'Keywords', 'Contact', 'Institution', 'Date', 'Endpoint',
'Endpoint_units', 'Interpretation', 'Dependent_variable', 'Species',
'Limits_applicability', 'Experimental_protocol', 'Model_availability',
'Data_info']),
('Algorithm and software',['Algorithm', 'Software', 'Descriptors', 'Algorithm_settings',
'AD_method', 'AD_parameters', 'Goodness_of_fit_statistics',
'Internal_validation_1', 'Internal_validation_2', 'External_validation',
'Comments']),
('Other information',['Other_related_models', 'Date_of_QMRF', 'Date_of_QMRF_updates',
'QMRF_updates', 'References', 'QMRF_same_models', 'Mechanistic_basis',
'Mechanistic_references', 'Supporting_information', 'Comment_on_the_endpoint',
'Endpoint_data_quality_and_variability', 'Descriptor_selection'])]
# openpyxl should be installed in the environment
# pip install openpyxl

#Save the position and name of the label for the first and last section
position = []
name = [sections[0][1][0],'Other Comments']

count = 1
for isection in sections:
from openpyxl import Workbook
from openpyxl.styles import Font,NamedStyle,Alignment

for ik in isection[1]:

label_k = ik.replace('_',' ')
wb = Workbook()
ws = wb.active
ws.title = f"Model {self.model} documentation"
alignment_style = Alignment(vertical='top',wrapText=True)

if label_k == 'Internal validation 2' or label_k == 'External validation':
ws[f"A{count}"] = label_k
ws[f'A{count}'].style = Label
else:
ws[f"B{count}"] = label_k
ws[f"B{count}"].style = Label

if ik in self.fields:
# set defaults for value
ivalue= ''
#v is the selected entry in the documentation dictionary
v = self.fields[ik]
# Label Style
Label = NamedStyle(name="Label")
Label.font = Font(name='Calibri',size=11,bold=True)
Label.alignment = alignment_style

ws.column_dimensions['A'].width = 25.10
ws.column_dimensions['B'].width = 28.00
ws.column_dimensions['C'].width = 60.00
ws.column_dimensions['D'].width = 60.00

# sections of the document, specifying the document keys which will be listed
sections = [('General model information',['ID', 'Version', 'Model_title', 'Model_description', 'Keywords', 'Contact', 'Institution', 'Date', 'Endpoint',
'Endpoint_units', 'Interpretation', 'Dependent_variable', 'Species',
'Limits_applicability', 'Experimental_protocol', 'Model_availability',
'Data_info']),
('Algorithm and software',['Algorithm', 'Software', 'Descriptors', 'Algorithm_settings',
'AD_method', 'AD_parameters', 'Goodness_of_fit_statistics',
'Internal_validation_1', 'Internal_validation_2', 'External_validation',
'Comments']),
('Other information',['Other_related_models', 'Date_of_QMRF', 'Date_of_QMRF_updates',
'QMRF_updates', 'References', 'QMRF_same_models', 'Mechanistic_basis',
'Mechanistic_references', 'Supporting_information', 'Comment_on_the_endpoint',
'Endpoint_data_quality_and_variability', 'Descriptor_selection'])]

#Save the position and name of the label for the first and last section
position = []
name = [sections[0][1][0],'Other Comments']

count = 1
for isection in sections:

for ik in isection[1]:

label_k = ik.replace('_',' ')

if label_k in ['Internal validation 2', 'External validation']:
ws[f"A{count}"] = label_k
ws[f'A{count}'].style = Label
else:
ws[f"B{count}"] = label_k
ws[f"B{count}"].style = Label

if ik in self.fields:
# set defaults for value
ivalue= ''
#v is the selected entry in the documentation dictionary
v = self.fields[ik]
## newest parameter formats are extended and contain
## rich metainformation for each entry
if 'value' in v:
ivalue = v['value']

if isinstance(ivalue,dict):
if 'value' in v:
ivalue = v['value']

ws[f"A{count}"] = label_k
ws[f"A{count}"].style = Label

end = (count)+(len(ivalue)-1)

for intk in ivalue:
label_ik = intk.replace('_',' ')
# label_ik = intk.replace('_f', '').replace('_', ' ')
ws[f'B{count}'] = label_ik
ws[f'B{count}'].style = Label


if isinstance(ivalue,dict):

ws[f"A{count}"] = label_k
ws[f"A{count}"].style = Label

end = (count)+(len(ivalue)-1)

for intk in ivalue:
label_ik = intk.replace('_',' ')
# label_ik = intk.replace('_f', '').replace('_', ' ')
ws[f'B{count}'] = label_ik
ws[f'B{count}'].style = Label


intv = ivalue[intk]
if not isinstance(intv,dict):

iivalue = intv
if iivalue is None:
iivalue = " "
else:
intv = ivalue[intk]
if not isinstance(intv,dict):

iivalue = intv
if iivalue is None:
iivalue = " "
else:
intv = ivalue[intk]
iivalue = ''
if 'value' in intv:
iivalue = intv["value"]
if iivalue is None:
iivalue = ''
if 'value' in intv:
iivalue = intv["value"]
if iivalue is None:
iivalue = ''

ws[f'D{count}'] = intv['description']
ws[f'D{count}'].alignment = alignment_style


ws[f'C{count}'] = f'{str(iivalue)}'
ws[f'C{count}'].font = Font(name='Calibri',size=11,color='3465a4')
ws[f'C{count}'].alignment = alignment_style

ws.merge_cells(f'A{count}:A{end}')

count +=1

else:

ws[f'D{count}'] = v['description']
ws[f'D{count}'].alignment = alignment_style
ws[f'D{count}'] = intv['description']
ws[f'D{count}'].alignment = alignment_style

if label_k == 'Experimental protocol' or label_k == 'Comments':
position.append(count)

if ivalue is None:
ivalue = ''

ws[f'C{count}'] = f'{str(ivalue)}'
ws[f'C{count}'] = f'{str(iivalue)}'
ws[f'C{count}'].font = Font(name='Calibri',size=11,color='3465a4')
ws[f'C{count}'].alignment = alignment_style


count += 1

itr = 0
for i in position:
if itr == 0:
ws[f'A{1}'] = name[itr]
ws[f"A{1}"].style = Label
ws.merge_cells(f'A{1}:A{i}')
else:
ws[f'A{i}'] = name[itr]
ws[f"A{i}"].style = Label
ws.merge_cells(f'A{i}:A{count-1}')
ws.merge_cells(f'A{count}:A{end}')

itr +=1
count +=1

try:
wb.save(oname)
except:
return False, f'error saving document as {oname}'

return True, 'OK'
else:

ws[f'D{count}'] = v['description']
ws[f'D{count}'].alignment = alignment_style

if label_k in ['Experimental protocol', 'Comments']:
position.append(count)

if ivalue is None:
ivalue = ''

ws[f'C{count}'] = f'{str(ivalue)}'
ws[f'C{count}'].font = Font(name='Calibri',size=11,color='3465a4')
ws[f'C{count}'].alignment = alignment_style


count += 1

for itr, i in enumerate(position):
if itr == 0:
ws['A1'] = name[itr]
ws['A1'].style = Label
ws.merge_cells(f'A1:A{i}')
else:
ws[f'A{i}'] = name[itr]
ws[f"A{i}"].style = Label
ws.merge_cells(f'A{i}:A{count-1}')

try:
wb.save(oname)
except:
return False, f'error saving document as {oname}'

return True, 'OK'

def dumpWORD (self, oname):

Expand Down Expand Up @@ -1069,27 +1066,31 @@ def empty_fields(self):
intv = ivalue[intk]
if not isinstance(intv,dict):
iivalue = intv
if iivalue is None or len(str(iivalue)) is 0:
if iivalue is None or not str(iivalue):
emptyfields.append(intk)

else:
intv = ivalue[intk]
iivalue = ''
if intv["value"] is None or len(str(intv["value"])) is 0:
if intv["value"] is None or not str(intv["value"]):
emptyfields.append(intk)

else:
if ivalue is None or len(str(ivalue)) is 0:
if ivalue is None or not str(ivalue):
emptyfields.append(ik)

return emptyfields

def get_mols(self):
def get_smiles(self):
''''''

return dict(zip(self.conveyor.getVal("obj_nam"),self.conveyor.getVal("SMILES")))



#dict(zip(self.conveyor.getVal("obj_nam"),self.conveyor.getVal("SMILES")))
return self.conveyor.getVal("SMILES")

def get_names(self):
''''''
return self.conveyor.getVal("obj_nam")

def autocomplete_documentation(self):
"""
Auto complete fields in model documentation
Expand All @@ -1101,8 +1102,11 @@ def autocomplete_documentation(self):
#Date, Date of model development and Date of QMRF.
today = date.today().strftime("%B %d, %Y")

self.fields['Date']['value'] = today
self.fields['Date_of_QMRF']['value'] = today
if not self.fields['Date']['value']:
self.fields['Date']['value'] = today

if not self.fields['Date_of_QMRF']['value']:
self.fields['Date_of_QMRF']['value'] = today

#format, Format used(SDF,TSV)
if self.parameters.getVal('input_type') == 'data':
Expand All @@ -1116,10 +1120,7 @@ def autocomplete_documentation(self):
fieldsapplysoftware = ['model','descriptors','applicability_domain']

for field in fieldsapplysoftware:
if field == 'applicability_domain':
if self.parameters.getVal('conformal'):
self.fields['Software']['value'][field]['value'] = software
else:
if field == 'applicability_domain' and self.parameters.getVal('conformal') or field != 'applicability_domain':
self.fields['Software']['value'][field]['value'] = software


Expand Down
8 changes: 5 additions & 3 deletions flame/util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

__modules__ = None

import os
import os
import sys
import yaml
import random
Expand All @@ -33,8 +33,10 @@
import codecs
import string
import re

from flame.util import get_logger
#from knowledgehub.api import KnowledgeHubAPI



LOG = get_logger(__name__)

Expand Down Expand Up @@ -463,4 +465,4 @@ def isFingerprint (md):
if md in fplist:
return True

return False
return False
Loading