Skip to content

Commit d607f22

Browse files
committed
Optimization to how groupsamples are created; by using the sample unique id we can create sampleidentifier
1 parent 89b830e commit d607f22

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

src/pages/studyView/StudyViewPageStore.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,11 +1650,12 @@ export class StudyViewPageStore
16501650
chartMeta.uniqueKey
16511651
);
16521652
if (!chartInfo || !this.hasFilteredSamples) return;
1653+
const includeSampleIds = true;
16531654

16541655
const data: any[] = await invokeGenomicDataCountIncludeSampleid(
16551656
chartInfo,
16561657
this.filters,
1657-
true
1658+
includeSampleIds
16581659
);
16591660

16601661
const lcValueToColor = _.keyBy(clinicalAttributeValues, d =>
@@ -1672,7 +1673,7 @@ export class StudyViewPageStore
16721673

16731674
/**
16741675
* Step 2:
1675-
* Build SessionGroupData objects for each group, using the sample ids from step 1
1676+
* Build SessionGroupData objects for each group, using the sample identifiers from step 1
16761677
*/
16771678
const groups: SessionGroupData[] = _.chain(
16781679
clinicalAttributeValues
@@ -1697,9 +1698,9 @@ export class StudyViewPageStore
16971698
: undefined
16981699
)
16991700
.value();
1700-
17011701
statusCallback(LoadingPhase.CREATING_SESSION);
17021702

1703+
// create session and get id
17031704
const { id } = await comparisonClient.addComparisonSession({
17041705
groups,
17051706
clinicalAttributeName: chartMeta.displayName,

src/pages/studyView/StudyViewUtils.spec.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,11 +3671,7 @@ describe('StudyViewUtils', () => {
36713671
counts: [
36723672
{
36733673
value: 'Missense_Mutation',
3674-
sampleIds: [
3675-
'study_ABC_123',
3676-
'study_DEF_456',
3677-
'lgg_ucsf_2014_P21_Pri',
3678-
],
3674+
sampleIds: ['study_ABC_123', 'study_DEF_456'],
36793675
},
36803676
],
36813677
},
@@ -3689,12 +3685,7 @@ describe('StudyViewUtils', () => {
36893685
},
36903686
] as any;
36913687

3692-
const studyId: string[] = [
3693-
'study_ABC',
3694-
'study_DEF',
3695-
'study_GHI',
3696-
'lgg_ucsf_2014',
3697-
];
3688+
const studyId: string[] = ['study_ABC', 'study_DEF', 'study_GHI'];
36983689

36993690
it('groups and creates SampleIdeifier by mutation status correctly', () => {
37003691
const result = groupSamplesByMutationStatus(data, studyId);
@@ -3708,10 +3699,6 @@ describe('StudyViewUtils', () => {
37083699
studyId: 'study_DEF',
37093700
sampleId: '456',
37103701
},
3711-
{
3712-
studyId: 'lgg_ucsf_2014',
3713-
sampleId: 'P21_Pri',
3714-
},
37153702
],
37163703
NOT_MUTATED: [
37173704
{

src/pages/studyView/StudyViewUtils.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4286,20 +4286,21 @@ export function groupSamplesByMutationStatus(data: any[], studyIds: string[]) {
42864286

42874287
return _.chain(data)
42884288
.flatMap(d => d.counts ?? [])
4289-
.filter(c => !SKIP_VALUES.has(c.value) && c.sampleIds?.length > 0)
4289+
.filter(c => !SKIP_VALUES.has(c.value) && c.sampleIds?.length > 0) // avoid NOT_PROFILED samples and any bins without samples
42904290
.flatMap(c => {
42914291
const group = NON_MUTATION_VALUES.has(c.value)
42924292
? c.value
42934293
: 'MUTATED';
42944294

42954295
return c.sampleIds
42964296
.map((rawId: string) => {
4297+
// sampleIds are in the format of {studyId}_{sampleId}, need to be split before grouping
42974298
const matchedStudyId = studyIds.find(studyId =>
42984299
rawId.startsWith(studyId + '_')
42994300
);
43004301

43014302
if (!matchedStudyId) return null;
4302-
4303+
// create an object with group, studyId and sampleId for each sampleId, where group is MUTATED or NOT_MUTATED based on the value of the bin it belongs to
43034304
return {
43044305
group,
43054306
studyId: matchedStudyId,
@@ -4311,8 +4312,14 @@ export function groupSamplesByMutationStatus(data: any[], studyIds: string[]) {
43114312
.groupBy('group')
43124313
.mapValues(items =>
43134314
_.uniqBy(
4314-
items.map(({ studyId, sampleId }) => ({ studyId, sampleId })),
4315-
i => i.sampleId
4315+
// cretaes a sampleidentifier{sampleId, studyId} using the matched studyId and the rest of the rawId as sampleId
4316+
items.map(
4317+
({ studyId, sampleId }): SampleIdentifier => ({
4318+
studyId,
4319+
sampleId,
4320+
})
4321+
),
4322+
i => i.sampleId // if sample IDs aren't globally unique across studies, we may want to use both studyId and sampleId to determine uniqueness
43164323
)
43174324
)
43184325
.value();

0 commit comments

Comments
 (0)