-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/mutated genes AlterationFilter and Fix unit test (#10803)
* Create new wide table sql file and rename package * Remove genomic_event view * Add AlterationFilter to mutated_genes endpoint * Add AlterationFilter to mutated-genes endpoint * Fix unit test * Fix sonar issues * Add test for mutation types and status * remove unused imports
- Loading branch information
Showing
17 changed files
with
761 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
src/main/java/org/cbioportal/persistence/helper/AlterationFilterHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package org.cbioportal.persistence.helper; | ||
|
||
import org.cbioportal.model.AlterationFilter; | ||
import org.cbioportal.model.CNA; | ||
import org.cbioportal.model.MutationEventType; | ||
import org.cbioportal.model.util.Select; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.lang.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
public final class AlterationFilterHelper { | ||
|
||
public static AlterationFilterHelper build(@Nullable AlterationFilter alterationFilter) { | ||
if (Objects.isNull(alterationFilter)) { | ||
alterationFilter = new AlterationFilter(); | ||
} | ||
return new AlterationFilterHelper(alterationFilter); | ||
} | ||
|
||
private final AlterationFilter alterationFilter; | ||
private final Select<String> mappedMutationTypes; | ||
|
||
private AlterationFilterHelper(@NonNull AlterationFilter alterationFilter){ | ||
this.alterationFilter = alterationFilter; | ||
this.mappedMutationTypes = buildMutationTypeList(); | ||
} | ||
|
||
private Select<String> buildMutationTypeList() { | ||
if (alterationFilter.getMutationTypeSelect().hasNone()) { | ||
return Select.none(); | ||
} | ||
if (alterationFilter.getMutationTypeSelect().hasAll()) { | ||
return Select.all(); | ||
} | ||
Select<String> typeSelects = alterationFilter.getMutationTypeSelect().map(MutationEventType::getMutationType); | ||
typeSelects.inverse(alterationFilter.getMutationTypeSelect().inverse()); | ||
|
||
return typeSelects; | ||
} | ||
|
||
public Select<String> getMutationTypeList() { | ||
return mappedMutationTypes; | ||
} | ||
|
||
public Select<Short> getCnaTypeList() { | ||
if (alterationFilter.getCNAEventTypeSelect().hasNone()) { | ||
return Select.none(); | ||
} | ||
if (alterationFilter.getCNAEventTypeSelect().hasAll()) { | ||
return Select.all(); | ||
} | ||
return alterationFilter.getCNAEventTypeSelect().map(CNA::getCode); | ||
} | ||
|
||
public boolean hasDriver() { | ||
return alterationFilter.getIncludeDriver(); | ||
} | ||
|
||
public boolean hasVUSDriver() { | ||
return alterationFilter.getIncludeVUS(); | ||
} | ||
|
||
public boolean hasUnknownOncogenicity() { | ||
return alterationFilter.getIncludeUnknownOncogenicity(); | ||
} | ||
|
||
public boolean hasGermline() { | ||
return alterationFilter.getIncludeGermline(); | ||
} | ||
|
||
public boolean hasSomatic() { | ||
return alterationFilter.getIncludeSomatic(); | ||
} | ||
|
||
public boolean hasUnknownMutationStatus() { | ||
return alterationFilter.getIncludeUnknownStatus(); | ||
} | ||
|
||
public Select<String> getSelectedTiers() { | ||
return alterationFilter.getSelectedTiers(); | ||
} | ||
|
||
public boolean hasUnknownTier() { | ||
return alterationFilter.getIncludeUnknownTier(); | ||
} | ||
|
||
public boolean isAllDriverAnnotationSelected() { | ||
return alterationFilter.getIncludeDriver() && alterationFilter.getIncludeVUS() && alterationFilter.getIncludeUnknownOncogenicity(); | ||
} | ||
|
||
public boolean isNoDriverAnnotationSelected() { | ||
return !alterationFilter.getIncludeDriver() && !alterationFilter.getIncludeVUS() && !alterationFilter.getIncludeUnknownOncogenicity(); | ||
} | ||
|
||
public boolean isSomeDriverAnnotationsSelected() { | ||
return !isAllDriverAnnotationSelected() && !isNoDriverAnnotationSelected(); | ||
} | ||
|
||
public boolean isAllMutationStatusSelected() { | ||
return alterationFilter.getIncludeGermline() | ||
&& alterationFilter.getIncludeSomatic() | ||
&& alterationFilter.getIncludeUnknownStatus(); | ||
} | ||
|
||
public boolean isNoMutationStatusSelected() { | ||
return !alterationFilter.getIncludeGermline() | ||
&& !alterationFilter.getIncludeSomatic() | ||
&& !alterationFilter.getIncludeUnknownStatus(); | ||
} | ||
|
||
public boolean isSomeMutationStatusSelected() { | ||
return !isAllMutationStatusSelected() && !isNoMutationStatusSelected(); | ||
} | ||
|
||
public boolean isAllTierOptionsSelected() { | ||
return !Objects.isNull(alterationFilter.getSelectedTiers()) | ||
&& alterationFilter.getSelectedTiers().hasAll() | ||
&& alterationFilter.getIncludeUnknownTier(); | ||
} | ||
|
||
public boolean isNoTierOptionsSelected() { | ||
return (Objects.isNull(alterationFilter.getSelectedTiers()) || alterationFilter.getSelectedTiers().hasNone()) | ||
&& !alterationFilter.getIncludeUnknownTier(); | ||
} | ||
|
||
public boolean isSomeTierOptionsSelected() { | ||
return !isAllTierOptionsSelected() && !isNoTierOptionsSelected(); | ||
} | ||
|
||
public boolean shouldApply() { | ||
return isSomeDriverAnnotationsSelected() | ||
|| isSomeMutationStatusSelected() | ||
|| isSomeTierOptionsSelected() | ||
|| mappedMutationTypes.hasNone() | ||
|| (!mappedMutationTypes.hasNone() && !mappedMutationTypes.hasAll()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
DROP TABLE IF EXISTS genomic_event_mutation; | ||
DROP TABLE IF EXISTS genomic_event; | ||
|
||
CREATE TABLE IF NOT EXISTS genomic_event | ||
( | ||
sample_unique_id String, | ||
variant String, | ||
variant_type String, | ||
hugo_gene_symbol String, | ||
gene_panel_stable_id String, | ||
cancer_study_identifier String, | ||
genetic_profile_stable_id String | ||
) ENGINE = MergeTree | ||
ORDER BY ( variant_type, sample_unique_id, hugo_gene_symbol); | ||
|
||
CREATE TABLE IF NOT EXISTS genomic_event_mutation | ||
( | ||
sample_unique_id String, | ||
variant String, | ||
hugo_gene_symbol String, | ||
gene_panel_stable_id String, | ||
cancer_study_identifier String, | ||
genetic_profile_stable_id String, | ||
mutation_type String, | ||
mutation_status String, | ||
driver_filter String, | ||
driver_tiers_filter String | ||
) ENGINE = MergeTree | ||
ORDER BY ( hugo_gene_symbol, genetic_profile_stable_id); |
91 changes: 91 additions & 0 deletions
91
src/main/resources/db-scripts/clickhouse/clickhouse_migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
-- Genomic Event Mutation Data | ||
Insert into genomic_event_mutation | ||
SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) as sample_unique_id, | ||
me.protein_change as variant, | ||
gene.hugo_gene_symbol as hugo_gene_symbol, | ||
gp.stable_id as gene_panel_stable_id, | ||
cs.cancer_study_identifier as cancer_study_identifier, | ||
g.stable_id as genetic_profile_stable_id, | ||
me.mutation_type as mutation_type, | ||
mutation.mutation_status as mutation_status, | ||
'NA' as driver_filter, | ||
'NA' as drivet_tiers_filter | ||
FROM mutation | ||
INNER JOIN mutation_event as me on mutation.mutation_event_id = me.mutation_event_id | ||
INNER JOIN sample_profile sp | ||
on mutation.sample_id = sp.sample_id and mutation.genetic_profile_id = sp.genetic_profile_id | ||
LEFT JOIN gene_panel gp on sp.panel_id = gp.internal_id | ||
LEFT JOIN genetic_profile g on sp.genetic_profile_id = g.genetic_profile_id | ||
INNER JOIN cancer_study cs on g.cancer_study_id = cs.cancer_study_id | ||
INNER JOIN sample on mutation.sample_id = sample.internal_id | ||
LEFT JOIN gene on mutation.entrez_gene_id = gene.entrez_gene_id; | ||
|
||
-- Genomic Event Data | ||
Insert into genomic_event | ||
SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) as sample_unique_id, | ||
me.protein_change as variant, | ||
'mutation' as variant_type, | ||
gene.hugo_gene_symbol as hugo_gene_symbol, | ||
gp.stable_id as gene_panel_stable_id, | ||
cs.cancer_study_identifier as cancer_study_identifier, | ||
g.stable_id as genetic_profile_stable_id | ||
FROM mutation | ||
INNER JOIN mutation_event as me on mutation.mutation_event_id = me.mutation_event_id | ||
INNER JOIN sample_profile sp | ||
on mutation.sample_id = sp.sample_id and mutation.genetic_profile_id = sp.genetic_profile_id | ||
LEFT JOIN gene_panel gp on sp.panel_id = gp.internal_id | ||
LEFT JOIN genetic_profile g on sp.genetic_profile_id = g.genetic_profile_id | ||
INNER JOIN cancer_study cs on g.cancer_study_id = cs.cancer_study_id | ||
INNER JOIN sample on mutation.sample_id = sample.internal_id | ||
LEFT JOIN gene on mutation.entrez_gene_id = gene.entrez_gene_id | ||
UNION ALL | ||
SELECT concat(cs.cancer_study_identifier, '_', sample.stable_id) as sample_unique_id, | ||
toString(ce.alteration) as variant, | ||
'cna' as variant_type, | ||
gene.hugo_gene_symbol as hugo_gene_symbol, | ||
gp.stable_id as gene_panel_stable_id, | ||
cs.cancer_study_identifier as cancer_study_identifier, | ||
g.stable_id as genetic_profile_stable_id | ||
FROM cna_event ce | ||
INNER JOIN sample_cna_event sce ON ce.cna_event_id = sce.cna_event_id | ||
INNER JOIN sample_profile sp ON sce.sample_id = sp.sample_id AND sce.genetic_profile_id = sp.genetic_profile_id | ||
INNER JOIN gene_panel gp ON sp.panel_id = gp.internal_id | ||
INNER JOIN genetic_profile g ON sp.genetic_profile_id = g.genetic_profile_id | ||
INNER JOIN cancer_study cs ON g.cancer_study_id = cs.cancer_study_id | ||
INNER JOIN sample ON sce.sample_id = sample.internal_id | ||
INNER JOIN gene ON ce.entrez_gene_id = gene.entrez_gene_id | ||
UNION ALL | ||
SELECT | ||
concat(cs.cancer_study_identifier, '_', s.stable_id) as sample_unique_id, | ||
event_info as variant, | ||
'structural_variant' as variant_type, | ||
gene2.hugo_gene_symbol as hugo_gene_symbol, | ||
gene_panel.stable_id as gene_panel_stable_id, | ||
cs.cancer_study_identifier as cancer_study_identifier, | ||
gp.stable_id as genetic_profile_stable_id | ||
FROM | ||
structural_variant sv | ||
INNER JOIN genetic_profile gp ON sv.genetic_profile_id = gp.genetic_profile_id | ||
INNER JOIN sample s ON sv.sample_id = s.internal_id | ||
INNER JOIN cancer_study cs ON gp.cancer_study_id = cs.cancer_study_id | ||
INNER JOIN gene gene2 ON sv.site2_entrez_gene_id = gene2.entrez_gene_id | ||
INNER JOIN sample_profile on s.internal_id = sample_profile.sample_id | ||
INNER JOIN gene_panel on sample_profile.panel_id = gene_panel.internal_id | ||
UNION ALL | ||
SELECT | ||
concat(cs.cancer_study_identifier, '_', s.stable_id) as sample_unique_id, | ||
event_info as variant, | ||
'structural_variant' as variant_type, | ||
gene1.hugo_gene_symbol as hugo_gene_symbol, | ||
gene_panel.stable_id as gene_panel_stable_id, | ||
cs.cancer_study_identifier as cancer_study_identifier, | ||
gp.stable_id as genetic_profile_stable_id | ||
FROM | ||
structural_variant sv | ||
INNER JOIN genetic_profile gp ON sv.genetic_profile_id = gp.genetic_profile_id | ||
INNER JOIN sample s ON sv.sample_id = s.internal_id | ||
INNER JOIN cancer_study cs ON gp.cancer_study_id = cs.cancer_study_id | ||
INNER JOIN gene gene1 ON sv.site1_entrez_gene_id = gene1.entrez_gene_id | ||
INNER JOIN sample_profile on s.internal_id = sample_profile.sample_id | ||
INNER JOIN gene_panel on sample_profile.panel_id = gene_panel.internal_id; |
Oops, something went wrong.