def action_model_template(model, version=None, doc_file=None): ''' Returns a TSV model reporting template ''' from flame.documentation import Documentation documentation = Documentation(model, version, context='model') if not model: return False, 'Empty model label' # get de model repo path rdir = utils.model_path(model, version) if not os.path.isfile(os.path.join(rdir, 'results.pkl')): # compatibity method. use info.pkl if not os.path.isfile(os.path.join(rdir, 'info.pkl')): return False, 'Info file not found' else: # new method, use results.pkl if not os.path.isfile(os.path.join(rdir, 'results.pkl')): return False, 'Info file not found' if doc_file is not None: # use the param_file to update existing parameters at the model # directory and save changes to make them persistent success, message = documentation.delta(model, 0, doc_file, iformat='YAML') print(success, message) documentation.get_upf_template2() return True, 'Model documentation template created'
def action_documentation(model, version=None, doc_file=None, oformat='YAML'): ''' Returns an object with whole results info for a given model and version ''' if model is None: return False, 'Empty model label' from flame.documentation import Documentation # get de model repo path rdir = utils.model_path(model, version) if not os.path.isfile(os.path.join(rdir, 'model-results.pkl')): return False, 'Info file not found' doc = Documentation(model, version) # INPUT, the doc_file will be applied to doc as a delta if doc_file is not None: success, message = doc.delta(model, version, doc_file, iformat=oformat) return success, message # CONSOLE PRINTING if oformat == 'YAML': yaml = doc.dumpYAML() for line in yaml: line = line.encode("ascii", "ignore") line = line.decode("ascii", "ignore") print(line) return True, 'parameters listed' # OUTPUT, the doc will be returened as a documentation object return True, doc
def action_prediction_template(model, version=None): ''' Returns a TSV model reporting template ''' from flame.documentation import Documentation if not model: return False, 'Empty model label' documentation = Documentation(model, version, context='prediction') documentation.get_prediction_template() return True, 'Prediction template created'
def verify_documentation(endpoint, version=None): ''' Check that the required fields are completed ''' blacklist = [ 'Species', 'Limits_applicability', 'Experimental_protocol', 'location', 'description', 'endpoint_positive', 'endpoint_negative', 'raw_data_url', 'test_set_size', 'training_set_url', 'test_set_url', 'bootstrap', 'ccp_alpha', 'criterion', 'max_depth', 'max_features', 'max_leaf_nodes', 'max_samples', 'min_impurity_decrease', 'min_impurity_split', 'min_samples_leaf', 'min_samples_split', 'min_weight_fraction_leaf', 'n_estimators', 'n_jobs', 'oob_score', 'random_state', 'verbose', 'warm_start', 'confidence', 'ACP_sampler', 'KNN_NN', 'aggregated', 'aggregation_function', 'conformal_predictors', 'normalizing_model', 'Conformal_mean_interval', 'Conformal_accuracy', 'Q2', 'SDEP', 'Comments', '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', 'Internal_validation_2', 'External_validation' ] if endpoint is None: return False, 'Empty model label' # get de model repo path rdir = utils.model_path(endpoint, version) if not os.path.isfile(os.path.join(rdir, 'model-results.pkl')): return False, 'Info file not found' doc = Documentation(endpoint, version) fields = [field for field in doc.empty_fields() if field not in blacklist] if fields: result = { 'status': 'Failed', 'comments': 'fields not completed', 'Information': fields } else: result = { 'status': 'Passed', 'comments': 'All fields required are completed', 'Information': [] } return True, result
def action_documentation(model, version=None, doc_file=None, oformat='text'): ''' Returns an object with whole results info for a given model and version ''' if model is None: return False, 'Empty model label' from flame.documentation import Documentation # get de model repo path rdir = utils.model_path(model, version) if not os.path.isfile(os.path.join(rdir, 'model-results.pkl')): return False, 'Info file not found' doc = Documentation(model, version) if doc_file is not None: if oformat == 'JSONS': # use the param string to update existing parameters at the model # directory and save changes to make them persistent success, message = doc.delta(model, 0, doc_file, iformat='JSONS') return True, 'OK' else: # use the param_file to update existing parameters at the model # directory and save changes to make them persistent success, message = doc.delta(model, 0, doc_file, iformat='YAML') if not success: return False, message doc = Documentation(model, version) if oformat != 'text': return True, doc else: order = [ 'ID', 'Version', 'Contact', 'Institution', 'Date', 'Endpoint', 'Endpoint_units', 'Interpretation', 'Dependent_variable', 'Species', 'Limits_applicability', 'Experimental_protocol', 'Model_availability', 'Data_info', 'Algorithm', 'Software', 'Descriptors', 'Algorithm_settings', 'AD_method', 'AD_parameters', 'Goodness_of_fit_statistics', 'Internal_validation_1', 'Internal_validation_2', 'External_validation', 'Comments', 'Other_related_models', 'Date_of_QMRF', 'Data_of_QMRF_updates', 'QMRF_updates', 'References', 'QMRF_same_models', 'Comment_on_the_endpoint', 'Endpoint_data_quality_and_variability', 'Descriptor_selection' ] for ik in order: if ik in doc.fields: k = ik v = doc.fields[k] ivalue = '' idescr = '' ioptio = '' ## newest parameter formats are extended and contain ## rich metainformation for each entry if 'value' in v: if not isinstance(v['value'], dict): ivalue = v['value'] else: # print header of dictionary print(f'{k} :') # iterate keys assuming existence of value and description for intk in v['value']: intv = v['value'][intk] if not isinstance(intv, dict): print(f' {intk:27} : {str(intv):30}' ) #{iioptio} {iidescr}') else: #print(intk) intv = v['value'][intk] iivalue = '' if "value" in intv: iivalue = intv["value"] # else: # iivalue = intv iidescr = '' if "description" in intv and intv[ "description"] is not None: iidescr = intv["description"] iioptio = '' if 'options' in intv: toptio = intv['options'] if isinstance(toptio, list): if toptio != [None]: iioptio = f' {toptio}' if isinstance(iivalue, float): iivalue = f'{iivalue:f}' elif iivalue is None: iivalue = '' print( f' {intk:27} : {str(iivalue):30} #{iioptio} {iidescr}' ) continue if 'description' in v: idescr = v['description'] if 'options' in v: toptio = v['options'] if isinstance(toptio, list): ioptio = f' {toptio}' print(f'{k:30} : {str(ivalue):30} #{ioptio} {idescr}') return True, 'parameters listed'