예제 #1
0
#!/usr/bin/python

import sys, argparse, os, csv, errno, subprocess
import lxml.etree as et

from belgerlab_utils import MyParser, get_subj_demo_from_raw_dir, create_bids_subj_directory_hierarchy

# Create recursive function to add "+" to any output that already exists
def check_if_already_converted(outname):
    if os.path.isfile(outname + ".nii.gz"): 
        outname = outname + "+"
        outname = check_if_already_converted(outname)
    return outname

# Setup and get the input arguments
parser = MyParser(description='Convert raw BXH/NII.GZ file to BIDS format')
parser.add_argument("raw_dir", help="raw data directory")
parser.add_argument("in_file", help="input BXH/NII.GZ filename")
parser.add_argument("bids_dir", 
    help="output directory; the root folder of a BIDS valid dataset (sub-XXXXX folders should be found at the top level in this folder)")
parser.add_argument("demo_file", help="demographics CSV file")
parser.add_argument("opts_file", help="convert_rawbxh_to_bids options CSV file")
# parser.add_argument("-d", "--add_date", help="add date and time to output filename", action="store_true")
args = parser.parse_args()

# Initialize some variables
bidssubdirs=["anat", "func", "fmap", "dwi", "beh", "notsupported"]
nspace={'b': 'http://www.biac.duke.edu/bxh'}

# Intialize the options dictionary
opts = {'demographics_rawdatadir_column': -1, 
예제 #2
0
import os
import csv
from random import randint

from belgerlab_utils import MyParser


# Sub-function to print a list to a file
def writelisttofile(writelines, outfile):
    for i, key in enumerate(writelines):
        outfile.write(key + '\r\n')


# Setup and get the input arguments
parser = MyParser(
    description='Split multi-run EPrime behavioral file into separate run files'
)
parser.add_argument("eprime_txt",
                    help="eprime output behavioral file you want to split")
parser.add_argument("instruct_file",
                    help="instructions file that describes the start of a run")
args = parser.parse_args()

# Input 1 is the EPrime text file to split into separate runs
txtfile = args.eprime_txt
fpath = os.path.dirname(txtfile)
# Input 2 is the instructions file that tells the first few lines of a new run
instructfile = args.instruct_file

# Add the instruction start lines to a list
splitinstructions = []
# More info here: https://bids-specification.readthedocs.io/en/latest/04-modality-specific-files/05-task-events.html
# And here: https://bids-specification.readthedocs.io/en/latest/04-modality-specific-files/07-behavioral-experiments.html

from belgerlab_utils import MyParser


def convert_to_seconds(text_value, units):
    out_value = text_value
    if units == 'msec':
        out_value = str(float(text_value) / 1000)
    return out_value


# Setup and get the input arguments
parser = MyParser(
    description=
    'Convert BIAC behavioral XML file to BIDS format xxxx_events.tsv')
parser.add_argument("xml_file", help="XML behavioral file you want to convert")
parser.add_argument("out_tsv",
                    help="filename of the output xxxx_events.tsv file")
parser.add_argument(
    "-r",
    "--rt_string",
    help="string that represents reaction time code; default RT",
    default="RT")
args = parser.parse_args()

# Initialize some variables
header_row = ['onset', 'duration', 'trial_type', 'response_time']

# Read the BXH file using XML parser
예제 #4
0
#!/usr/bin/python

import sys, os, argparse, json, subprocess
from datetime import datetime

from belgerlab_utils import MyParser

# Setup and get the input arguments
parser = MyParser(
    description=
    'Find the acquistion time of an imaging series and write to file if it is the first series'
)
parser.add_argument(
    "in_file",
    help="input file describing the imaging series; BXH or BIDS JSON")
parser.add_argument("time_file",
                    help="file where the time of scan will be saved")
args = parser.parse_args()

# Check to see if input file exists
if not os.path.isfile(args.in_file):
    sys.exit('Error - could not find input file: {}'.format(args.in_file))

# Find the previous "first" series time if the file exists
oldtime = ''
if os.path.isfile(args.time_file):
    with open(args.time_file, 'r', newline='') as timefile:
        for line in timefile:
            oldtime = line.strip()
    # NOTE: might need to change this; go here: https://strftime.org/
    oldtime = datetime.strptime(oldtime, '%H:%M:%S.%f')
#!/usr/bin/python

import sys, os, argparse, csv
from shutil import copyfile
from subprocess import check_output

from belgerlab_utils import MyParser, get_subj_demo_from_subjid_and_visit, search_replace_in_string

# Setup and get the input arguments
parser = MyParser(
    description='Add and/or edit an imaging session in the sessions.tsv file')
parser.add_argument("bids_dir", help="BIDS top level directory")
parser.add_argument("demo_file", help="demographics CSV file")
parser.add_argument(
    "template_file",
    help=
    "BIDS sessions.tsv template CSV file; header row with column number matching that field from demographics CSV"
)
parser.add_argument(
    "json_file",
    help="sessions.json file that will be copied with the sessions.tsv")
parser.add_argument("bids_subjid", help="BIDS subject ID")
parser.add_argument("subjid_col",
                    help="BIDS subject ID column in demographics CSV file",
                    nargs='?',
                    type=int,
                    const=0,
                    default=0)
parser.add_argument("visit", help="vist string; ex. ses-baseline")
parser.add_argument("visit_col",
                    help="BIDS visit column in demographics CSV file",
#!/usr/bin/python

import sys, os, argparse

from belgerlab_utils import MyParser

# Setup and get the input arguments
parser = MyParser(
    description=
    'Zero-pad the series and acquisition numbers to make listing chronological'
)
parser.add_argument("infile", help="input filename to zero-pad")
parser.add_argument("-s",
                    "--srspad",
                    help="how many digits for series number; default 3",
                    nargs='?',
                    type=int,
                    const=3,
                    default=3)
parser.add_argument("-a",
                    "--acqpad",
                    help="how many digits for acquisition number; default 3",
                    nargs='?',
                    type=int,
                    const=3,
                    default=3)
args = parser.parse_args()

# Get the file path and file name
fpath = os.path.dirname(args.infile)
fname = os.path.basename(args.infile)
예제 #7
0
#!/usr/bin/python

from belgerlab_utils import MyParser, create_bids_subj_directory_hierarchy

# Setup and get the input arguments
parser = MyParser(
    description='Create an empty BIDS subject directory hierarchy')
parser.add_argument("bids_dir", help="BIDS top level directory")
parser.add_argument("bids_subjid", help="BIDS subject ID")
parser.add_argument("visit", help="vist string; ex. ses-baseline")
args = parser.parse_args()

# Initialize some variables
bidssubdirs = ["anat", "func", "fmap", "dwi", "beh", "notsupported"]

# Create the empty directory
create_bids_subj_directory_hierarchy(args.bids_subjid, args.visit,
                                     [args.bids_dir], bidssubdirs)