Custom MultiqcModule Factory Pattern

Hi all, thanks for this awesome tool, and community!

I have multiple samples that are associated with custom plots - I would like to create a module for each sample and use the self.add_section functionality to add the custom plots. Here is a simple abstraction of the factory function+class

def test_factory(sample, images)
  class TestModule(BaseMultiqcModule):
    def __init__(self):
      super(TestModule, self).__init__(name=sample, anchor=sample)
      for i, image enumerate(images):
        self.add_section(
            name=sample + "_" + str(i),
            anchor=sample,
            content=image
        )
  return TestModule

I have a hook that calls this function at ‘execution_start’ after globing a bunch of images.
This hook is registered in setup.py.

def trigger_fcn():
  sample_to_images = default_dict {str: List[Path]}
  for sample, images in sample_to_images.items():
    test_factory(sample, images)()

The only problem is my does not return entries for these samples - am I missing something here? Does MultiQC not support this kind of pattern?

Hi @Nathan_Phillips!

You need to register the output from the module somehow. If this is a Python script you can do it as in the notebook example:

module = multiqc.BaseMultiqcModule(
    name="nf-core/viralrecon summary",
    anchor="custom_data",
)
module.add_section(
    name="De novo assembly metrics",
    anchor="de_novo_assembly_metrics",
    description="Summary of input reads, trimmed reads, and non-host reads. Generated by the nf-core/viralrecon pipeline",
    plot=plot,
)
multiqc.report.modules = [module] + multiqc.report.modules

If this is running with the MultiQC CLI then you need to register the entry point:

Hopefully that’s the cause - if it doesn’t help then shout and I can try to think of other potential issues.

Phil

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.