diff --git a/data/files.sql b/data/files.sql index a77853b3..0506d6fd 100644 --- a/data/files.sql +++ b/data/files.sql @@ -149,6 +149,7 @@ INSERT INTO alias VALUES('y','Y'); INSERT INTO alias VALUES('mt','MT'); CREATE TABLE variantfile ( id VARCHAR NOT NULL, + genomic_id VARCHAR, drs_object_id VARCHAR, indexed INTEGER, chr_prefix VARCHAR, diff --git a/htsget_server/database.py b/htsget_server/database.py index aebf2337..7fae95a9 100644 --- a/htsget_server/database.py +++ b/htsget_server/database.py @@ -91,6 +91,7 @@ class Contig(ObjectDBBase): class VariantFile(ObjectDBBase): __tablename__ = 'variantfile' id = Column(String, primary_key=True) + genomic_id = Column(String) indexed = Column(Integer) chr_prefix = Column(String) reference_genome = Column(String) @@ -130,6 +131,7 @@ def __repr__(self): result = { 'id': self.id, 'drsobject': self.drs_object_id, + 'genomic_id': self.genomic_id, 'indexed': self.indexed, 'chr_prefix': self.chr_prefix, 'reference_genome': self.reference_genome, @@ -497,7 +499,7 @@ def get_variantfile(variantfile_id): def create_variantfile(obj): - # obj = {"id", "reference_genome"} + # obj = {"id", "reference_genome", "genomic_id"} with Session() as session: new_variantfile = session.query(VariantFile).filter_by(id=obj['id']).one_or_none() if new_variantfile is None: @@ -505,6 +507,10 @@ def create_variantfile(obj): new_variantfile.indexed = 0 new_variantfile.chr_prefix = '0' new_variantfile.id = obj['id'] + if "genomic_id" in obj: + new_variantfile.genomic_id = obj['genomic_id'] + else: + new_variantfile.genomic_id = obj['id'] new_variantfile.reference_genome = obj['reference_genome'] new_drs = session.query(DrsObject).filter_by(id=obj['id']).one_or_none() if new_drs is not None: diff --git a/htsget_server/openapi.yml b/htsget_server/openapi.yml index db2490e7..6ce5c0b9 100644 --- a/htsget_server/openapi.yml +++ b/htsget_server/openapi.yml @@ -191,6 +191,7 @@ paths: - $ref: '#/components/parameters/idPathParam' - $ref: '#/components/parameters/forceParam' - $ref: '#/components/parameters/refGenomeParam' + - $ref: '#/components/parameters/genomicIdParam' responses: 200: description: Successfully indexed variant file @@ -666,6 +667,13 @@ components: required: false schema: $ref: '#/components/schemas/ReferenceGenome' + genomicIdParam: + in: query + name: genomic_id + description: If specified, sets this variant entity's associated genomic_id. Otherwise default is the same as the id. + required: false + schema: + type: string readsFormatParam: in: query name: format diff --git a/htsget_server/operations.py b/htsget_server/operations.py index 087db328..50855d2f 100644 --- a/htsget_server/operations.py +++ b/htsget_server/operations.py @@ -111,11 +111,14 @@ def get_variants_data(id_, reference_name=None, format_="VCF", start=None, end=N @app.route('/variants//index') -def index_variants(id_=None, force=False, genome='hg38'): +def index_variants(id_=None, force=False, genome='hg38', genomic_id=None): if not authz.is_site_admin(request): return {"message": "User is not authorized to index variants"}, 403 if id_ is not None: - varfile = database.create_variantfile({"id": id_, "reference_genome": genome}) + params = {"id": id_, "reference_genome": genome} + if genomic_id is not None: + params["genomic_id"] = genomic_id + varfile = database.create_variantfile(params) if varfile is not None: if varfile['indexed'] == 1 and not force: return varfile, 200 @@ -193,6 +196,7 @@ def search_variants(): htsget_obj['urls'].append(_get_base_url("variant", drs_obj_id, data=False)) htsget_obj['id'] = drs_obj_id htsget_obj['variantcount'] = count + htsget_obj['genomic_id'] = database.get_variantfile(drs_obj_id)['genomic_id'] htsget_obj['samples'] = database.get_samples_in_drs_objects({'drs_object_ids': [drs_obj_id]}) htsget_obj['reference_genome'] = searchresult['reference_genome'][i] result['results'].append(htsget_obj) diff --git a/tests/test_htsget_server.py b/tests/test_htsget_server.py index 9a6011dc..dd09db54 100644 --- a/tests/test_htsget_server.py +++ b/tests/test_htsget_server.py @@ -78,17 +78,21 @@ def test_post_update(): def test_index_variants(): - return [('sample.compressed'), ('NA18537'), ('NA20787'), ('multisample_1'), ('multisample_2')] + return [('sample.compressed', None), ('NA18537', None), ('NA20787', None), ('multisample_1', 'HG00096'), ('multisample_2', 'HG00097')] -@pytest.mark.parametrize('sample', test_index_variants()) -def test_index_variantfile(sample): +@pytest.mark.parametrize('sample, genomic_id', test_index_variants()) +def test_index_variantfile(sample, genomic_id): url = f"{HOST}/htsget/v1/variants/{sample}/index" params = {"genome": "hg37"} + if genomic_id is not None: + params["genomic_id"] = genomic_id #params['force'] = True response = requests.get(url, params=params, headers=headers) print(response.text) assert response.json()["id"] == sample + if genomic_id is not None: + assert response.json()["genomic_id"] == genomic_id def invalid_start_end_data():