Skip to content

Commit

Permalink
feat: Pass maxRows to loadTSV for associations
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jan 11, 2025
1 parent 2bafdea commit 7415c12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/schema/associations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const associationLookup = {
suffix: 'events',
extensions: ['.tsv'],
inherit: true,
load: async (file: BIDSFile): Promise<Events> => {
const columns = await loadTSV(file)
load: async (file: BIDSFile, options: { maxRows: number }): Promise<Events> => {
const columns = await loadTSV(file, options.maxRows)
.catch((e) => {
return new Map()
})
Expand All @@ -53,8 +53,9 @@ const associationLookup = {
inherit: true,
load: async (
file: BIDSFile,
options: { maxRows: number },
): Promise<Aslcontext> => {
const columns = await loadTSV(file)
const columns = await loadTSV(file, options.maxRows)
.catch((e) => {
return new Map()
})
Expand All @@ -69,31 +70,31 @@ const associationLookup = {
suffix: 'm0scan',
extensions: ['.nii', '.nii.gz'],
inherit: false,
load: (file: BIDSFile): Promise<M0Scan> => {
load: (file: BIDSFile, options: any): Promise<M0Scan> => {
return Promise.resolve({ path: file.path })
},
},
magnitude: {
suffix: 'magnitude',
extensions: ['.nii', '.nii.gz'],
inherit: false,
load: (file: BIDSFile): Promise<Magnitude> => {
load: (file: BIDSFile, options: any): Promise<Magnitude> => {
return Promise.resolve({ path: file.path })
},
},
magnitude1: {
suffix: 'magnitude1',
extensions: ['.nii', '.nii.gz'],
inherit: false,
load: (file: BIDSFile): Promise<Magnitude1> => {
load: (file: BIDSFile, options: any): Promise<Magnitude1> => {
return Promise.resolve({ path: file.path })
},
},
bval: {
suffix: 'dwi',
extensions: ['.bval'],
inherit: true,
load: async (file: BIDSFile): Promise<Bval> => {
load: async (file: BIDSFile, options: any): Promise<Bval> => {
const contents = await file.text()
const rows = parseBvalBvec(contents)
return {
Expand All @@ -109,7 +110,7 @@ const associationLookup = {
suffix: 'dwi',
extensions: ['.bvec'],
inherit: true,
load: async (file: BIDSFile): Promise<Bvec> => {
load: async (file: BIDSFile, options: any): Promise<Bvec> => {
const contents = await file.text()
const rows = parseBvalBvec(contents)

Expand All @@ -128,8 +129,8 @@ const associationLookup = {
suffix: 'channels',
extensions: ['.tsv'],
inherit: true,
load: async (file: BIDSFile): Promise<Channels> => {
const columns = await loadTSV(file)
load: async (file: BIDSFile, options: { maxRows: number }): Promise<Channels> => {
const columns = await loadTSV(file, options.maxRows)
.catch((e) => {
return new Map()
})
Expand All @@ -145,7 +146,7 @@ const associationLookup = {
suffix: 'coordsystem',
extensions: ['.json'],
inherit: true,
load: (file: BIDSFile): Promise<Coordsystem> => {
load: (file: BIDSFile, options: any): Promise<Coordsystem> => {
return Promise.resolve({ path: file.path })
},
},
Expand All @@ -154,6 +155,7 @@ const associationLookup = {
export async function buildAssociations(
source: BIDSFile,
issues: DatasetIssues,
maxRows: number = -1,
): Promise<Associations> {
const associations: Associations = {}

Expand All @@ -177,7 +179,7 @@ export async function buildAssociations(

if (file) {
// @ts-expect-error Matching load return value to key is hard
associations[key] = await load(file).catch((error) => {
associations[key] = await load(file, { maxRows }).catch((error) => {
if (error.key) {
issues.add({ code: error.key, location: file.path })
}
Expand Down
6 changes: 5 additions & 1 deletion src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ export class BIDSContext implements Context {
}

async loadAssociations(): Promise<void> {
this.associations = await buildAssociations(this.file, this.dataset.issues)
this.associations = await buildAssociations(
this.file,
this.dataset.issues,
this.dataset.options?.maxRows,
)
return
}

Expand Down

0 comments on commit 7415c12

Please sign in to comment.