From b00c36b9d1afdd7a3bf3890111f5f087c739e535 Mon Sep 17 00:00:00 2001 From: Adrien Coulier Date: Thu, 7 Mar 2024 21:54:09 +0100 Subject: [PATCH 1/6] Add nf-core/demultiplex version parser --- bin/get_metadata.py | 20 ++++++++++++++++++- .../pipeline_info/software_versions.yml | 8 ++++++++ tests/unit_tests/test_get_metadata.py | 14 ++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test_data/210510_M03910_0104_000000000-JHGJL/pipeline_info/software_versions.yml diff --git a/bin/get_metadata.py b/bin/get_metadata.py index ebbb9b5..f0d682e 100644 --- a/bin/get_metadata.py +++ b/bin/get_metadata.py @@ -6,6 +6,7 @@ import argparse import os import json +from pathlib import Path class RunfolderInfo: @@ -82,6 +83,14 @@ def get_bcl2fastq_version(self, runfolder): bcl2fastq_str = f.read() return bcl2fastq_str.split("v")[1].strip() + def get_software_version(self, runfolder): + with open(Path(runfolder) / "pipeline_info" / "software_versions.yml") as f: + return dict( + line.strip().split(": ") + for line in f.readlines() + if line.startswith(" ") + ) + def get_run_parameters(self): results = OrderedDict() for key, value in self.run_parameters_tags.items(): @@ -116,8 +125,17 @@ def get_info(self): flowcell_type = self.find_flowcell_type_novaseqx() if flowcell_type: results.update(flowcell_type) - if os.path.exists(os.path.join(self.runfolder, "bcl2fastq_version")): + + try: results["bcl2fastq version"] = self.get_bcl2fastq_version(self.runfolder) + except FileNotFoundError: + pass + + try: + results.update(self.get_software_version(self.runfolder)) + except FileNotFoundError: + pass + return results diff --git a/test_data/210510_M03910_0104_000000000-JHGJL/pipeline_info/software_versions.yml b/test_data/210510_M03910_0104_000000000-JHGJL/pipeline_info/software_versions.yml new file mode 100644 index 0000000..f04bf35 --- /dev/null +++ b/test_data/210510_M03910_0104_000000000-JHGJL/pipeline_info/software_versions.yml @@ -0,0 +1,8 @@ +BCL2FASTQ: + bcl2fastq: 2.20.0.422 +CUSTOM_DUMPSOFTWAREVERSIONS: + python: 3.12.0 + yaml: 6.0.1 +Workflow: + Nextflow: 23.04.3 + nf-core/demultiplex: 1.5.0dev diff --git a/tests/unit_tests/test_get_metadata.py b/tests/unit_tests/test_get_metadata.py index 64fa01b..83e9fb4 100644 --- a/tests/unit_tests/test_get_metadata.py +++ b/tests/unit_tests/test_get_metadata.py @@ -57,6 +57,18 @@ def test_bcl2fastq_version(runfolder_info): ) assert bcl2fastq_version == "2.20.0.422" +def test_get_software_version(runfolder_info): + software_versions = runfolder_info.get_software_version( + "test_data/210510_M03910_0104_000000000-JHGJL" + ) + + assert software_versions == { + "bcl2fastq": "2.20.0.422", + "python": "3.12.0", + "yaml": "6.0.1", + "Nextflow": "23.04.3", + "nf-core/demultiplex": "1.5.0dev", + } def test_get_run_parameters(runfolder_info): filtered_run_parameters = runfolder_info.get_run_parameters() @@ -95,4 +107,4 @@ def test_get_read_cycles(runfolder_info): def test_get_info(runfolder_info): results = runfolder_info.get_info() - assert len(results) == 10 + assert len(results) == 15 From 487a999cd98ffaf84e139f8d1a6a3791ce29da81 Mon Sep 17 00:00:00 2001 From: Adrien Coulier Date: Fri, 8 Mar 2024 08:50:07 +0100 Subject: [PATCH 2/6] Apply black --- tests/unit_tests/test_get_metadata.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_get_metadata.py b/tests/unit_tests/test_get_metadata.py index 83e9fb4..1c00127 100644 --- a/tests/unit_tests/test_get_metadata.py +++ b/tests/unit_tests/test_get_metadata.py @@ -57,19 +57,21 @@ def test_bcl2fastq_version(runfolder_info): ) assert bcl2fastq_version == "2.20.0.422" + def test_get_software_version(runfolder_info): software_versions = runfolder_info.get_software_version( "test_data/210510_M03910_0104_000000000-JHGJL" ) assert software_versions == { - "bcl2fastq": "2.20.0.422", - "python": "3.12.0", - "yaml": "6.0.1", - "Nextflow": "23.04.3", - "nf-core/demultiplex": "1.5.0dev", + "bcl2fastq": "2.20.0.422", + "python": "3.12.0", + "yaml": "6.0.1", + "Nextflow": "23.04.3", + "nf-core/demultiplex": "1.5.0dev", } + def test_get_run_parameters(runfolder_info): filtered_run_parameters = runfolder_info.get_run_parameters() assert len(filtered_run_parameters) == 5 From ebaa3df56788fe2ffc52d9ff72535fab619c191c Mon Sep 17 00:00:00 2001 From: Adrien Coulier Date: Mon, 11 Mar 2024 14:23:13 +0100 Subject: [PATCH 3/6] Parse yaml file with yaml module --- bin/get_metadata.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bin/get_metadata.py b/bin/get_metadata.py index f0d682e..950600b 100644 --- a/bin/get_metadata.py +++ b/bin/get_metadata.py @@ -7,6 +7,7 @@ import os import json from pathlib import Path +import yaml class RunfolderInfo: @@ -85,11 +86,11 @@ def get_bcl2fastq_version(self, runfolder): def get_software_version(self, runfolder): with open(Path(runfolder) / "pipeline_info" / "software_versions.yml") as f: - return dict( - line.strip().split(": ") - for line in f.readlines() - if line.startswith(" ") - ) + return { + software: version + for sotfware_dict in yaml.safe_load(f).values() + for software, version in sotfware_dict.items() + } def get_run_parameters(self): results = OrderedDict() From f6119fd09d9387744801b9ecf5bdecd28b7017e3 Mon Sep 17 00:00:00 2001 From: Adrien Coulier Date: Mon, 11 Mar 2024 14:23:25 +0100 Subject: [PATCH 4/6] Reorganize version listing This is to make it clear that these version come from e.g. the nf-core/demultiplex pipeline and not the seqreports pipeline. --- bin/get_metadata.py | 26 ++++++++++++++++++++------ tests/unit_tests/test_get_metadata.py | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/bin/get_metadata.py b/bin/get_metadata.py index 950600b..7d20cb7 100644 --- a/bin/get_metadata.py +++ b/bin/get_metadata.py @@ -127,17 +127,26 @@ def get_info(self): if flowcell_type: results.update(flowcell_type) + return results + + def get_demultiplexing_info(self): try: - results["bcl2fastq version"] = self.get_bcl2fastq_version(self.runfolder) + return { + "Demultiplexing": { + "bcl2fastq": self.get_bcl2fastq_version(self.runfolder) + } + } except FileNotFoundError: pass try: - results.update(self.get_software_version(self.runfolder)) + return { + "Demultiplexing": self.get_software_version(self.runfolder) + } except FileNotFoundError: pass - return results + return {} if __name__ == "__main__": @@ -157,7 +166,7 @@ def get_info(self): bcl2fastq_outdir = args.bcl2fastq_outdir runfolder_info = RunfolderInfo(runfolder, bcl2fastq_outdir) - results = runfolder_info.get_info() + info = runfolder_info.get_info() print( """ @@ -169,6 +178,11 @@ def get_info(self):
""" ) - for k, v in results.items(): - print("
{}
{}
".format(k, v)) + for k, v in info.items(): + print(f"
{k}
{v}
") + + print("
Demultiplexing
") + for software, version in runfolder_info.get_demultiplexing_info().items(): + print(f"
{software}: {version}
") + print("
") diff --git a/tests/unit_tests/test_get_metadata.py b/tests/unit_tests/test_get_metadata.py index 1c00127..d77fa20 100644 --- a/tests/unit_tests/test_get_metadata.py +++ b/tests/unit_tests/test_get_metadata.py @@ -109,4 +109,4 @@ def test_get_read_cycles(runfolder_info): def test_get_info(runfolder_info): results = runfolder_info.get_info() - assert len(results) == 15 + assert len(results) == 9 From 5050770974de9973dfe3f535330e60affd50e583 Mon Sep 17 00:00:00 2001 From: Adrien Coulier Date: Mon, 11 Mar 2024 15:31:05 +0100 Subject: [PATCH 5/6] Run Black --- bin/get_metadata.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bin/get_metadata.py b/bin/get_metadata.py index 7d20cb7..4a8a7a8 100644 --- a/bin/get_metadata.py +++ b/bin/get_metadata.py @@ -86,7 +86,7 @@ def get_bcl2fastq_version(self, runfolder): def get_software_version(self, runfolder): with open(Path(runfolder) / "pipeline_info" / "software_versions.yml") as f: - return { + return { software: version for sotfware_dict in yaml.safe_load(f).values() for software, version in sotfware_dict.items() @@ -140,9 +140,7 @@ def get_demultiplexing_info(self): pass try: - return { - "Demultiplexing": self.get_software_version(self.runfolder) - } + return {"Demultiplexing": self.get_software_version(self.runfolder)} except FileNotFoundError: pass From a97d75786bf3a346cef375c81b9ee4f71cbaf8ef Mon Sep 17 00:00:00 2001 From: Adrien Coulier Date: Tue, 12 Mar 2024 10:48:07 +0100 Subject: [PATCH 6/6] Fix typo --- bin/get_metadata.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/get_metadata.py b/bin/get_metadata.py index 4a8a7a8..2e20b55 100644 --- a/bin/get_metadata.py +++ b/bin/get_metadata.py @@ -88,8 +88,8 @@ def get_software_version(self, runfolder): with open(Path(runfolder) / "pipeline_info" / "software_versions.yml") as f: return { software: version - for sotfware_dict in yaml.safe_load(f).values() - for software, version in sotfware_dict.items() + for software_dict in yaml.safe_load(f).values() + for software, version in software_dict.items() } def get_run_parameters(self):