# Using filename as samplename for custom content

**URL:** <https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346>\
**Category:** Ask for help\
**Tags:** multiqc\
**Created:** [August 27, 2025, 9:20pm UTC](https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346 "2025-08-27T21:20:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![znorgaard](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/znorgaard/32/1973_2.png) [@znorgaard](https://community.seqera.io/u/znorgaard)\
**Post date:** [August 27, 2025, 9:20pm UTC](https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346/1 "2025-08-27T21:20:49Z")

</div>

I can’t seem to get the Sample Name for custom content to respect the `s_name_filenames` (or `use_filename_as_sample_name`) option.

Example metric file, `test.metrics.csv`:

```auto
metric1,metric2
10,20

```

Example config, `multiqc.config`

```auto
custom_data:
  custom_metrics:
    file_format: "csv"
    s_name_filenames: True
    section_name: "Custom Metrics"
    description: "Detailed Description"
    plot_type: "bargraph"

sp:
  custom_metrics:
    fn: "*.metrics.csv"

```

Command, multiqc v1.30

```auto
multiqc --config multiqc.config .

```

[multiqc\_report.html](https://community.seqera.io/uploads/short-url/4wFTrJGCCXQQFJWDJy8NbStAJuc.html) (4.6 MB)

This generates a bargraph where the sample name is “10”. I would expect the sample name to be “test” and the bargraph to have two values for that sample “metric1” and “metric2”.

There’s a workaround to modify the metrics files to include a sample name column, but I’d like to avoid that when I’m using files produced by existing open source software.

---

<div class="post-metadata">

**Author:** ![ewels](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/ewels/32/1_2.png) [@ewels](https://community.seqera.io/u/ewels)\
**Post date:** [August 28, 2025, 9:19am UTC](https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346/2 "2025-08-28T09:19:47Z")

</div>

There is a Custom Content test case that _nearly_ does this [here](https://github.com/MultiQC/test-data/tree/main/data/custom_content/no_config/bargraph_single_samples), but the file contents are transposed with category names as the first column rather than a header row:

```csv
Category_1 39
Category_2 374
Category_3 253
Category_4 162

```

I don’t think that there’s currently a way to get MultiQC to accept both formats (Custom Content is difficult in this way: there are almost infinite data structures that could be supplied).

I would say that your best bet is to modify the files like you say (combine with sample name, or transpose). Or another way would be to run MultiQC via a script that handles it with custom logic. eg:

```python
#!/usr/bin/env python3

import os
import glob
import multiqc

# Read CSV files
data = {}
for filepath in glob.glob("input_data/*.csv"):
    sample_name = os.path.basename(filepath).replace(".metrics.csv", "")
    with open(filepath, "r") as f:
        header = f.readline().strip().split(",")
        values = f.readline().strip().split(",")
        data[sample_name] = {cat: float(val) for cat, val in zip(header, values)}

# Create bar graph plot
plot = multiqc.plots.bargraph.plot(
    data, pconfig={"id": "custom_metrics_plot", "title": "Sample Metrics Comparison"}
)

# Create custom module
module = multiqc.BaseMultiqcModule(
    name="custom-metrics", anchor="custom_metrics_module"
)
module.add_section(
    name="Sample Metrics",
    anchor="sample_metrics_section",
    description="Metrics comparison across samples",
    plot=plot,
)
multiqc.report.modules.append(module)

# Write report
multiqc.write_report(title="Custom Metrics Report", filename="multiqc_report.html")

```

Then just run `python generate_report.py` instead of `multiqc .`

---

<div class="post-metadata">

**Author:** ![znorgaard](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/znorgaard/32/1973_2.png) [@znorgaard](https://community.seqera.io/u/znorgaard)\
**Post date:** [August 28, 2025, 3:08pm UTC](https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346/3 "2025-08-28T15:08:04Z")

</div>

Thanks Phil! We went with the custom script to add the Sample Name column. We did try running a multiqc script but hit a blocker there as well. We couldn’t get a custom logo imported. I can work on a minimal example for that one too.

---

<div class="post-metadata">

**Author:** ![ewels](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/ewels/32/1_2.png) [@ewels](https://community.seqera.io/u/ewels)\
**Post date:** [August 29, 2025, 7:29pm UTC](https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346/4 "2025-08-29T19:29:51Z")

</div>

Sounds good. It _should_ be possible to do a custom logo with a script, that’s just config and you can set whatever config you want before running within a script. But yeah if you have a minimal example then please do create a GitHub issue and I can take a look into it.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [November 5, 2025, 4:28pm UTC](https://community.seqera.io/t/using-filename-as-samplename-for-custom-content/2346/5 "2025-11-05T16:28:21Z")

</div>

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