|
5 | 5 | from collections import OrderedDict |
6 | 6 | from sdrf_pipelines.openms.openms import UnimodDatabase |
7 | 7 | from multiqc.plots import table |
| 8 | +import os |
8 | 9 |
|
9 | 10 | from pmultiqc.modules.common.histogram import Histogram |
10 | 11 | from pmultiqc.modules.common.stats import ( |
@@ -984,3 +985,77 @@ def dia_sample_level_modifications(df, sdrf_file_df): |
984 | 985 | mod_plot[f"Sample {str(sample)}"] = mod_plot_dict |
985 | 986 |
|
986 | 987 | return mod_plot |
| 988 | + |
| 989 | + |
| 990 | +def parse_diann_version(log_file_path): |
| 991 | + """Parse the DIA-NN version from a DIA-NN log file (report.log.txt). |
| 992 | +
|
| 993 | + The DIA-NN log file typically starts with a line like: |
| 994 | + DIA-NN 1.8.1 (Data-Independent Acquisition by Neural Networks) |
| 995 | +
|
| 996 | + Args: |
| 997 | + log_file_path: Path to the DIA-NN log file. |
| 998 | +
|
| 999 | + Returns: |
| 1000 | + Version string (e.g. "1.8.1") or None if not found. |
| 1001 | + """ |
| 1002 | + version_pattern = re.compile(r"^DIA-NN\s+(\d+(?:\.\d+)*)", re.IGNORECASE) |
| 1003 | + try: |
| 1004 | + with open(log_file_path, "r", encoding="utf-8", errors="replace") as f: |
| 1005 | + for i, line in enumerate(f): |
| 1006 | + match = version_pattern.match(line.strip()) |
| 1007 | + if match: |
| 1008 | + return match.group(1) |
| 1009 | + # Version line is expected near the top; stop after 20 lines |
| 1010 | + if i >= 20: |
| 1011 | + break |
| 1012 | + except Exception as e: |
| 1013 | + log.warning(f"Could not parse DIA-NN version from {log_file_path}: {e}") |
| 1014 | + return None |
| 1015 | + |
| 1016 | + |
| 1017 | +def draw_diann_metadata_table(sub_section, diann_version): |
| 1018 | + """Draw a metadata table showing DIA-NN software version. |
| 1019 | +
|
| 1020 | + Args: |
| 1021 | + sub_section: The sub-section list to add the table to. |
| 1022 | + diann_version: DIA-NN version string to display. |
| 1023 | + """ |
| 1024 | + if not diann_version: |
| 1025 | + return |
| 1026 | + |
| 1027 | + table_data = { |
| 1028 | + 1: { |
| 1029 | + "parameter": "DIA-NN Version", |
| 1030 | + "value": diann_version, |
| 1031 | + } |
| 1032 | + } |
| 1033 | + |
| 1034 | + draw_config = { |
| 1035 | + "id": "diann_metadata", |
| 1036 | + "title": "DIA-NN Metadata", |
| 1037 | + "save_file": False, |
| 1038 | + "sort_rows": False, |
| 1039 | + "only_defined_headers": True, |
| 1040 | + "col1_header": "No.", |
| 1041 | + "no_violin": True, |
| 1042 | + "save_data_file": False, |
| 1043 | + } |
| 1044 | + |
| 1045 | + headers = { |
| 1046 | + "parameter": {"title": "Parameter"}, |
| 1047 | + "value": {"title": "Value"}, |
| 1048 | + } |
| 1049 | + |
| 1050 | + table_html = table.plot(data=table_data, headers=headers, pconfig=draw_config) |
| 1051 | + |
| 1052 | + add_sub_section( |
| 1053 | + sub_section=sub_section, |
| 1054 | + plot=table_html, |
| 1055 | + order=0, |
| 1056 | + description="This table presents the DIA-NN software version used for the analysis.", |
| 1057 | + helptext=""" |
| 1058 | + DIA-NN metadata, extracted from the DIA-NN log file (report.log.txt), shows the |
| 1059 | + version of DIA-NN used for data-independent acquisition analysis. |
| 1060 | + """, |
| 1061 | + ) |
0 commit comments