Bidscoin: I fail to display session label in the BIDS output name


I’m running the bidsmapper (step 1) and I would like to display the session label in the BIDS output names (because of multiple sessions). I know it’s possible, but I can’t figure out where to apply the tip mentioned in the doc, sorry about that. I managed to clear it in the bidseditor, but in vain.

Sorry to ask such a basic thing.

Thank you for your help.
Best, Gaëlle

Hi Gaelle,

before I can help you, I need to know how exactly the session information is available. For instance, is it stored in the DICOM header? Or is it stored in the filename? If it is in the filepath, then can you give me an example of such a filepath? I can then help you with the regular expression that will extract the session label

Thank you very much!
It’s only stored in the filepath, such as:

If useful, I changed my bidsmap_mystudy.yaml, with:
lines 23-28 :

General BIDScoin and plugin options

version: 4.3.2 # BIDScoin version (should correspond with the version in pyproject.toml)
subprefix: sub- # The subject prefix of the source data
sesprefix: ses-prenight # The session prefix of the source data

and since, I use nibabel (after REC/PAR conversion using dicm2niix):
lines 112-115 :

Nibabel key-value heuristics (header fields that are mapped to the BIDS labels)

subject: <filepath:/intermediate_data/sub-(.*?)/>
session: <filepath:/intermediate_data/sub-.*?/ses-prenight(.*?)/>

Hope it’s enough to answer;

Many thanks!

There is a somewhat subtle but important distinction between the template and the study bidsmap. The template contains the prior mapping knowledge about how you collect your data (for all datatypes for all your studies). The study bidsmap contains the mapping information for a particular study at hand. So normally, you only edit the template bidsmap only once (or so), and you edit (tweak) the study bidsmap to add study specific details (such as taskname or so). You changed the session label to contain a study specific path (i.e. intermediate_data), so I assume (and advice) you were editing the study bidsmap. You should also know that there is a difference between using <<>> and <> dynamic labels, that is <<>> is evaluated per subject (during bidscoiner data conversion) and <> is evaluated per study (during bidsmapper data discovery). The session label changes per subject/session, so you need to use the double brackets and delete that prenight substring that you want to extract (that is what you want to extract, i.e. what goes into ()):


This is just the default expression, wasn’t that working fine?

I asked chatgpt to explain it for you :-). Here it is (slightly edited):

Explain this regular expression pattern: /intermediate_data/sub-.*?/ses-(.*?)/

Sure, let’s break down the regular expression pattern /intermediate_data/sub-.*?/ses-(.*?)/ step by step:

  • /intermediate_data/sub-: This part of the pattern matches the literal string “/intermediate_data/sub-”.
  • .*?: This is a non-greedy (or lazy) match for any character (except for line terminators) zero or more times. The .* part means “match any character (.) zero or more times (*)”, and the ? makes the quantifier non-greedy, which means it will match as few characters as possible.
  • /ses-: This matches the literal string “/ses-”.
  • (.*?): This is another non-greedy match for any character zero or more times, but this time it is inside parentheses, which means it captures the matched characters into a group. The non-greedy quantifier ensures that this group will match as few characters as possible.
  • /: This matches the literal character “/”.


In summary, the regular expression /intermediate_data/sub-.*?/ses-(.*?)/ is designed to:

  1. Match the literal path starting with “/intermediate_data/sub-”.
  2. Use a non-greedy match to skip over characters until it finds “/ses-”.
  3. Capture the segment following “/ses-” up to the next “/”.

Example Matches

Here are a few example strings and how they would be matched by the regular expression:

    Matches the entire string.
    Captured group 1: 456

    Matches the entire string.
    Captured group 1: efgh