[RESOLVED] Guidance running longitudinal HCP pipeline

I’m excited for the release of HCP longitudinal pipeline and eager to get going with it. I would like to use the new run_recipe command to start a job that gets the initial hcp_freesurfer jobs running for each of eg 2 longitudinal scans for a subject running in parallel and then proceeds with the longitudinal steps. Is there documentation / examples for how to do this? I couldn’t find any, sorry if I missed it. I put together a run_recipe command (and yaml file) based on what I could find in the documentation, and it seems to be running ok, but every step is going in serial (i.e. first completes freesurfer for session1, then completes freesurfer for session2, then post FS for session1, etc … i guess i’m messing up some parallel directive?)

Any advice is appreciated!!

My run_recipe command:

qunex_container run_recipe \
    --container="${con}" \
	--bind="${qdir}" \
    --recipe_file="$qdir/$projectname/sessions/specs/recipe.yaml" \
    --recipe="hcp_longitudinal" \
	--scheduler="SLURM,jobname=hcp_long,time=48:00:00,mem-per-cpu=16000,partition=scavenger"

My recipe.yaml file:

global_parameters:
  sessionsfolder    : /work/long/qunex/SUBJECT/sessions
  sessions          : session1,session2
  overwrite         : "yes"
  batchfile         : /work/long/qunex/SUBJECT/processing/batch.txt

recipes:

  hcp_longitudinal:
      parsessions: 2
      
      commands:
          - create_session_info:
              mapping: /work/long/qunex/SUBJECT/sessions/specs/hcp_mapping.txt
          - setup_hcp
          - create_batch:
              targetfile: /work/long/qunex/SUBJECT/processing/batch.txt
              paramfile : /work/long/qunex/SUBJECT/sessions/specs/parameters.txt              
          - hcp_pre_freesurfer
          - hcp_freesurfer
          - hcp_post_freesurfer
          - hcp_long_freesurfer
          - hcp_long_post_freesurfer

Hi!

If this is not something super pressing, I would advise you to wait a couple of days or a week. We are just running final tests that patches some bugs in the HCP’s structural longitudinal processing, this will be released with QuNex 1.1.0. Furthermore, 1.1.0 will also include longitudinal surface and volume processing.

Right now we are discussing whether we want to delay the release until end of next week and fold in the longitudinal diffusion as well since that is also under testing right now.

Anyhow, your recipe file and the command look fine. I would just add parsessions: 2 to the top of the recipe file to process both sessions in parallel where possible. One thing that might be problematic is the naming of your sessions. By default QuNex expects the following naming <subject>_<session> this is irrelevant for traditional processing, but very important for longitudinal since it tells QuNex how sessions should be grouped together. I imagine that in your case the subject is not set correctly. You can check that by opening the session file (/sessions/session1/session.txt or session_hcp.txt) or the batch file (processing/batch.txt). One way to fix this manually is to set appropriate subject labels in the batch file. The other is to either fix the raw data archive name before running import_dicom or to change the pattern string of the import_dicom command (but the subject id needs to be present somewhere in the archive name so the pattern can extract it).

Best, Jure

Ah ok thank you, I am happy to wait until it’s more finalized! Will stay tuned for updates.

In the meantime I’m wanting to make sure I understand how to implement your other suggestions… I have added parsessions: 2 to the top of the recipe file (global_parameters section; and left it in the the hcp_longitudinal section as well)

I am not sure i completely follow the details on the convention i should be using for subject/session ID formatting - if it’s easy to point me to documentation on that, i’d appreciate it, otherwise i’ll keep poking around.

The rest of what I’ll post might be moot with the updates, but in case not I wanted to get a head start on any feedback about what I might be doing wrong. My test run has finished now, and it looks to me like everything through hcp_long_freesurfer has completed (e.g. see aseg.stats outputs below), and then an error was encountered. FWIW, my actually subject ID here is 0223, and sessions are P45 and P52, using those below.

$ ll DBIS_long_0223/subjects/0223/0223.long.base/T1w/*/stats/aseg.stats
-rw-rw-r--. 1 ark19 wheel 9808 Feb 20 07:09 DBIS_long_0223/subjects/0223/0223.long.base/T1w/base/stats/aseg.stats
-rw-rw-r--. 1 ark19 wheel 9489 Feb 20 14:56 DBIS_long_0223/subjects/0223/0223.long.base/T1w/P45.long.base/stats/aseg.stats
-rw-rw-r--. 1 ark19 wheel 9798 Feb 19 06:21 DBIS_long_0223/subjects/0223/0223.long.base/T1w/P45/stats/aseg.stats
-rw-rw-r--. 1 ark19 wheel 9489 Feb 20 15:03 DBIS_long_0223/subjects/0223/0223.long.base/T1w/P52.long.base/stats/aseg.stats
-rw-rw-r--. 1 ark19 wheel 9798 Feb 19 16:50 DBIS_long_0223/subjects/0223/0223.long.base/T1w/P52/stats/aseg.stats
$
$ tail -5 DBIS_long_0223/processing/logs/comlogs/done_hcp_long_freesurfer_0223_2025-02-19_21.43.22.705024.log
Started at Wed Feb 19 21:43:29 EST 2025
Ended   at Thu Feb 20 07:29:27 EST 2025
#@#%# recon-all-run-time-hours 9.766
recon-all -s base finished without error at Thu Feb 20 07:29:27 EST 2025
done

Here are relevant lines of DBIS_long_0223/processing/batch.txt, which look good to me:

session: P45
subject: 0223

bids: /work/long/qunex/DBIS_long_0223/sessions/P45/bids
raw_data: /work/long/qunex/DBIS_long_0223/sessions/P45/nii
hcp: /work/long/qunex/DBIS_long_0223/sessions/P45/hcp


hcpready: true

1   :T1w             :T1w: fm(1)
2   :T2w             :T2w acq-FLAIR: fm(1)
3   :FM-Magnitude    :magnitude: fm(1)
4   :FM-Phase        :phasediff: fm(1)

---
# Generated by QuNex 1.0.4 [QIO] on 2025-02-18_17.37.49.452888
#
session: P52
subject: 0223

bids: /work/long/qunex/DBIS_long_0223/sessions/P52/bids
raw_data: /work/long/qunex/DBIS_long_0223/sessions/P52/nii
hcp: /work/long/qunex/DBIS_long_0223/sessions/P52/hcp


hcpready: true

1   :T1w             :T1w: fm(1)
2   :T2w             :T2w acq-FLAIR: fm(1)
3   :FM-Magnitude    :magnitude: fm(1)
4   :FM-Phase        :phasediff: fm(1)

and here is the end of $HOME/qunex_container_2025-02-18_17.37.21.460015.txt reflecting the error that seems to have arisen after hcp_long_freesurfer

Starting processing of subjects 0223 at Wednesday, 19. February 2025 21:43:22

Running external command: /opt/HCP/HCPpipelines/FreeSurfer/LongitudinalFreeSurferPipeline.sh             --subject="0223"             --path="/work/long/qunex/DBIS_long_0223/subjects/0223"             --sessions="P45@P52"             --longitudinal-template="base"             --parallel-mode="BUILTIN"             --logdir="/work/long/qunex/DBIS_long_0223/processing/logs/comlogs/extra_logs_hcp_long_freesurfer_0223"



You can follow command's progress in:

/work/long/qunex/DBIS_long_0223/processing/logs/comlogs/tmp_hcp_long_freesurfer_0223_2025-02-19_21.43.22.705024.log

------------------------------------------------------------



------------------------------------------------------------

Sessions: 0223

[started on Wednesday, 19. February 2025 21:43:22]

Running HCP Longitudnal FS Pipeline [HCPStyleData] ...

ERROR: Unknown error occured:

...................................

Traceback (most recent call last):

  File "/opt/qunex/python/qx_utilities/hcp/process_hcp.py", line 2459, in hcp_long_freesurfer

    log = result["log"]

          ~~~~~~^^^^^^^

KeyError: 'log'

...................................





HCP Longitudinal FS Preprocessing completed on Thursday, 20. February 2025 15:38:49

------------------------------------------------------------





---> Final report for command hcp_long_freesurfer

... 0223 ---> Error

---> Not all tasks completed fully!


---> ERROR in completing run_recipe:
     run_recipe command failed
     Command hcp_long_freesurfer inside recipe hcp_longitudinal failed
     See error logs in the study folder for details

If there’s something I’ll need to fix even after the update, please let me know - thanks!

Hi,

  1. The bug you pasted has been fixed in the new version. The plan is to publish 1.1.0 which has this patch in it along with longitudinal support for Surface, Volume and Diffusion by the end of next week.

  2. Sorry, I did not see parsessions: 2 in your intial recipe. You can have it either under global_parameters on top or under a parameter block inside the recipe. For example if you setting in global would be 4 and inside the recipe as 2 then that particular recipe would use parsessions=2 while other recipe you might have in the file would use 4. I see that we have a mistake in our documentation as the recipe level parsessions is not listed under a parameters block. Will fix that for the next release as well.

  3. I guess that you manually tweaked the subject ID in the batch file? Correct session and subject would be automatically set by QuNex if the data archives (.zip, .tar.gz …) would have names 0223_P45 and 0223_P52. Instead of archives these can also be “root” folders with all the images (dicoms) in them. Then you use import_dicom on sessions 0223_P45 and 0223_P52.

Best, Jure

Hi Jure, will ICAFIX and MSMAll also be adapted at some point for the longitudinal stream?

Hi,

Yes, if I am not mistaken the HCP team is already working on this. I do not have an eta for this though.

Best, Jure

Hi,

Did you maybe get the chance to test the pipeline with the latest container?

Best, Jure

Hi Jure, I’ve now downloaded the latest container and am able to run the pipeline without issue - thanks! No more questions, for now at least :slight_smile: