-
Notifications
You must be signed in to change notification settings - Fork 21
/
combineqc.py
50 lines (38 loc) · 1.27 KB
/
combineqc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Aggregate qc of all the subjects."""
import os
from argparse import ArgumentParser, RawTextHelpFormatter
from pathlib import Path
import pandas as pd
def get_parser():
"""Build parser object."""
parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
parser.add_argument(
"xcpd_dir",
action="store",
type=Path,
help="xcp_d output dir",
)
parser.add_argument(
"output_prefix",
action="store",
type=str,
help="output prefix for group",
)
return parser
def main():
"""Run the combineqc workflow."""
opts = get_parser().parse_args()
xcpd_dir = os.path.abspath(opts.xcpd_dir)
outputfile = os.path.join(os.getcwd(), f"{opts.output_prefix}_allsubjects_qc.csv")
qc_files = []
for dirpath, _, filenames in os.walk(xcpd_dir):
for filename in filenames:
if filename.endswith("_desc-linc_qc.csv"):
qc_files.append(os.path.join(dirpath, filename))
dfs = [pd.read_csv(qc_file) for qc_file in qc_files]
df = pd.concat(dfs, axis=0)
df.to_csv(outputfile, index=False)
if __name__ == "__main__":
raise RuntimeError("this should be run after xcp_d;\nrun xcp-d first")