X axis ordered by date?

Hello! I’m testing MultiQC for proteomics data and I’m wondering if there’s a way to order the X axis by date (for instance, dd/MM/YY hh:mm) from older to newer. So what we want is to see how the QC parameters changes across time (a classical time series).
Thanks!
Roger

Hi @rolivella!

Could you give a little more context please? X axis of what? A screengrab or something would help.

Thanks!

Phil

Hi @ewels !

Yes, I’m would like to ask if we can do plots like this:

The X axis is time, for instance “2024-03-23 11:40:36” for a particular data point. The Y axis is a measure if the area of some QC peptides (EYE, YIC, etc.). We have similar QC plots for other parameters but always with the same time X axis.

Is it more clear now?

Thanks!

Roger

Understood, thanks :+1: I don’t think that there are any existing plots that have a datetime axis like this, so I think it’s unlikely that it’s supported at present. Best bet is to put in a GitHub issue requesting it. The underlying plotting library definitely supports it, so hopefully it shouldn’t be a big task.

Short term, two workarounds spring to mind - if all the points are shared and the data points are evenly distributed, you could treat the x axis as categorical data and it should sort of work. Alternatively, you could convert the dates / times into a unix timestamp so that they behave as a simple integer and can be treated as a numerical axis. But then the labels will be nonsensical. So neither approach is perfect.

Tagging @vlad.savelyev for visbility.

Phil

OK, thank you very much! It’s not urgent so I can put it in a GitHub issue requesting it.

Roger

1 Like

Values like “2024-03-23 11:40:36” should work well as X-axis values, and get the right sorting. Plotly will even recognize it as a timestamp and render nicely:

lineplot_data = {
    "sample1": {
        str(datetime.datetime.today()): 1,
        str(datetime.datetime.today() + datetime.timedelta(days=1)): 2,
        str(datetime.datetime.today() + datetime.timedelta(days=2)): 3,
        str(datetime.datetime.today() + datetime.timedelta(days=3)): 5,
        str(datetime.datetime.today() + datetime.timedelta(days=4)): 2,
        str(datetime.datetime.today() + datetime.timedelta(days=5)): 3,
        str(datetime.datetime.today() + datetime.timedelta(days=6)): 4,
        str(datetime.datetime.today() + datetime.timedelta(days=7)): 5,
    },
}

self.add_section(
    name="Line Plot",
    anchor="test-line-plot",
    description="Line plot test.",
    plot=linegraph.plot(lineplot_data, pconfig={"id": "test_line_plot"}),
)

And the X axis orderred automatically as well by date.

lineplot_data = {
    "sample1": {
        str(datetime.datetime(2024, 3, 10)): 2,
        str(datetime.datetime(2024, 3, 7)): 10,
        str(datetime.datetime(2024, 3, 5, 1, 30)): 1,
        str(datetime.datetime(2024, 3, 6, 18, 10)): 4,
        str(datetime.datetime(2024, 3, 8, 12, 2)): 2,
    },
}

So not sure if there is an issue here. Let me know if that’s not working for you or if I misunderstood the question, @rolivella.

Thanks @vlad.savelyev ! Looks promising. As I’m working with non-standard multiqc data (proteomics data) I’m using a customized JSON like this test:

{
  "id": "custom_data_lineplot_2",
  "section_name": "Mass accuracy",
  "description": "This is the mass accuracy.",
  "plot_type": "linegraph",
  "pconfig": {
    "id": "custom_data_linegraph2",
    "title": "Mass accuracy",
    "ylab": "Mass accuracy (ppm)",
    "xDecimals": false,
    "ymax": "2",
    "ymin": "-2"

  },
  "data": {
    "LVN": { "24/03/2024": -0.20262053803095767,"25/03/2024": -0.50262053803095767},
    "HLV": { "24/03/2024": -0.30262053803095767,"25/03/2024": -0.10262053803095767}
  }
  }

How should I apply those Plotly timestamps to this JSON? Thanks!

Your JSON works for me:

multiqc test_mqc.json

What are you getting? How are you running MultiQC?

Yes yes, is working, I meant now I’m using this string “24/03/2024”. Should I put it in another format in order Plotly to get it as timestamp? Now is a “string”, I’m wondering if I have put it as a “timestamp”, do you know what I mean?

Going on @vlad.savelyev’s suggestion above:

Python 3.12.1 | packaged by conda-forge | (main, Dec 23 2023, 08:01:35) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> str(datetime.datetime.today())
'2024-03-28 13:22:17.508050'

So 24/03/20242024-03-24 00:00:00.000000

I suspect that Plotly will be relatively forgiving and that you can cut some / all of the timestamp off the end. But maybe start with this and see if it works first.

Phil

1 Like

Right on, in order for Plotly to recognize a string as a date, it needs to be in ISO format:

  "data": {
    "LVN": { "2024-03-24": -0.20262053803095767,"2024-03-25": -0.50262053803095767},
    "HLV": { "2024-03-24": -0.30262053803095767,"2024-03-25": -0.10262053803095767}
  }

Your original “24/03/2024” format sort of works as Plotly interprets it as a plain string category, but since it would sort it alphanumerically - date first - month second - this is not ideal. So if you change the format to “2024-03-24”, it should work as expected.

Yes, the format did the trick. By putting dates in this format “2024-03-24 11:00” the X axis worked as expected.

Thank you both for the help!

1 Like

Great! Thanks for letting us know!

Hi again :waving_hand:

I’m working on the nf-core/ribomsqc pipeline and need to implement the feature we discussed last year. Since the pipeline will process one file at a time as the instrument generates data, I was wondering if this setup would work:

File 1:

{
  "id": "custom_data_lineplot_2",
  "section_name": "Mass accuracy",
  "description": "This is the mass accuracy.",
  "plot_type": "linegraph",
  "pconfig": {
    "id": "custom_data_linegraph2",
    "title": "Mass accuracy",
    "ylab": "Mass accuracy (ppm)",
    "ymax": "2",
    "ymin": "-2"
  },
  "data": {
    "LVN": { "2024-03-24": -0.20262053803095767 },
    "HLV": { "2024-03-24": -0.30262053803095767 }
  }
}

File 2:

{
  "id": "custom_data_lineplot_2",
  "section_name": "Mass accuracy",
  "description": "This is the mass accuracy.",
  "plot_type": "linegraph",
  "pconfig": {
    "id": "custom_data_linegraph2",
    "title": "Mass accuracy",
    "ylab": "Mass accuracy (ppm)",
    "ymax": "2",
    "ymin": "-2"
  },
  "data": {
    "LVN": { "2024-03-25": -0.50262053803095767 },
    "HLV": { "2024-03-25": -0.10262053803095767 }
  }
}

Can MultiQC merge these and show both time points on the x-axis?

I tried placing both files in a folder and running MultiQC, but only the one with the earlier date (2024-03-24) shows up in the report.

Thanks!

Hi @rolivella,

I’m not sure that this is possible, at least with Custom Content. You can progressively add more samples with more files, but merging data points for the same samples across multiple files isn’t possible, I think.

What might work is writing a script that imports MultiQC, this gives a lot more flexibility in what is possible. With this method you could build the data for the plot however you want, including parsing whatever series of data structures you want, before passing back to MultiQC to generate a plot and report.

Phil

Thanks, @ewels, for replying so quickly!

Got it — I’ll take a look at what you mentioned about importing the MultiQC library within a script. That said, for this initial version of the pipeline, I’d really like to wrap things up as soon as possible, since we have a major mass spectrometry conference in the US during the first week of June. I’d like to have the first version of the pipeline functional and published in the official repo by then, if possible.

So for now, I’d prefer to focus on presenting the results with MultiQC as-is, without developing additional scripts. I was thinking about reordering the samples in a different way, as shown in this (admittedly rough!) plot. But I think the idea comes across. P1 and P2 are two different parameters, and S1, S2, S3 are the samples being processed, each generating an output file that MultiQC picks up.

I believe this structure fits better within MultiQC’s framework, and I wouldn’t need to develop another script, right?

Thanks again!

A little tough to see but yes, if different plots for each data input then I think it should be fine :+1:

1 Like

This topic was automatically closed after 6 days. New replies are no longer allowed.