DCAN-Labs / dcan_bold_processing

functional connectivity preprocessing for resting state fMRI outputs of the dcan-fmri-pipelines
BSD 3-Clause "New" or "Revised" License
7 stars 6 forks source link

Include new/updated motion TSV file generation as part of this workflow #4

Closed ericearl closed 11 months ago

ericearl commented 4 years ago

@perronea We have a piece of code we used to generate the "updated_motion" uploads for collection 3165, but I don't remember where it went. I believe you wrote it. Please find that code and integrate it into the "teardown" stage here. I think it was Python code. Let me know if you have questions.

ericearl commented 4 years ago

@perronea I found the old code here:

/home/exacloud/lustre1/fnl_lab/projects/ABCD/make_FD/update_with_FD.py

It looks like this:

#! /usr/bin/env python3

import csv
import math
import numpy as np
import os
import sys

def calc_FD(motion_array, brain_radius_in_mm=50):
    # motion array: N-by-6 matrix, where N is the number of frames
    # brain_radius_in_mm is just that, typically 50 for adolescents/adults and 35 for infants

    # motion numbers
    trans_mm = motion_array[:,:3]
    rot_mm = np.multiply( motion_array[:,3:6], brain_radius_in_mm*math.pi/180 )

    # backwards differences
    difference = np.diff( np.concatenate((trans_mm, rot_mm), axis=1), axis=0 )

    # framewise displacement vector
    FD = np.sum(np.absolute(difference), axis=1)

    # return back FD values from calc_FD function
    return FD

# user inputs
mo_tsv = os.path.abspath(sys.argv[1])
# since rows have variable number of space delimiters
f = open(mo_tsv)
tokens = f.read().split()
rows = []
for idx, token in enumerate(tokens):
    if idx % 12 == 0:
        row = []
        rows.append(row)
    row.append(token)
mo_data = np.array(rows[1:], dtype='float')

FD = calc_FD(mo_data)
FD = np.insert(FD, 0, 0)

header = rows[0] + ['FD']
header_str = '    '.join(header)
new_mo_data = np.concatenate((mo_data, FD[:, None]), axis=1)

np.savetxt(os.path.join('new_motion_nums',os.path.basename(mo_tsv)), new_mo_data, fmt='%-6.6f' ,delimiter='    ', header=header_str)
audreymhoughton commented 11 months ago

From @madisoth: Looks like it was added to DCANBOLDProc in Feb 2021 (https://github.com/DCAN-Labs/dcan_bold_processing/commit/661d656d1594684910a319a562c2811434337524)

All the HCP-based pipelines post-Aug 2021 (for ABCD-BIDS, 0.1.0 and up) should have it