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] Standardized query result files #398

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
20 changes: 10 additions & 10 deletions cypress/e2e/ResultsTSV.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ describe('Unprotected response', () => {
expect(phenotypicSession.split('\t')[4]).to.equal('ses-nb01');
expect(phenotypicSession.split('\t')[5]).to.equal('');
expect(phenotypicSession.split('\t')[6]).to.equal('Phenotypic');
expect(phenotypicSession.split('\t')[7]).to.equal('10.4');
expect(phenotypicSession.split('\t')[8]).to.equal('female');
expect(phenotypicSession.split('\t')[9]).to.equal('Major depressive disorder');
expect(phenotypicSession.split('\t')[10]).to.equal('multisource interference task');
expect(phenotypicSession.split('\t')[11]).to.equal('1');
expect(phenotypicSession.split('\t')[12]).to.equal('0');
expect(phenotypicSession.split('\t')[7]).to.equal('1');
expect(phenotypicSession.split('\t')[8]).to.equal('0');
expect(phenotypicSession.split('\t')[9]).to.equal('10.4');
expect(phenotypicSession.split('\t')[10]).to.equal('female');
expect(phenotypicSession.split('\t')[11]).to.equal('Major depressive disorder');
expect(phenotypicSession.split('\t')[12]).to.equal('multisource interference task');
expect(phenotypicSession.split('\t')[13]).to.equal('');
expect(phenotypicSession.split('\t')[14]).to.equal('');
expect(phenotypicSession.split('\t')[15]).to.equal('Flow Weighted, T2 Weighted');
Expand All @@ -127,12 +127,12 @@ describe('Unprotected response', () => {
expect(imagingSession.split('\t')[4]).to.equal('ses-nb01');
expect(imagingSession.split('\t')[5]).to.equal('/ds004116/sub-300101');
expect(imagingSession.split('\t')[6]).to.equal('Imaging');
expect(imagingSession.split('\t')[7]).to.equal('');
expect(imagingSession.split('\t')[8]).to.equal('');
expect(imagingSession.split('\t')[7]).to.equal('0');
expect(imagingSession.split('\t')[8]).to.equal('1');
expect(imagingSession.split('\t')[9]).to.equal('');
expect(imagingSession.split('\t')[10]).to.equal('');
expect(imagingSession.split('\t')[11]).to.equal('0');
expect(imagingSession.split('\t')[12]).to.equal('1');
expect(imagingSession.split('\t')[11]).to.equal('');
expect(imagingSession.split('\t')[12]).to.equal('');
expect(imagingSession.split('\t')[13]).to.equal('Flow Weighted, T2 Weighted');
expect(imagingSession.split('\t')[14]).to.equal('fmriprep 23.1.3, freesurfer 7.3.2');
expect(imagingSession.split('\t')[15]).to.equal('Flow Weighted, T2 Weighted');
Expand Down
220 changes: 88 additions & 132 deletions src/components/ResultContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,147 +144,103 @@ function ResultContainer({
if (response) {
const tsvRows = [];
const datasets = response.responses.filter((res) => download.includes(res.dataset_uuid));
const isHumanFile = buttonIdentifier === 'cohort-participant';

if (buttonIdentifier === 'cohort-participant') {
const headers = [
'DatasetName',
'PortalURI',
'NumMatchingSubjects',
'SubjectID',
'SessionID',
'SessionFilePath',
'SessionType',
'Age',
'Sex',
'Diagnosis',
'Assessment',
'NumMatchingPhenotypicSessions',
'NumMatchingImagingSessions',
'SessionImagingModalities',
'SessionCompletedPipelines',
'DatasetImagingModalities',
'DatasetPipelines',
].join('\t');
tsvRows.push(headers);

datasets.forEach((res) => {
if (res.records_protected) {
tsvRows.push(
[
res.dataset_name.replace('\n', ' '),
res.dataset_portal_uri,
res.num_matching_subjects,
'protected', // subject_id
'protected', // session_id
'protected', // session_file_path
'protected', // session_type
'protected', // age
'protected', // sex
'protected', // diagnosis
'protected', // assessment
'protected', // num_matching_phenotypic_sessions
'protected', // num_matching_imaging_sessions
'protected', // session_imaging_modality
'protected', // session_completed_pipelines
convertURIToLabel('modality', res.image_modals),
convertURIToLabel(
'pipeline',
parsePipelinesInfoToString(res.available_pipelines).split(', ')
),
].join('\t')
);
} else {
// @ts-expect-error: typescript doesn't know that subject_data is an array when records_protected is false.
res.subject_data.forEach((subject) => {
tsvRows.push(
[
res.dataset_name.replace('\n', ' '),
res.dataset_portal_uri,
res.num_matching_subjects,
subject.sub_id,
subject.session_id,
subject.session_file_path,
convertURIToLabel('sessionType', subject.session_type),
subject.age,
convertURIToLabel('sex', subject.sex),
convertURIToLabel('diagnosis', subject.diagnosis),
convertURIToLabel('assessment', subject.assessment),
subject.num_matching_phenotypic_sessions,
subject.num_matching_imaging_sessions,
convertURIToLabel('modality', subject.image_modal),
convertURIToLabel(
'pipeline',
parsePipelinesInfoToString(subject.completed_pipelines).split(', ')
),
convertURIToLabel('modality', res.image_modals),
convertURIToLabel(
const headers = [
'DatasetName',
'PortalURI',
'NumMatchingSubjects',
'SubjectID',
'SessionID',
'ImagingSessionPath',
'SessionType',
'NumMatchingPhenotypicSessions',
'NumMatchingImagingSessions',
'Age',
'Sex',
'Diagnosis',
'Assessment',
'SessionImagingModalities',
'SessionCompletedPipelines',
'DatasetImagingModalities',
'DatasetPipelines',
].join('\t');
tsvRows.push(headers);
datasets.forEach((res) => {
if (res.records_protected) {
tsvRows.push(
[
res.dataset_name.replace('\n', ' '),
res.dataset_portal_uri,
res.num_matching_subjects,
'protected', // subject_id
'protected', // session_id
'protected', // session_file_path
'protected', // session_type
'protected', // num_matching_phenotypic_sessions
'protected', // num_matching_imaging_sessions
'protected', // age
'protected', // sex
'protected', // diagnosis
'protected', // assessment
'protected', // session_imaging_modality
'protected', // session_completed_pipelines
isHumanFile
? convertURIToLabel('modality', res.image_modals)
: res.image_modals?.join(', '),
isHumanFile
? convertURIToLabel(
'pipeline',
parsePipelinesInfoToString(res.available_pipelines).split(', ')
),
].join('\t')
);
});
}
});
} else {
const headers = [
'DatasetName',
'PortalURI',
'SubjectID',
'SessionID',
'SessionFilePath',
'SessionType',
'NumMatchingPhenotypicSessions',
'NumMatchingImagingSessions',
'SessionImagingModalities',
'SessionCompletedPipelines',
'DatasetImagingModalities',
'DatasetPipelines',
].join('\t');
tsvRows.push(headers);

datasets.forEach((res) => {
if (res.records_protected) {
)
: parsePipelinesInfoToString(res.available_pipelines),
].join('\t')
);
} else {
// @ts-expect-error: typescript doesn't know that subject_data is an array when records_protected is false.
res.subject_data.forEach((subject) => {
tsvRows.push(
[
res.dataset_name.replace('\n', ' '),
res.dataset_portal_uri,
'protected', // subject_id
'protected', // session_id
'protected', // session_file_path
'protected', // session_type
'protected', // num_matching_phenotypic_sessions
'protected', // num_matching_imaging_sessions
'protected', // session_imaging_modality
'protected', // session_completed_pipelines
res.image_modals?.join(', '),
parsePipelinesInfoToString(res.available_pipelines),
res.num_matching_subjects,
subject.sub_id,
subject.session_id,
subject.session_file_path,
isHumanFile
? convertURIToLabel('sessionType', subject.session_type)
: subject.session_type,
subject.num_matching_phenotypic_sessions,
subject.num_matching_imaging_sessions,
subject.age,
isHumanFile ? convertURIToLabel('sex', subject.sex) : subject.sex,
isHumanFile ? convertURIToLabel('diagnosis', subject.diagnosis) : subject.diagnosis,
isHumanFile
? convertURIToLabel('assessment', subject.assessment)
: subject.assessment,
isHumanFile
? convertURIToLabel('modality', subject.image_modal)
: subject.image_modal?.join(', '),
isHumanFile
? convertURIToLabel(
'pipeline',
parsePipelinesInfoToString(subject.completed_pipelines).split(', ')
)
: parsePipelinesInfoToString(subject.completed_pipelines),
isHumanFile
? convertURIToLabel('modality', res.image_modals)
: res.image_modals?.join(', '),
isHumanFile
? convertURIToLabel(
'pipeline',
parsePipelinesInfoToString(res.available_pipelines).split(', ')
)
: parsePipelinesInfoToString(res.available_pipelines),
].join('\t')
);
} else {
// @ts-expect-error: typescript doesn't know that subject_data is an array when records_protected is false.
res.subject_data.forEach((subject) => {
tsvRows.push(
[
res.dataset_name.replace('\n', ' '),
res.dataset_portal_uri,
subject.sub_id,
subject.session_id,
subject.session_file_path,
subject.session_type,
subject.num_matching_phenotypic_sessions,
subject.num_matching_imaging_sessions,
subject.image_modal?.join(', '),
parsePipelinesInfoToString(subject.completed_pipelines),
res.image_modals?.join(', '),
parsePipelinesInfoToString(res.available_pipelines),
].join('\t')
);
});
}
});
}

});
}
});
return tsvRows.join('\n');
}

Expand Down
Loading