Skip to content

Commit

Permalink
Merge pull request #1449 from kalletlak/fix-4502
Browse files Browse the repository at this point in the history
Fix case list issue when all cases list is tagged under other category
  • Loading branch information
inodb authored Sep 17, 2018
2 parents 3cbf4d8 + da2425e commit 78126de
Showing 1 changed file with 48 additions and 52 deletions.
100 changes: 48 additions & 52 deletions src/shared/components/query/QueryStoreUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,78 +120,74 @@ export function profileAvailability(molecularProfiles:MolecularProfile[]) {
};
}

export function categorizedSamplesCount(sampleLists: SampleList[],selectedStudies:string[],selectedVirtualStudies:VirtualStudy[]) {
let mutationSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};
let cnaSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};
let mutationCnaSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};
let allSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};

let filteredMutationSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};
let filteredCnaSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};
let filteredMutationCnaSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};
let filteredallSamples: { [studyId: string]: { [sampleId: string]: boolean } } = {};

sampleLists
.filter(sampleList => _.includes(['all_cases_in_study', 'all_cases_with_mutation_and_cna_data', 'all_cases_with_mutation_data', 'all_cases_with_cna_data'], sampleList.category))
.forEach(sampleList => {
let samples: { [sampleId: string]: boolean } =
_.reduce(sampleList.sampleIds, (acc: { [sampleId: string]: boolean }, next) => {
acc[next] = true;
return acc;
}, {});

switch (sampleList.category) {
case "all_cases_with_mutation_and_cna_data":
mutationCnaSamples[sampleList.studyId] = samples;
break;
case "all_cases_with_mutation_data":
mutationSamples[sampleList.studyId] = samples;
break;
case "all_cases_with_cna_data":
cnaSamples[sampleList.studyId] = samples;
break;
case "all_cases_in_study":
allSamples[sampleList.studyId] = samples;
break;
export function categorizedSamplesCount(sampleLists: SampleList[], selectedStudies: string[], selectedVirtualStudies: VirtualStudy[]) {
let mutationSamples: { [studyId: string]: { [sampleId: string]: string } } = {};
let cnaSamples: { [studyId: string]: { [sampleId: string]: string } } = {};
let mutationCnaSamples: { [studyId: string]: { [sampleId: string]: string } } = {};
let allSamples: { [studyId: string]: { [sampleId: string]: string } } = {};

let filteredMutationSamples: { [studyId: string]: { [sampleId: string]: string } } = {};
let filteredCnaSamples: { [studyId: string]: { [sampleId: string]: string } } = {};
let filteredMutationCnaSamples: { [studyId: string]: { [sampleId: string]: string } } = {};
let filteredallSamples: { [studyId: string]: { [sampleId: string]: string } } = {};

_.each(sampleLists, sampleList => {
switch (sampleList.category) {
case "all_cases_with_mutation_and_cna_data":
mutationCnaSamples[sampleList.studyId] = _.keyBy(sampleList.sampleIds);
break;
case "all_cases_with_mutation_data":
mutationSamples[sampleList.studyId] = _.keyBy(sampleList.sampleIds);
break;
case "all_cases_with_cna_data":
cnaSamples[sampleList.studyId] = _.keyBy(sampleList.sampleIds);
break;
case "all_cases_in_study":
allSamples[sampleList.studyId] = _.keyBy(sampleList.sampleIds);
break;
default: {
// this in case if the all cases list is tagged under other category
if (sampleList.sampleListId === sampleList.studyId + '_all') {
allSamples[sampleList.studyId] = _.keyBy(sampleList.sampleIds);
}
}
});
}
});

let selectedVirtualStudySet: { [id: string]: VirtualStudy } =_.reduce(selectedVirtualStudies, (acc: { [id: string]: VirtualStudy }, next) => {
acc[next.id] = next; return acc
}, {});
let selectedPhysicalStudyIds = selectedStudies.filter(id => !_.has(selectedVirtualStudySet, id));
const selectedVirtualStudyIds = _.map(selectedVirtualStudies, virtualStudy => virtualStudy.id);
const selectedPhysicalStudyIds = selectedStudies.filter(id => !_.includes(selectedVirtualStudyIds, id));

//add all samples from selected physical studies
_.forEach(selectedPhysicalStudyIds,studyId=>{
_.forEach(selectedPhysicalStudyIds, studyId => {
filteredMutationSamples[studyId] = mutationSamples[studyId] || {};
filteredCnaSamples[studyId] = cnaSamples[studyId] || {};
filteredMutationCnaSamples[studyId] = mutationCnaSamples[studyId] || {};
filteredallSamples[studyId] = allSamples[studyId] || {};
});

_.forEach(selectedVirtualStudySet,virtualStudy=>{
_.forEach(virtualStudy.data.studies,study=>{
_.forEach(selectedVirtualStudies, virtualStudy => {
_.forEach(virtualStudy.data.studies, study => {

// check if the study in this virtual study is already in the selected studies list
// and only add the samples if its not already present
if(!_.includes(selectedPhysicalStudyIds,study.id)){
if (!_.includes(selectedPhysicalStudyIds, study.id)) {
filteredMutationSamples[study.id] = filteredMutationSamples[study.id] || {};
filteredCnaSamples[study.id] = filteredCnaSamples[study.id] || {};
filteredMutationCnaSamples[study.id] = filteredMutationCnaSamples[study.id] || {};
filteredallSamples[study.id] = filteredallSamples[study.id] || {};

_.forEach(study.samples,sampleId=>{
if(mutationSamples[study.id] && mutationSamples[study.id][sampleId]){
filteredMutationSamples[study.id][sampleId] = true;
_.forEach(study.samples, sampleId => {
if (mutationSamples[study.id] && mutationSamples[study.id][sampleId]) {
filteredMutationSamples[study.id][sampleId] = sampleId;
}
if(cnaSamples[study.id] && cnaSamples[study.id][sampleId]){
filteredCnaSamples[study.id][sampleId] = true;
if (cnaSamples[study.id] && cnaSamples[study.id][sampleId]) {
filteredCnaSamples[study.id][sampleId] = sampleId;
}
if(mutationCnaSamples[study.id] && mutationCnaSamples[study.id][sampleId]){
filteredMutationCnaSamples[study.id][sampleId] = true;
if (mutationCnaSamples[study.id] && mutationCnaSamples[study.id][sampleId]) {
filteredMutationCnaSamples[study.id][sampleId] = sampleId;
}
if(allSamples[study.id] && allSamples[study.id][sampleId]){
filteredallSamples[study.id][sampleId] = true;
if (allSamples[study.id] && allSamples[study.id][sampleId]) {
filteredallSamples[study.id][sampleId] = sampleId;
}
});
}
Expand Down

0 comments on commit 78126de

Please sign in to comment.