hed-typescript API
    Preparing search index...

    Class BidsDataset<FileType>

    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();

    Type Parameters

    • FileType
    Index
    datasetRootDirectory: string | null

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

    fileAccessor: BidsFileAccessor<FileType>

    The BIDS file accessor.

    sidecarMap: Map<string, BidsSidecar>

    Map of BIDS sidecar files that contain HED annotations.

    • Load and set the HED schemas for this dataset.

      Returns Promise<BidsHedIssue[]>

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

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

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

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

      Returns Promise<BidsHedIssue[]>

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

      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.

    • Validate the full BIDS dataset for HED compliance.

      Returns Promise<BidsHedIssue[]>

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

      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.

    • Validate the JSON sidecars in the dataset.

      Returns BidsHedIssue[]

      An array of issues found during sidecar validation.

      This method iterates through all JSON sidecars and validates the HED data within them. Note: The data has already been parsed into BidsSidecar objects.

    • Validate the TSV files in the dataset.

      Returns Promise<BidsHedIssue[]>

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

      This method iterates through all .tsv files, merges them with the corresponding JSON sidecars, and validates the HED data within them.

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

      Type Parameters

      • FileType

      Parameters

      • rootOrFiles: string | object

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

      • fileAccessorClass: BidsFileAccessorConstructor<FileType>

        The BidsFileAccessor class to use for accessing files.

      Returns Promise<[BidsDataset<FileType> | null, BidsHedIssue[]]>

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

      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.