Skip to content

Commit

Permalink
[ENH] Standardized query result files (#398)
Browse files Browse the repository at this point in the history
* Standardized query result files

* Addressed the PR review comments
  • Loading branch information
rmanaem authored Dec 13, 2024
1 parent 178f377 commit 8277948
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 151 deletions.
32 changes: 16 additions & 16 deletions cypress/e2e/ResultsTSV.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ 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');
expect(phenotypicSession.split('\t')[16]).to.equal('fmriprep 23.1.3, freesurfer 7.3.2');
expect(phenotypicSession.split('\t')[15]).to.equal('Flow Weighted,T2 Weighted');
expect(phenotypicSession.split('\t')[16]).to.equal('fmriprep 23.1.3,freesurfer 7.3.2');

expect(imagingSession.split('\t')[0]).to.equal('some dataset');
expect(imagingSession.split('\t')[1]).to.equal(
Expand All @@ -127,16 +127,16 @@ 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')[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');
expect(imagingSession.split('\t')[16]).to.equal('fmriprep 23.1.3, freesurfer 7.3.2');
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');
expect(imagingSession.split('\t')[16]).to.equal('fmriprep 23.1.3,freesurfer 7.3.2');
});
});
});
226 changes: 91 additions & 135 deletions src/components/ResultContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function ResultContainer({
): string | string[] | null {
// Handle array of URIs
if (Array.isArray(uri)) {
return uri.map((singleUri) => convertURIToLabel(type, singleUri)).join(', ');
return uri.map((singleUri) => convertURIToLabel(type, singleUri)).join(',');
}

if (!uri) {
Expand Down Expand Up @@ -136,155 +136,111 @@ function ResultContainer({
.flatMap(([name, versions]) =>
(versions as string[]).map((version: string) => `${name} ${version}`)
)
.join(', ')
.join(',')
: '';
}

function generateTSVString(buttonIdentifier: string) {
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(
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(subject.completed_pipelines).split(', ')
),
convertURIToLabel('modality', res.image_modals),
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).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,
'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

0 comments on commit 8277948

Please sign in to comment.