diff --git a/ihm_validation/cx.py b/ihm_validation/cx.py index 3d1d31f2..33620a1f 100644 --- a/ihm_validation/cx.py +++ b/ihm_validation/cx.py @@ -68,7 +68,8 @@ def infinite_defaultdict(): return defaultdict(infinite_defaultdict) class CxValidation(GetInputInformation): def __init__(self, mmcif_file): super().__init__(mmcif_file) - self.ID = str(self.get_id()) + self.ID = self.get_id() + self.ID_f = self.get_file_id() self.nos = self.get_number_of_models() self.dataset = self.get_dataset_comp() # Only atomic structures are supported so far @@ -863,7 +864,7 @@ def plot_distograms_per_model_group(self, imgDirname='.'): def save_plots(self, plot, title, imgDirname='.'): imgpath = Path( imgDirname, - f'{self.ID}_{title}.html') + f'{self.ID_f}_{title}.html') save( plot, imgpath, resources=CDN, @@ -872,7 +873,7 @@ def save_plots(self, plot, title, imgDirname='.'): imgpath_json = Path( imgDirname, - f'{self.ID}_{title}.json') + f'{self.ID_f}_{title}.json') with open(imgpath_json, 'w') as f: json.dump(json_item(plot, title), f) diff --git a/ihm_validation/excludedvolume.py b/ihm_validation/excludedvolume.py index 782108fd..89931942 100644 --- a/ihm_validation/excludedvolume.py +++ b/ihm_validation/excludedvolume.py @@ -21,7 +21,8 @@ class GetExcludedVolume(GetInputInformation): def __init__(self, mmcif_file, cache): super().__init__(mmcif_file) - self.ID = Path(self.mmcif_file).stem + self.ID = self.get_id() + self.ID_f = self.get_file_id() self.nos = self.get_number_of_models() self.cache = cache @@ -156,7 +157,7 @@ def get_exc_vol_given_sphere_parallel(self, sphere_list: list) -> (float, int): def run_exc_vol_parallel(self, model_dict: dict) -> dict: """ get exc vol info in parallel """ # list_of_sphere_list=list(model_dict.values()) - filename = str(Path(self.cache, self.ID + '_exv.txt')) + filename = str(Path(self.cache, self.ID_f + '_exv.txt')) if os.path.exists(filename): return self.process_exv(filename) diff --git a/ihm_validation/get_plots.py b/ihm_validation/get_plots.py index 728c4c5d..8599a232 100644 --- a/ihm_validation/get_plots.py +++ b/ihm_validation/get_plots.py @@ -31,7 +31,8 @@ class Plots(GetInputInformation): def __init__(self, mmcif, imageDirName, driver): super().__init__(mmcif) - self.ID = str(GetInputInformation.get_id(self)) + self.ID = self.get_id() + self.ID_f = self.get_file_id() self.dirname = os.path.dirname(os.path.abspath(__file__)) self.imageDirName = imageDirName self.filename = os.path.join(self.imageDirName) @@ -41,7 +42,7 @@ def plot_quality_at_glance(self, molprobity_data: dict, exv_data: dict, sas_data: dict, sas_fit: dict, cx_fit: dict) -> bokeh.plotting.figure: # create tabs list to add all the panel figures (model quality, data quality.. etc) - output_file(self.ID+"quality_at_glance.html", mode="inline") + output_file(self.ID_f+ "_" + "quality_at_glance.html", mode="inline") # MODEL QUALITY # check for molprobity or excluded volume data @@ -99,7 +100,7 @@ def plot_quality_at_glance(self, molprobity_data: dict, exv_data: dict, plots.append(p) export_svg(p, filename=self.filename+'/' + - self.ID+'_' + str(i) + "_quality_at_glance_MQ.svg", webdriver=self.driver) + self.ID_f + "_" + str(i) + "_quality_at_glance_MQ.svg", webdriver=self.driver) grid = gridplot(plots, ncols=1, @@ -166,7 +167,7 @@ def plot_quality_at_glance(self, molprobity_data: dict, exv_data: dict, plots.append(p) export_svg(p, filename=self.filename+'/' + - self.ID+'_' + str(i) + "_quality_at_glance_MQ.svg", webdriver=self.driver) + self.ID_f + "_" + str(i) + "_quality_at_glance_MQ.svg", webdriver=self.driver) grid = gridplot(plots, ncols=1, merge_tools=True, @@ -207,9 +208,9 @@ def plot_quality_at_glance(self, molprobity_data: dict, exv_data: dict, # make panel figures # first panel is model quality export_svg(fullplot, filename=self.filename+'/' + - self.ID+"quality_at_glance_MQ.svg", webdriver=self.driver) + self.ID_f + "_" +"quality_at_glance_MQ.svg", webdriver=self.driver) save(fullplot, filename=self.filename+'/' + - self.ID+"quality_at_glance_MQ.html") + self.ID_f + "_" +"quality_at_glance_MQ.html") # DATA QUALITY # check for sas data, if exists, plot @@ -245,9 +246,9 @@ def plot_quality_at_glance(self, molprobity_data: dict, exv_data: dict, pd.title.align = "center" pd.output_backend = "svg" export_svg(pd, filename=self.filename+'/' + - self.ID+"quality_at_glance_DQ.svg", webdriver=self.driver) + self.ID_f + "_" +"quality_at_glance_DQ.svg", webdriver=self.driver) save(pd, filename=self.filename+'/' + - self.ID+"quality_at_glance_DQ.html") + self.ID_f + "_" +"quality_at_glance_DQ.html") # FIT TO DATA QUALITY # check for sas data, if exists, plot @@ -285,6 +286,6 @@ def plot_quality_at_glance(self, molprobity_data: dict, exv_data: dict, pf.title.align = "center" pf.output_backend = "svg" export_svg(pf, filename=self.filename+'/' + - self.ID+"quality_at_glance_FQ.svg", webdriver=self.driver) + self.ID_f + '_' +"quality_at_glance_FQ.svg", webdriver=self.driver) save(pf, filename=self.filename+'/' + - self.ID+"quality_at_glance_FQ.html") + self.ID_f + '_' +"quality_at_glance_FQ.html") diff --git a/ihm_validation/mmcif_io.py b/ihm_validation/mmcif_io.py index ea1a556b..96ab3749 100644 --- a/ihm_validation/mmcif_io.py +++ b/ihm_validation/mmcif_io.py @@ -91,7 +91,34 @@ def get_databases(self): def get_id(self): """Return _entry.id; Requires compliant CIF file""" - entry_id = self.system.id + ids = self.get_ranked_id_list() + + if len(ids) == 0: + raise(ValueError('Missing system ID')) + + id_type, entry_id = ids[0] + + return entry_id + + def get_file_id(self): + """Return _entry.id; Requires compliant CIF file""" + ids = self.get_ranked_id_list() + + if len(ids) == 0: + raise(ValueError('Missing system ID')) + + id_type, entry_id = ids[0] + + if id_type == 'PDB ID': + # PDB filenames have to be lowercase + entry_id = entry_id.lower() + elif id_type == 'PDB-Dev ID': + # PDB-Dev filenames have to be uppercase + entry_id = entry_id.upper() + else: + # Use entry ID as is + pass + return entry_id def get_pdb_id(self) -> str: diff --git a/ihm_validation/report.py b/ihm_validation/report.py index dba22d26..38600f59 100644 --- a/ihm_validation/report.py +++ b/ihm_validation/report.py @@ -79,7 +79,9 @@ def run_entry_composition(self, Template_Dict: dict) -> dict: Template_Dict['flex'] = utility.get_flex( utility.dict_to_JSlist_rows(RB, flex)) entry_id = self.input.get_id() + file_id = self.input.get_file_id() Template_Dict['ID'] = entry_id + Template_Dict['ID_f'] = file_id Template_Dict['PDB_ID'] = self.input.get_pdb_id() Template_Dict['PDBDEV_ID'] = self.input.get_pdb_dev_id() Template_Dict['ranked_id_list'] = self.input.get_ranked_id_list() diff --git a/ihm_validation/sas.py b/ihm_validation/sas.py index 40e5f218..1ad1dd70 100644 --- a/ihm_validation/sas.py +++ b/ihm_validation/sas.py @@ -36,7 +36,7 @@ class SasValidation(GetInputInformation): def __init__(self, mmcif_file, db='.'): super().__init__(mmcif_file) self.version = self.get_atsas_version() - self.ID = str(GetInputInformation.get_id(self)) + self.ID = self.get_id() self.nos = GetInputInformation.get_number_of_models(self) self.dataset = GetInputInformation.get_dataset_comp(self) self.imagepath = '../static/images/' diff --git a/ihm_validation/sas_plots.py b/ihm_validation/sas_plots.py index b1a8688a..13b5e1f9 100644 --- a/ihm_validation/sas_plots.py +++ b/ihm_validation/sas_plots.py @@ -19,7 +19,8 @@ class SasValidationPlots(sas.SasValidation): def __init__(self, mmcif_file, imageDirName, driver): super().__init__(mmcif_file) - self.ID = str(GetInputInformation.get_id(self)) + self.ID = self.get_id() + self.ID_f = self.get_file_id() # self.intensities = self.get_intensities() # self.intensities = self.modify_intensity() @@ -39,7 +40,7 @@ def plot_intensities(self, sasbdb: str, df: pd.DataFrame): ''' plot intensities with errors ''' - output_file(self.ID+sasbdb+"intensities.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+"intensities.html", mode="inline") source = ColumnDataSource(df) p = figure(plot_height=350, plot_width=350, title=f"Log I(q) vs q with error bars\n{sasbdb}", @@ -61,16 +62,16 @@ def plot_intensities(self, sasbdb: str, df: pd.DataFrame): p.xaxis.axis_label_text_font_style = 'italic' p.yaxis.axis_label_text_font_style = 'italic' - save(p, filename=self.filename+'/'+self.ID+sasbdb+"intensities.html") + save(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+"intensities.html") p.output_backend = "svg" export_svg(p, height=350, width=350, filename=self.filename + - '/'+self.ID+sasbdb+"intensities.svg", webdriver=self.driver) + '/'+self.ID_f + '_' +sasbdb+"intensities.svg", webdriver=self.driver) def plot_intensities_log(self, sasbdb: str, df: pd.DataFrame): ''' plot intensities on a log scale with errors ''' - output_file(self.ID+sasbdb+"intensities_log.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+"intensities_log.html", mode="inline") source = ColumnDataSource(df) p = figure(plot_height=350, plot_width=350, title=f"Log I(q) vs Log q with error bars\n{sasbdb}", @@ -93,16 +94,16 @@ def plot_intensities_log(self, sasbdb: str, df: pd.DataFrame): p.yaxis.axis_label_text_font_style = 'italic' save(p, filename=self.filename+'/' + - self.ID+sasbdb+"intensities_log.html") + self.ID_f + '_' +sasbdb+"intensities_log.html") p.output_backend = "svg" export_svg(p, height=350, width=350, filename=self.filename + - '/'+self.ID+sasbdb+"intensities_log.svg", webdriver=self.driver) + '/'+self.ID_f + '_' +sasbdb+"intensities_log.svg", webdriver=self.driver) def plot_kratky(self, sasbdb: str, df: pd.DataFrame): ''' plot dimensionless kratky ''' - output_file(self.ID+sasbdb+"Kratky.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+"Kratky.html", mode="inline") source = ColumnDataSource(df) p = figure(plot_height=350, plot_width=350, title=f"Dimensionless Kratky plot\n{sasbdb}", @@ -124,15 +125,15 @@ def plot_kratky(self, sasbdb: str, df: pd.DataFrame): p.yaxis.axis_label_text_font_size = '14pt' p.xaxis.axis_label_text_font_style = 'italic' p.yaxis.axis_label_text_font_style = 'italic' - save(p, filename=self.filename+'/'+self.ID+sasbdb+"Kratky.html") + save(p, filename=self.filename+'/'+self.ID_f+ '_' + sasbdb+"Kratky.html") p.output_backend = "svg" - export_svg(p, filename=self.filename+'/'+self.ID+sasbdb+"Kratky.svg", webdriver=self.driver) + export_svg(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+"Kratky.svg", webdriver=self.driver) def plot_porod_debye(self, sasbdb: str, df: pd.DataFrame): ''' porod debye plot for flexibility ''' - output_file(self.ID+sasbdb+"porod.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+"porod.html", mode="inline") source = ColumnDataSource(df) p = figure(plot_height=350, plot_width=350, title=f"Porod-Debye plot\n{sasbdb}", @@ -152,14 +153,14 @@ def plot_porod_debye(self, sasbdb: str, df: pd.DataFrame): p.xaxis.axis_label_text_font_style = 'italic' p.yaxis.axis_label_text_font_style = 'italic' p.output_backend = "svg" - save(p, filename=self.filename+'/'+self.ID+sasbdb+"porod.html") - export_svg(p, filename=self.filename+'/'+self.ID+sasbdb+"porod.svg", webdriver=self.driver) + save(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+"porod.html") + export_svg(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+"porod.svg", webdriver=self.driver) def plot_pddf(self, sasbdb: str, df: pd.DataFrame, Rg=None, Dmax=None): ''' p(r) plot, deprecated function ''' - output_file(self.ID+sasbdb+"pddf.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+"pddf.html", mode="inline") source = ColumnDataSource(df) ymax = max(df['P']) * 1.1 @@ -197,8 +198,8 @@ def plot_pddf(self, sasbdb: str, df: pd.DataFrame, Rg=None, Dmax=None): p.output_backend = "svg" p.xaxis.axis_label_text_font_style = 'italic' p.yaxis.axis_label_text_font_style = 'italic' - save(p, filename=self.filename+'/'+self.ID+sasbdb+"pddf.html") - export_svg(p, height=350, width=350, filename=self.filename+'/'+self.ID+sasbdb+"pddf.svg", webdriver=self.driver) + save(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+"pddf.html") + export_svg(p, height=350, width=350, filename=self.filename+'/'+self.ID_f+ "_" + sasbdb+"pddf.svg", webdriver=self.driver) def plot_pddf_int_rwt(self, sasbdb: str, df_int: pd.DataFrame, @@ -207,7 +208,7 @@ def plot_pddf_int_rwt(self, sasbdb: str, ''' p(r) with fit ''' - output_file(self.ID+sasbdb+"pddf_int.html", mode="inline") + output_file(self.ID_f + '_' + sasbdb+"pddf_int.html", mode="inline") source1 = ColumnDataSource(df_int) source2 = ColumnDataSource(df_pofr) p1 = figure(plot_height=350, plot_width=350, @@ -267,16 +268,16 @@ def plot_pddf_int_rwt(self, sasbdb: str, p.width = 350 p.height = 550 - save(p, filename=self.filename+'/'+self.ID+sasbdb+"pddf_int.html") + save(p, filename=self.filename+'/'+self.ID_f + '_' + sasbdb+"pddf_int.html") # p.output_backend = "svg" export_svg(p, filename=self.filename+'/' + - self.ID+sasbdb+"pddf_int.svg", webdriver=self.driver) + self.ID_f + '_' + sasbdb+"pddf_int.svg", webdriver=self.driver) def Guinier_plot_fit_rwt(self, sasbdb: str, df: pd.DataFrame, score: float): ''' Gunier plot with fit ''' - output_file(self.ID+sasbdb+"guinier.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+"guinier.html", mode="inline") source = ColumnDataSource(df) p1 = figure(plot_height=350, plot_width=350, title=f"Guinier plot for {sasbdb}") @@ -338,8 +339,8 @@ def Guinier_plot_fit_rwt(self, sasbdb: str, df: pd.DataFrame, score: float): p.height = 550 - save(p, filename=self.filename+'/'+self.ID+sasbdb+"guinier.html") - export_svg(p, filename=self.filename+'/'+self.ID+sasbdb+"guinier.svg", webdriver=self.driver) + save(p, filename=self.filename+'/'+self.ID_f+ '_' + sasbdb+"guinier.html") + export_svg(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+"guinier.svg", webdriver=self.driver) def plot_multiple(self): @@ -384,7 +385,7 @@ def plot_fit_rwt(self, sasbdb: str, fit: int, score: float, df: pd.DataFrame): ''' plot chi-squared fit ''' - output_file(self.ID+sasbdb+str(fit)+"fit1.html", mode="inline") + output_file(self.ID_f + '_' +sasbdb+str(fit)+"fit1.html", mode="inline") source = ColumnDataSource(df) p1 = figure(plot_height=350, plot_width=350, title=f"Model fit for {sasbdb}, model {fit + 1}") @@ -440,7 +441,7 @@ def plot_fit_rwt(self, sasbdb: str, fit: int, score: float, df: pd.DataFrame): p = gridplot([p1, p2], ncols=1, toolbar_location="above") - save(p, filename=self.filename+'/'+self.ID+sasbdb+str(fit)+"fit1.html") + save(p, filename=self.filename+'/'+self.ID_f + '_' +sasbdb+str(fit)+"fit1.html") # p.output_backend = "svg" export_svg(p, filename=self.filename+'/' + - self.ID+sasbdb+str(fit)+"fit1.svg", webdriver=self.driver) + self.ID_f + '_' +sasbdb+str(fit)+"fit1.svg", webdriver=self.driver) diff --git a/templates/data_quality.html b/templates/data_quality.html index b40761e0..3abe1e17 100644 --- a/templates/data_quality.html +++ b/templates/data_quality.html @@ -60,9 +60,9 @@