Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] BEP031: Microscopy #1359

Merged
merged 75 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cc51cc1
Added the microscopy Regex parts in the rules and added the function …
etiennebergeron Jul 28, 2021
8a854b8
Added the different microscopy modality suffixes
etiennebergeron Jul 28, 2021
00a8605
Add back the enter removed by accident in phenotypic_rules.json
etiennebergeron Jul 28, 2021
6ad4f0f
Created the file with the required metadata fields microscopy.json an…
etiennebergeron Jul 29, 2021
5b79bcf
JSON field 'AcquisitionParameters' is now 'OtherAcquisitionParameters'
etiennebergeron Jul 30, 2021
374bdde
Added error codes 214 and 215 for missing samples files. Added the fi…
etiennebergeron Aug 3, 2021
a5051d6
Corrected a typo between the 'pet' and 'microscopy' paths.
etiennebergeron Aug 4, 2021
6fc7cc5
Codes '216' and '217' added for 'PixelSizeUnits' and a missing recomm…
etiennebergeron Aug 4, 2021
a659e97
Removed code 214 since 'samples.json' is only recommended if samples.…
etiennebergeron Aug 4, 2021
5fc6c9a
Modified 'checkSamples.js' to check 'samples.tsv' instead of JSON. Mi…
etiennebergeron Aug 4, 2021
a061340
Modified again to check 'samples.tsv'.
etiennebergeron Aug 5, 2021
7978b57
The checkSamples method was working with 'samples.json', but not with…
etiennebergeron Aug 5, 2021
f3cc039
Didn't succeed to figure out how to detect samples.tsv. I restored th…
etiennebergeron Aug 5, 2021
44826a0
Removed enters in fullTest.js.
etiennebergeron Aug 5, 2021
ee5b8e2
Removed the warning for RECOMMENDED JSON fields missing. Doesn't seem…
etiennebergeron Aug 5, 2021
66e3e3d
Update bids-validator/utils/issues/list.js
etiennebergeron Aug 6, 2021
9c71d9b
Update bids-validator/validators/json/json.js
etiennebergeron Aug 6, 2021
586abbe
Changed the suffixes to uppercase in the rules and 'json.js'.
etiennebergeron Aug 6, 2021
a924c6a
Merge branch 'bids-standard:master' into bep031
etiennebergeron Aug 6, 2021
8f7bf7a
The entity 'sample' is REQUIRED in microscopy, so modified the regex …
etiennebergeron Aug 6, 2021
32b0aec
Added a new 'checkSamples.js' file, but this time based on 'checkRead…
etiennebergeron Aug 9, 2021
caacc19
Removed unnecessary import.
etiennebergeron Aug 9, 2021
e039372
Added the rules related to the 'samples.tsv' file in 'tsv.js'. Added …
etiennebergeron Aug 11, 2021
a0b6246
The PixelSizeUnits now needs to be in um. Currently using the existin…
etiennebergeron Aug 12, 2021
3135040
Merge branch 'bids-standard:master' into bep031
etiennebergeron Aug 19, 2021
1168a50
Added a dictionary 'microscopy_json' in the 'file_level_rules.json' t…
etiennebergeron Sep 16, 2021
a5bcb7a
Added the Regex rule for a file named _photo.jpg. Added the JSON fiel…
etiennebergeron Sep 19, 2021
5d0a27e
Entities order modified; <chunk> at the end.
etiennebergeron Sep 28, 2021
f2588ed
Merge branch 'master' into bep031
mariehbourget Oct 1, 2021
5bec57b
Modified tsv.js for samples.tsv ; now two different subjects can have a
etiennebergeron Oct 13, 2021
2873d73
Merge branch 'bep031' of https://github.com/neuropoly/bids-validator …
etiennebergeron Oct 13, 2021
8bde477
Completed the JSON fields ('TissueDeformationScaling' and 'SampleEnvi…
etiennebergeron Oct 21, 2021
a587434
Merge branch 'bids-standard:master' into bep031
etiennebergeron Oct 23, 2021
6345516
Merge branch 'master' of github.com:bids-standard/bids-validator into…
rwblair Nov 4, 2021
74d18c1
Resolve some issues that mentioned in BEP031 pr changes document
konantian Dec 5, 2021
a655568
Resolve comments from PR
konantian Dec 5, 2021
d1e27b9
Fix microscopy regexp
konantian Dec 6, 2021
c9a89f6
Merge branch 'bep031' into main-pr-changes
konantian Dec 6, 2021
c182b64
Remove "ChunkTransformationMatrix" from the recommended list
konantian Dec 7, 2021
d4025d0
Add regexp for _photo ext in microscopy
konantian Dec 8, 2021
aea59e0
Revert changes
konantian Dec 8, 2021
958bbea
Merge pull request #2 from neuropoly/main-pr-changes
konantian Dec 8, 2021
59a0bf8
1. Add Check for consistency for PixelSize between JSON and OME-TIFF …
konantian Dec 20, 2021
9ecc25d
Resolve comments
konantian Dec 21, 2021
759bdf7
Resolve comments
konantian Dec 23, 2021
ea6a5f3
Resolve comments
konantian Dec 23, 2021
1d3f0a4
Resolve comments
konantian Dec 24, 2021
aa15dbc
Rename folder ometiff to microscopy
konantian Dec 24, 2021
3f406e3
Merge pull request #3 from neuropoly/bep031-consistency-check
konantian Dec 24, 2021
fca9cdc
1. Update regex rules for microscopy
konantian Dec 27, 2021
79f006d
Update regex for matrix field check
konantian Dec 27, 2021
bfe860a
Bug fix
konantian Dec 28, 2021
d3478a3
Merge pull request #4 from neuropoly/bep031-minor-changes
konantian Dec 28, 2021
6a7ee58
Update the error message when sample type is not valid
konantian Dec 29, 2021
1a778ba
1. Add validation for tiff and big tiff
konantian Jan 2, 2022
1dc89e2
Change an error to warning
konantian Jan 3, 2022
0a1b53b
Merge pull request #5 from neuropoly/bep031-tiff-validation
konantian Jan 3, 2022
c7b95fb
Merge branch 'master' into bep031
konantian Jan 3, 2022
b9428aa
Update validation for OME namespace
konantian Jan 6, 2022
4daf782
add tests for checkJSONAndField
rwblair Jan 6, 2022
8e23cba
add tests for checkSample.js
rwblair Jan 6, 2022
7d1e4ad
add tests for microscopy validate.js and test data
rwblair Jan 6, 2022
fb5da0a
add param docs to readFile function
rwblair Jan 6, 2022
e7ebc94
generate error if magic number is incorrect on tiff file
rwblair Jan 6, 2022
3e67824
Fix code style
konantian Jan 7, 2022
2fed58a
Merge pull request #6 from neuropoly/bep031-update-namespace
konantian Jan 7, 2022
b920d2d
move new dependencies into validator package.json
rwblair Jan 7, 2022
7588c0e
have micro json check use old sidecar generation function
rwblair Jan 7, 2022
0b7fd4f
Merge branch 'bep031' of github.com:neuropoly/bids-validator into HEAD
rwblair Jan 7, 2022
9e3cabe
rearrange logic for samples.tsv validation. Add tests.
rwblair Jan 7, 2022
5fdb675
updated package-lock to reflect package.json changes.
rwblair Jan 7, 2022
5862244
have microscopy json check return empty list if no other issues found
rwblair Jan 11, 2022
877e8c7
set esbuild buffer size env in bin/bids-validator when we are using e…
rwblair Jan 12, 2022
d5ad033
added babel runtime to web package.json, maybe it was just my setup b…
rwblair Jan 12, 2022
bd78f58
Merge pull request #7 from bids-standard/bep031_review_updates
mariehbourget Jan 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bids-validator-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.16.7",
"bootstrap": "^4.3.0",
"bowser": "^1.0.0",
"next": "^11.1.2",
Expand Down
65 changes: 65 additions & 0 deletions bids-validator/bids_validator/rules/file_level_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,5 +523,70 @@
"tokens": {
"@@@_pet_ext_@@@": ["blood\\.tsv\\.gz", "blood\\.tsv", "blood\\.json"]
}
},

"microscopy": {
"regexp": "^[\\/\\\\](sub-[a-zA-Z0-9]+)[\\/\\\\](?:(ses-[a-zA-Z0-9]+)[\\/\\\\])?micr[\\/\\\\](sub-[a-zA-Z0-9]+)(?:(_ses-[a-zA-Z0-9]+))?(?:_sample-[a-zA-Z0-9]+)(?:_acq-[a-zA-Z0-9]+)?(?:_stain-[a-zA-Z0-9]+)?(?:_run-[0-9]+)?(?:_chunk-[0-9]+)?((@@@_microscopy_type_@@@)(@@@_microscopy_ext_@@@))$",
"tokens": {
"@@@_microscopy_type_@@@": [
"_TEM",
"_SEM",
"_uCT",
"_BF",
"_DF",
"_PC",
"_DIC",
"_FLUO",
"_CONF",
"_PLI",
"_CARS",
"_2PE",
"_MPE",
"_SR",
"_NLO",
"_OCT",
"_SPIM"
],
"@@@_microscopy_ext_@@@": [
".ome\\.tif",
".ome\\.btf",
".tif",
".png"
]
}
},
"microscopy_photo": {
"regexp": "^[\\/\\\\](sub-[a-zA-Z0-9]+)[\\/\\\\](?:(ses-[a-zA-Z0-9]+)[\\/\\\\])?micr[\\/\\\\](sub-[a-zA-Z0-9]+)(?:(_ses-[a-zA-Z0-9]+))?(?:_sample-[a-zA-Z0-9]+)(?:_acq-[a-zA-Z0-9]+)?(@@@_photo_ext_@@@)$",
"tokens":{
"@@@_photo_ext_@@@": [
"_photo\\.jpg",
"_photo\\.png",
"_photo\\.tif"
]
}
},
"microscopy_json": {
"regexp": "^[\\/\\\\](sub-[a-zA-Z0-9]+)[\\/\\\\](?:(ses-[a-zA-Z0-9]+)[\\/\\\\])?micr[\\/\\\\](sub-[a-zA-Z0-9]+)(?:(_ses-[a-zA-Z0-9]+))?(?:_sample-[a-zA-Z0-9]+)?(?:_acq-[a-zA-Z0-9]+)?(?:_stain-[a-zA-Z0-9]+)?(?:_run-[0-9]+)?(?:_chunk-[0-9]+)?(@@@_microscopy_type_@@@)\\.json$",
"tokens": {
"@@@_microscopy_type_@@@": [
"_TEM",
"_SEM",
"_uCT",
"_BF",
"_DF",
"_PC",
"_DIC",
"_FLUO",
"_CONF",
"_PLI",
"_CARS",
"_2PE",
"_MPE",
"_SR",
"_NLO",
"_OCT",
"_SPIM"
]
}
}
}
25 changes: 25 additions & 0 deletions bids-validator/bids_validator/rules/session_level_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,30 @@
"UNCInfant2V23"
]
}
},

"microscopy_ses": {
"regexp": "^[\\/\\\\](sub-[a-zA-Z0-9]+)[\\/\\\\](?:(ses-[a-zA-Z0-9]+)[\\/\\\\])?\\1(_\\2)?(?:_sample-[a-zA-Z0-9]+)?(?:_acq-[a-zA-Z0-9]+)?(?:_stain-[a-zA-Z0-9]+)?(?:_run-[0-9]+_)?(?:_chunk-[0-9]+)?(@@@_microscopy_ses_type_@@@)$",
"tokens": {
"@@@_microscopy_ses_type_@@@": [
"_TEM.json",
"_SEM.json",
"_uCT.json",
"_BF.json",
"_DF.json",
"_PC.json",
"_DIC.json",
"_FLUO.json",
"_CONF.json",
"_PLI.json",
"_CARS.json",
"_2PE.json",
"_MPE.json",
"_SR.json",
"_NLO.json",
"_OCT.json",
"_SPIM.json"
]
}
}
}
29 changes: 28 additions & 1 deletion bids-validator/bids_validator/rules/top_level_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"phase2.json",
"fieldmap.json",
"events.json",
"scans.json"
"scans.json",
"samples.json",
"samples.tsv"
]
}
},
Expand Down Expand Up @@ -133,5 +135,30 @@
"tokens": {
"@@@_other_top_files_ext_@@@": ["physio\\.json", "stim\\.json"]
}
},

"microscopy_top": {
"regexp": "^[\\/\\\\](?:ses-[a-zA-Z0-9]+_)?(?:_sample-[a-zA-Z0-9]+)?(?:_acq-[a-zA-Z0-9]+)?(?:_stain-[a-zA-Z0-9]+)?(?:_run-[0-9]+)?(?:_chunk-[0-9]+)?(?:@@@_microscopy_top_ext_@@@)$",
"tokens": {
"@@@_microscopy_top_ext_@@@": [
"_TEM\\.json",
"_SEM\\.json",
"_uCT\\.json",
"_BF\\.json",
"_DF\\.json",
"_PC\\.json",
"_DIC\\.json",
"_FLUO\\.json",
"_CONF\\.json",
"_PLI\\.json",
"_CARS\\.json",
"_2PE\\.json",
"_MPE\\.json",
"_SR\\.json",
"_NLO\\.json",
"_OCT\\.json",
"_SPIM\\.json"
]
}
}
}
1 change: 1 addition & 0 deletions bids-validator/bin/bids-validator
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function entry(cli) {
try {
// Test if there's a development tree to run
require.resolve('../cli.js')
process.env.ESBUILD_MAX_BUFFER = 64 * 1024 * 1024
// For dev, use esbuild-runner
require('esbuild-runner/register')
const { default: cli } = require('../cli.js')
Expand Down
4 changes: 3 additions & 1 deletion bids-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
"stream-browserify": "^3.0.0",
"table": "^5.2.3",
"yaml": "^1.10.2",
"yargs": "^16.2.0"
"yargs": "^16.2.0",
"exifreader": "^4.1.0",
"xml2js": "^0.4.23"
},
"devDependencies": {
"adm-zip": "",
Expand Down
26 changes: 26 additions & 0 deletions bids-validator/tests/tsv.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,30 @@ describe('TSV', function() {
let issues = validate.TSV.validateContRec([physio_file], {})
assert(issues.length === 1 && issues[0].code === 133)
})

// samples checks -----------------------------------------------------------

const samplesFile = {
name: 'samples.tsv',
relativePath: '/samples.tsv',
}

it('should return errors for each missing mandatory header in samples.tsv', () => {
const tsv = 'wrong_col\nsome_data\n'
validate.TSV.TSV(samplesFile, tsv, [], function(issues) {
expect(issues.length).toBe(3)
const codes = issues.map(x => x.code)
expect(codes.includes(216)).toBe(true)
expect(codes.includes(217)).toBe(true)
expect(codes.includes(218)).toBe(true)
})
})

it('should return an error for invalid sample_type samples.tsv', () => {
const tsv = 'sample_type\nbad\n'
validate.TSV.TSV(samplesFile, tsv, [], function(issues) {
const codes = issues.map(x => x.code)
expect(codes.includes(219)).toBe(true)
})
})
})
4 changes: 4 additions & 0 deletions bids-validator/utils/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import FileAPI from './FileAPI'

import newFile from './newFile'
import readFile from './readFile'
import readOMEFile from './readOMEFile'
import readBuffer from './readBuffer'
import readNiftiHeader from './readNiftiHeader'
import readDir from './readDir'
import potentialLocations from './potentialLocations'
Expand All @@ -21,6 +23,8 @@ export default {
newFile,
readFile,
readDir,
readBuffer,
readOMEFile,
readNiftiHeader,
generateMergedSidecarDict,
potentialLocations,
Expand Down
23 changes: 23 additions & 0 deletions bids-validator/utils/files/readBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import isNode from '../isNode'
import fs from 'fs'

const readBuffer = file => {
return new Promise((resolve, reject) => {
if (isNode) {
resolve(fs.readFileSync(file.path))
} else {
try {
const reader = new FileReader()
reader.onload = event => {
resolve(event.target.result)
}

reader.readAsArrayBuffer(file)
} catch (e) {
reject(e)
}
}
})
}

export default readBuffer
10 changes: 7 additions & 3 deletions bids-validator/utils/files/readFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const checkEncoding = (file, data, cb) => {
}

/**
* Read
* readFile
* @param {object | File} file - nodeJS fs file or browser File
* @param {boolean} annexed - is the file currently annexed?
* @param {string} dir - path to directory containing dataset. Only used if
* annexed is true.
*
* A helper method for reading file contents.
* Takes a file object and a callback and calls
Expand All @@ -39,12 +43,12 @@ const checkEncoding = (file, data, cb) => {
function readFile(file, annexed, dir) {
return new Promise((resolve, reject) => {
if (isNode) {
testFile(file, annexed, dir, function (issue, stats, remoteBuffer) {
testFile(file, annexed, dir, function(issue, stats, remoteBuffer) {
if (issue) {
return reject(issue)
}
if (!remoteBuffer) {
fs.readFile(file.path, function (err, data) {
fs.readFile(file.path, function(err, data) {
if (err) {
return reject(err)
}
Expand Down
17 changes: 17 additions & 0 deletions bids-validator/utils/files/readOMEFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ExifReader from 'exifreader'
rwblair marked this conversation as resolved.
Show resolved Hide resolved
const xml2js = require('xml2js')

const readOMEFile = buffer => {
let tags = ExifReader.load(buffer)
let xml = tags['ImageDescription']['description']
return new Promise((resolve, reject) => {
xml2js
.parseStringPromise(xml)
.then(result => {
resolve(result)
})
.catch(error => reject(error))
})
}

export default readOMEFile
76 changes: 76 additions & 0 deletions bids-validator/utils/issues/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,4 +1042,80 @@ export default {
reason:
'The recommended file /README is very small. Please consider expanding it with additional information about the dataset.',
},
214: {
key: 'SAMPLES_TSV_MISSING',
severity: 'error',
reason:
'The compulsory file /samples.tsv is missing. See Section 03 (Modality agnostic files) of the BIDS specification.',
},
215: {
key: 'SAMPLE_ID_PATTERN',
severity: 'error',
reason:
'sample_id column labels must consist of the pattern "sample-<sample_id>".',
},
216: {
key: 'SAMPLE_ID_COLUMN',
severity: 'error',
reason: "Samples .tsv files must have a 'sample_id' column.",
},
217: {
key: 'PARTICIPANT_ID_COLUMN',
severity: 'error',
reason: "Samples .tsv files must have a 'participant_id' column.",
},
218: {
key: 'SAMPLE_TYPE_COLUMN',
severity: 'error',
reason: "Samples .tsv files must have a 'sample_type' column.",
},
219: {
key: 'SAMPLE_TYPE_VALUE',
severity: 'error',
reason:
'sample_type MUST consist of one of the following values: cell line, in vitro differentiated cells, primary cell, cell-free sample, cloning host, tissue, whole organisms, organoid or technical sample.',
},
220: {
key: 'SAMPLE_ID_DUPLICATE',
severity: 'error',
reason:
'Each sample from a same subject MUST be described by one and only one row.',
},
221: {
key: 'PIXEL_SIZE_INCONSISTENT',
severity: 'error',
reason:
'PixelSize need to be consistent with PhysicalSizeX, PhysicalSizeY and PhysicalSizeZ OME metadata fields',
},
222: {
key: 'INVALID_PIXEL_SIZE_UNIT',
severity: 'warning',
reason: 'PixelSize consistency is only validated for "mm", "µm" and "nm".',
},
223: {
key: 'CHUNK_TRANSFORMATION_MATRIX_MISSING',
severity: 'warning',
reason:
"It is recommended to define 'ChunkTransformationMatrix' for this file.",
},
224: {
key: 'OPTIONAL_FIELD_INCONSISTENT',
severity: 'error',
reason: 'Optional JSON field is not consistent with the OME-TIFF metadata',
},
225: {
key: 'NO_VALID_JSON',
severity: 'error',
reason: 'No valid JSON file found for this file',
},
226: {
key: 'UNSUPPORTED_BIG_TIFF',
severity: 'warning',
reason: 'Metadata consistency check skipped for BigTiff OME-TIFF file',
},
227: {
key: 'INCONSISTENT_TIFF_EXTENSION',
severity: 'error',
reason: 'Inconsistent TIFF file type and extension',
},
}
4 changes: 4 additions & 0 deletions bids-validator/utils/summary/collectModalities.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const collectModalities = filenames => {
MEG: 0,
EEG: 0,
iEEG: 0,
Microscopy: 0,
}
const secondary = {
MRI_Diffusion: 0,
Expand Down Expand Up @@ -56,6 +57,9 @@ export const collectModalities = filenames => {
if (type.file.isIEEG(path)) {
modalities.iEEG++
}
if (type.file.isMicroscopy(path)) {
modalities.Microscopy++
}
}
// Order by matching file count
const nonZero = Object.keys(modalities).filter(a => modalities[a] !== 0)
Expand Down
Loading