Skip to content

Commit

Permalink
qc cov csv for std atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
baxpr committed Jul 23, 2024
1 parent c3d8fe6 commit ffb552f
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions scripts/stats_csvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
#
# Stats file conversions for XCP_D when standard atlas used

import argparse
import bids
import os
import pandas
import sys

parser.add_argument('--xcpd_dir', required=True,
help='Absolute path of xcpd output (must match subject/session/etc of fmriprep)')
parser.add_argument('--atlas', required=True,
help='Atlas used')
parser.add_argument('--out_dir', default='/OUTPUTS',
help='Output directory for stats CSVs')
args = parser.parse_args()

# Process BIDS dir
bids_xcpd = bids.layout.BIDSLayout(args.xcpd_dir, validate=False)

# Find QC file and convert to CSV
# Fail if more than one because we can't handle that right now
qc_tsv = bids_xcpd.get(
extension='tsv',
desc='linc',
suffix='qc',
)
if len(qc_tsv)!=1:
raise Exception(f'Found {len(qc_tsv)} qc .tsv instead of 1')
qc = qc_tsv[0].get_df()
qc.to_csv(os.path.join(args.out_dir, 'qc.csv'), index=False)

# Find coverage file
# Base this on QC filename because 'stat' is not a valid standard BIDS
# entity and I don't know how to use the xcp-d extended entities
cov_tsv_fname = qc_tsv.path.replace(
f'_desc-linc_qc.tsv',
f'_seg-{args.atlas}_stat-coverage_bold.tsv'
)
cov = pandas.read_csv(cov_tsv_fname, sep='\t')
cov.transpose().to_csv(
os.path.join(args.out_dir, 'coverage.csv'),
index=False,
header=False
)

0 comments on commit ffb552f

Please sign in to comment.