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

Study view custom sample selection with multi study #4867

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _ from 'lodash';
import _, { uniq } from 'lodash';
import { Sample } from 'cbioportal-ts-api-client';
import { ClinicalDataType, ClinicalDataTypeEnum } from '../../StudyViewUtils';
import Pluralize from 'pluralize';
Expand Down Expand Up @@ -132,6 +132,7 @@ export function validateLines(

let occurrence: { [key: string]: number } = {};
let validLines: { [key: string]: InputLine } = {};
let multiStudyCases: string[] = [];

// Remove all dups, not necessary to mention in the message
_.reduce(
Expand All @@ -140,27 +141,34 @@ export function validateLines(
}),
(acc, line) => {
let _case = '';
let validLine = true;
let validLine = false;
let newLines: InputLine[] = [];
if (line.studyId === undefined || line.studyId === '') {
if (!isSingleStudy) {
warningMessages.push({
code: CodeEnum.INVALID_CASE_ID,
message: new Error(
`No study specified for ${caseType} id: ${line.caseId}, and more than one study selected for query. The case will be ignored.`
),
});
validLine = false;
} else {
_case = getUniqueCaseId(selectedStudies[0], line.caseId);
if (!validPair[_case]) {
invalidCases.push(line.caseId);
validLine = false;
} else {
let validCaseCount = 0;
selectedStudies.map(studyId => {
_case = getUniqueCaseId(studyId, line.caseId);
if (validPair[_case]) {
if (occurrence[_case] === undefined) {
occurrence[_case] = 0;
}
occurrence[_case]++;

let newLine = _.cloneDeep(line);
newLine.studyId = studyId;
newLines.push(newLine);

validCaseCount += 1;
validLine = true;
}
});

if (validCaseCount === 0) {
invalidCases.push(line.caseId);
}

// case where it belongs to multiple studies
if (validCaseCount > 1) {
multiStudyCases.push(line.caseId);
}
} else {
if (!_.includes(selectedStudies, line.studyId)) {
Expand All @@ -170,28 +178,42 @@ export function validateLines(
`Incorrect study id: ${line.studyId}`
),
});
validLine = false;
} else {
_case = getUniqueCaseId(line.studyId, line.caseId);
if (validPair[_case] !== undefined) {
if (occurrence[_case] === undefined) {
occurrence[_case] = 0;
}
occurrence[_case]++;
validLine = true;
} else {
invalidCases.push(line.caseId);
validLine = false;
}
newLines.push(_.cloneDeep(line));
}
}

if (validLine) {
acc[getInputLineKey(line)] = line;
_.forEach(newLines, newLine => {
acc[getInputLineKey(newLine)] = newLine;
});
}
return acc;
},
validLines
);

if (!isSingleStudy && !_.isEmpty(multiStudyCases)) {
warningMessages.push({
code: CodeEnum.INVALID_CASE_ID,
message: new Error(
`The ${caseType} ID's below belong to multiple studies. All of them in the different studies will be selected.
To select specific ${caseType}, pelase specify study_id, Example: study_id:sample_id.
${caseType} ID's: ${multiStudyCases.join(', ')}`
),
});
}

// Find duplication cases
const dups = _.reduce(
occurrence,
Expand Down
Loading