HED JavaScript Library
    Preparing search index...

    Class BidsDataset

    A BIDS dataset.

    This class organizes and provides access to the files and metadata within a BIDS dataset. It is designed to be used for HED validation of BIDS datasets.

    The BidsDataset should not be created with the constructor. Instead, it should be created using the asynchronous BidsDataset.create factory method. This method handles the initial setup and file discovery.

    BidsDataset creation will return a null dataset if any of the sidecars have invalid JSON, or it cannot find and load the needed HED schemas.

    // In a Node.js environment:
    const { BidsDataset, BidsDirectoryAccessor } = require('hed-validator');
    const path = require('path');

    async function main() {
    const dataRoot = path.join(__dirname, 'path/to/bids/dataset');
    const [dataset, issues] = await BidsDataset.create(dataRoot, BidsDirectoryAccessor);
    if (dataset) {
    const validationIssues = await dataset.validate();
    // process issues
    } else {
    // process creation issues
    }
    }

    main();
    Index

    Properties

    datasetRootDirectory: string

    The dataset's root directory as an absolute path (Node.js context).

    fileAccessor: BidsFileAccessor

    The BIDS file accessor.

    hedSchemas: Schemas

    The HED schemas used to validate this dataset.

    sidecarMap: Map<string, BidsSidecar>

    Map of BIDS sidecar files that contain HED annotations.

    Methods

    • Parameters

      • tsvPath: any
      • category: any
      • jsonPaths: any

      Returns any

    • Load and set the HED schemas for this dataset.

      This method reads the dataset_description.json file, extracts the HEDVersion field, and builds the HED schemas. The result is stored in BidsDataset.hedSchemas.

      Returns Promise<BidsHedIssue[]>

      A promise that resolves to an array of issues encountered during schema loading.

      If dataset_description.json is missing or contains an invalid HED specification.

    • Find and parse all JSON sidecar files in the dataset.

      This method iterates through the dataset's files, identifies JSON sidecars with HED data, parses them into BidsSidecar objects, and stores them in BidsDataset.sidecarMap.

      Note: This method does not validate the HED data within the sidecars; it only parses them.

      Returns Promise<BidsHedIssue[]>

      A promise that resolves to an array of issues encountered during sidecar parsing.

    • Validate the full BIDS dataset for HED compliance.

      This method validates all HED data in the dataset, including:

      • HED strings in JSON sidecars.
      • HED columns in TSV files, evaluated against their corresponding merged sidecars.

      Note: If any of the sidecars have errors (not just warnings), the tsv files will not be validated. This is because a single error in a sidecar can result in errors on every line of a TSV file.

      Returns Promise<BidsHedIssue[]>

      A promise that resolves to an array of issues found during validation.

    • Factory method to create a BidsDataset. This method, rather than the constructor should always be used to create a BidsDataset instance.

      Note: This method will fail to create a BidsDataset if a valid HED schema cannot be loaded or any of the JSON sidecars cannot be loaded. It does not perform HED validation.

      Parameters

      • rootOrFiles: any

        The root directory of the dataset or a file-like object.

      • fileAccessorClass: Function

        The BidsFileAccessor class to use for accessing files.

      Returns Promise<[BidsDataset, BidsHedIssue[]]>

      A Promise that resolves to a two-element array containing the BidsDataset instance (or null if creation failed) and an array of issues.