Ejemplo n.º 1
0
def SessionEndEP(session: BidsSession):
    """
    1. Checks the series in the prepared folder
    2. Extract KSS/VAS data from kss_dict to tsv file
    3. Parces in-scan nBack and KSS/VAS log files
    """
    # path contain destination folder, where
    # all data files are placed

    # session.getPath generates bids path based on
    #   subject and session id, eg. sub-001/ses-HCL
    #   if parameter empty==True, and no session,
    #   the generated path will still contain 'ses-'
    #   empty must be True in preparation plugin
    path = os.path.join(preparefolder,
                        session.getPath(True))
    out_path = os.path.join(path,
                            "MRI")

    # checking if session contains correct series
    if not dry_run:
        checkSeries(out_path,
                    session.subject, session.session,
                    False)

    ############################################
    # Retrieving in-scan task and KSS/VAS data #
    ############################################
    if session.session == "ses-STROOP":
        return 0
    # where tsv files are
    inp_dir = os.path.join(session.in_path, "inp")
    # where tsv files should be
    aux_dir = os.path.join(path, "auxiliary")
    if not os.path.isdir(inp_dir):
        raise NotADirectoryError(inp_dir)

    # do not copy if we are in dry mode
    if not dry_run:
        os.makedirs(aux_dir, exist_ok=True)
        # just copy file, in real life application
        # you may parce files
        for file in ("FCsepNBack.tsv", "VAS.tsv"):
            file = os.path.join(inp_dir, file)
            if not os.path.isfile(file):
                raise FileNotFoundError(file)
            shutil.copy2(file, aux_dir)

        # copiyng correspondent json files
        for file in ("FCsepNBack.json", "VAS.json"):
            file = os.path.join(plugin_root, file)
            if not os.path.isfile(file):
                raise FileNotFoundError(file)
            shutil.copy2(file, aux_dir)
Ejemplo n.º 2
0
def SessionEP(scan: BidsSession) -> int:
    """
    Session files modifications

    1. Stores the list of sequences in the session
    2. Checks if session contains correct sequences
    2. Checks if session HCL and LCL contains task and
    KSS/VAS files
    """

    ######################################
    # Initialisation of sesion variables #
    ######################################
    # retrieving sequences and puttintg them into list
    global seq_list
    global seq_index
    path = os.path.join(scan.in_path, "MRI")
    seq_list = sorted(os.listdir(path))
    # removing leading sequence number from name
    seq_list = [s.split("-", 1)[1] for s in seq_list]
    seq_index = -1

    #################################
    # Checking sequences in session #
    #################################
    checkSeries(path, scan.subject, scan.session, False)

    #############################################
    # Checking for existance of auxiliary files #
    #############################################
    # BidsSession.in_path contains current session folder path
    aux_input = os.path.join(scan.in_path, "auxiliary")
    if scan.session in ("ses-LCL", "ses-HCL"):
        if not os.path.isdir(aux_input):
            logger.error(
                "Session {}/{} do not contain auxiliary folder".format(
                    scan.subject, scan.session))
            return -1
        for old, new in (("FCsepNBack.tsv", "task-rest_events.tsv"),
                         ("FCsepNBack.json", "task-rest_events.json"),
                         ("VAS.tsv", "task-rest_beh.tsv"),
                         ("VAS.json", "task-rest_beh.json")):
            source = "{}/{}".format(aux_input, old)
            if not os.path.isfile(source):
                logger.error("{}/{}: File {} not found".format(
                    scan.subject, scan.session, source))
Ejemplo n.º 3
0
def SessionEP(scan):
    """
    Session files modification

    1. Stores the list of sequences in session
    2. Checks the sequences
    3. Copies HCL and LCL task and KSS/VAS files
    to bidsified dataset
    """

    ######################################
    # Initialisation of sesion variables #
    ######################################
    # retrieving list of sequences and puttintg them into list
    global seq_list
    global seq_index
    path = os.path.join(scan.in_path, "MRI")
    seq_list = sorted(os.listdir(path))
    seq_list = [s.split("-", 1)[1] for s in seq_list]
    seq_index = -1

    #################################
    # Checking sequences in session #
    #################################
    checkSeries(path, scan.subject, scan.session, False)

    #############################################
    # Checking for existance of auxiliary files #
    #############################################

    # all the copy instructions must be protected by
    # if not dry_run

    aux_input = os.path.join(scan.in_path, "auxiliary")
    if scan.session in ("ses-LCL", "ses-HCL"):
        if not os.path.isdir(aux_input):
            logger.error("Session {}/{} do not contain auxiliary folder"
                         .format(scan.subject, scan.session))
            raise FileNotFoundError("folder {} not found"
                                    .format(aux_input))
        beh = os.path.join(scan.in_path, "beh")
        if not dry_run:
            os.makedirs(beh, exist_ok=True)
        for old, new in (("FCsepNBack.tsv", "task-rest_events.tsv"),
                         ("FCsepNBack.json", "task-rest_events.json"),
                         ("VAS.tsv", "task-rest_beh.tsv"),
                         ("VAS.json", "task-rest_beh.json")):
            source = "{}/{}".format(aux_input, old)
            dest = "{}/{}_{}_{}".format(beh, scan.subject, scan.session, new)
            if not os.path.isfile(source):
                if dry_run:
                    logger.error("{}/{}: File {} not found"
                                 .format(scan.subject, scan.session, source))
                else:
                    logger.critical("{}/{}: File {} not found"
                                    .format(scan.subject,
                                            scan.session,
                                            source))
                    raise FileNotFoundError(source)
            if os.path.isfile(dest):
                logger.warning("{}/{}: File {} already exists"
                               .format(scan.subject, scan.session, dest))
            if not dry_run:
                shutil.copy2(source, dest)