Skip to content

Commit

Permalink
Merge pull request #1777 from alliance-genome/SCRUM-4654
Browse files Browse the repository at this point in the history
Add synonyms to variant
  • Loading branch information
VarunReddy1111 authored Jan 3, 2025
2 parents 889b888 + 4712cc5 commit 55f4c59
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/cliapp/src/containers/variantsPage/VariantsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { OntologyTermTemplate } from '../../components/Templates/OntologyTermTem
import { CountDialogTemplate } from '../../components/Templates/dialog/CountDialogTemplate';
import { BooleanTemplate } from '../../components/Templates/BooleanTemplate';
import { IdTemplate } from '../../components/Templates/IdTemplate';
import { StringListTemplate } from '../../components/Templates/StringListTemplate';

import { useGetTableData } from '../../service/useGetTableData';
import { useGetUserSettings } from '../../service/useGetUserSettings';
Expand Down Expand Up @@ -226,6 +227,13 @@ export const VariantsTable = () => {
filterConfig: FILTER_CONFIGS.sourceGeneralConsequenceFilterConfig,
editor: (props) => <SourceGeneralConsequenceTableEditor rowProps={props} errorMessagesRef={errorMessagesRef} />,
},
{
field: 'synonyms',
header: 'Synonyms',
sortable: true,
filterConfig: FILTER_CONFIGS.synonymsFilterConfig,
body: (rowData) => <StringListTemplate list={rowData.synonyms} />,
},
{
field: 'dataProvider.sourceOrganization.abbreviation',
header: 'Data Provider',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
import org.alliancegenome.curation_api.view.View;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.search.engine.backend.types.Aggregable;
import org.hibernate.search.engine.backend.types.Searchable;
import org.hibernate.search.engine.backend.types.Sortable;
import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FullTextField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.KeywordField;

import com.fasterxml.jackson.annotation.JsonView;

import jakarta.persistence.CascadeType;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.JoinTable;
Expand All @@ -33,7 +39,7 @@
@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
@ToString(exclude = { "curatedVariantGenomicLocations", "alleleVariantAssociations" }, callSuper = true)
@AGRCurationSchemaVersion(min = "1.10.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = { GenomicEntity.class })
@AGRCurationSchemaVersion(min = "2.9.1", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = { GenomicEntity.class })
@Table(indexes = {
@Index(name = "variant_varianttype_index", columnList = "varianttype_id"),
@Index(name = "variant_variantstatus_index", columnList = "variantstatus_id"),
Expand Down Expand Up @@ -89,4 +95,11 @@ public class Variant extends GenomicEntity {
@JsonView({ View.FieldsAndLists.class, View.VariantDetailView.class })
private List<AlleleVariantAssociation> alleleVariantAssociations;

@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
@FullTextField(analyzer = "autocompleteAnalyzer", searchAnalyzer = "autocompleteSearchAnalyzer")
@KeywordField(name = "synonyms_keyword", aggregable = Aggregable.YES, sortable = Sortable.YES, searchable = Searchable.YES, normalizer = "sortNormalizer")
@ElementCollection
@JoinTable(indexes = @Index(name = "variant_synonyms_variant_index", columnList = "variant_id"))
@JsonView({ View.FieldsAndLists.class, View.VariantView.class })
private List<String> synonyms;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class VariantFmsDTO extends BaseDTO {
private List<VariantNoteFmsDTO> notes;
private List<PublicationRefFmsDTO> references;
private List<CrossReferenceFmsDTO> crossReferences;
private List<String> synonyms;
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ public Long validateVariant(VariantFmsDTO dto, List<Long> idsAdded, BackendBulkD
}
}
variant.setSourceGeneralConsequence(consequence);

if (CollectionUtils.isNotEmpty(dto.getSynonyms())) {
List<String> existingSynonyms = variant.getSynonyms();
if (CollectionUtils.isEmpty(existingSynonyms)) {
existingSynonyms = new ArrayList<>();
}
// remove synonyms that are no longer in the submitted file
List<String> toBeRemoved = existingSynonyms.stream()
.filter(synonym -> !dto.getSynonyms().contains(synonym))
.toList();
existingSynonyms.removeIf(toBeRemoved::contains);
// add missing synonyms
final List<String> synonymStrings = existingSynonyms;
List<String> toBeAdded = dto.getSynonyms().stream()
.filter(synonym -> !synonymStrings.contains(synonym))
.toList();
existingSynonyms.addAll(toBeAdded);
variant.setSynonyms(existingSynonyms);
} else {
variant.setSynonyms(null);
}

List<CrossReference> validatedXrefs = new ArrayList<>();
if (CollectionUtils.isNotEmpty(dto.getCrossReferences())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE variant_synonyms (
variant_id bigint,
synonyms text
);

CREATE INDEX variant_synonyms_variant_index ON variant_synonyms USING btree (variant_id);

ALTER TABLE variant_synonyms ADD CONSTRAINT variant_synonyms_variant_id_fk FOREIGN KEY (variant_id) REFERENCES variant (id);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.hamcrest.Matchers.is;

import java.util.HashMap;
import java.util.List;

import org.alliancegenome.curation_api.base.BaseITCase;
import org.alliancegenome.curation_api.constants.VocabularyConstants;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void variantFmsBulkUpload() throws Exception {
body("entity.taxon.curie", is("NCBITaxon:6239")).
body("entity.dataProvider.sourceOrganization.abbreviation", is("WB")).
body("entity.variantType.curie", is("SO:1000002")).
body("entity.synonyms", is(List.of("Syn 1", "Syn 2"))).
body("entity.sourceGeneralConsequence.curie", is("SO:0001587")).
body("entity.curatedVariantGenomicLocations", hasSize(1)).
body("entity.curatedVariantGenomicLocations[0].hgvs", is("NC_003279.8:g.1A>T")).
Expand Down Expand Up @@ -132,6 +134,7 @@ public void variantFmsBulkUploadUpdate() throws Exception {
body("entity.taxon.curie", is("NCBITaxon:6239")).
body("entity.dataProvider.sourceOrganization.abbreviation", is("WB")).
body("entity.variantType.curie", is("SO:1000008")).
body("entity.synonyms", is(List.of("Syn 3", "Syn 4"))).
body("entity.sourceGeneralConsequence.curie", is("SO:0001578")).
body("entity.curatedVariantGenomicLocations", hasSize(1)).
body("entity.curatedVariantGenomicLocations[0].hgvs", is("NC_003279.8:g.1A>T")).
Expand Down Expand Up @@ -195,7 +198,7 @@ public void variantFmsBulkUploadEmptyRequiredFields() throws Exception {
}

@Test
@Order(3)
@Order(5)
public void variantFmsBulkUploadInvalidFields() throws Exception {
HashMap<String, HashMap<String, Integer>> params = new HashMap<>();
params.put("Entities", createCountParams(1, 1, 0, 0));
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/bulk/fms/10_variant/AF_01_all_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"homepage"
]
}
],
"synonyms" : [
"Syn 1","Syn 2"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
]
}
],
"synonyms" : [
"Syn 3","Syn 4"
],
"crossReferences": [
{
"id": "TEST:WBVar00252637",
Expand Down

0 comments on commit 55f4c59

Please sign in to comment.