From 5118d6e72fc4ea6d01e0fb0da0f130b0b2eefab5 Mon Sep 17 00:00:00 2001 From: francastell Date: Mon, 5 Feb 2024 12:56:17 -0500 Subject: [PATCH 1/2] Geneset metdata with pub info API --- src/geneweaver/api/controller/genesets.py | 5 +++- src/geneweaver/api/services/geneset.py | 7 +++-- tests/data/__init__.py | 3 ++ tests/data/response_geneset_1234.json | 34 ++++++++++++++++++++++- tests/services/test_genset.py | 12 ++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/geneweaver/api/controller/genesets.py b/src/geneweaver/api/controller/genesets.py index 69ef483..60be6ce 100644 --- a/src/geneweaver/api/controller/genesets.py +++ b/src/geneweaver/api/controller/genesets.py @@ -108,9 +108,12 @@ def get_geneset_metadata( ], user: UserInternal = Security(deps.full_user), cursor: Optional[deps.Cursor] = Depends(deps.cursor), + include_pub_info: Optional[bool] = False, ) -> dict: """Get a geneset metadata by geneset id.""" - response = genset_service.get_geneset_metadata(cursor, geneset_id, user) + response = genset_service.get_geneset_metadata( + cursor, geneset_id, user, include_pub_info + ) if "error" in response: if response.get("message") == api_message.ACCESS_FORBIDDEN: diff --git a/src/geneweaver/api/services/geneset.py b/src/geneweaver/api/services/geneset.py index f1bfbf4..de5ed6e 100644 --- a/src/geneweaver/api/services/geneset.py +++ b/src/geneweaver/api/services/geneset.py @@ -12,19 +12,22 @@ from psycopg import Cursor -def get_geneset_metadata(cursor: Cursor, geneset_id: int, user: User) -> dict: +def get_geneset_metadata( + cursor: Cursor, geneset_id: int, user: User, include_pub_info: bool = False +) -> dict: """Get a geneset metadata by geneset id. @param cursor: DB cursor @param geneset_id: geneset identifier @param user: GW user + @param include_pub_info: bool (Optional with publication information) @return: dictionary response (geneset). """ try: if not is_geneset_readable_by_user(cursor, geneset_id, user): return {"error": True, "message": message.ACCESS_FORBIDDEN} - geneset = db_geneset.by_id(cursor, geneset_id) + geneset = db_geneset.by_id(cursor, geneset_id, include_pub_info) return {"geneset": geneset} except Exception as err: diff --git a/tests/data/__init__.py b/tests/data/__init__.py index f8bfeb6..2165c71 100644 --- a/tests/data/__init__.py +++ b/tests/data/__init__.py @@ -24,6 +24,9 @@ test_geneset_data = { "geneset_by_id_resp": json.loads(geneset_response_json), "geneset_w_gene_id_type_resp": json.loads(geneset_w_gene_id_type_json), + "geneset_metadata_w_pub_info": json.loads(geneset_response_json).get( + "geneset_with_publication_info" + ), } # Gene test data diff --git a/tests/data/response_geneset_1234.json b/tests/data/response_geneset_1234.json index 82063fb..7a30026 100644 --- a/tests/data/response_geneset_1234.json +++ b/tests/data/response_geneset_1234.json @@ -74,5 +74,37 @@ "gsv_date": "2020-05-05", "ode_ref_id": "Hs.541341" } - ] + ], + "geneset_with_publication_info": { + "geneset": { + "id": 1234, + "user_id": 51, + "file_id": 1715, + "curation_id": 3, + "species_id": 2, + "name": "Differential expression in heroin and cocaine abusers-Down-regulated Cocaine, Up-regulated Heroin", + "abbreviation": "UpRegHeroinDwnRegCocaine", + "pub_id": 6, + "description": "From the initial set of differentially expressed genes in post mortum nucleus accumbens of chronic heroin and cocaine abusers, this set contains genes upregulated in cocaine abusers but downregulated in heroin abusers.", + "count": 3, + "threshold_type": 3, + "threshold": "0.5", + "groups": "0", + "status": "normal", + "gene_id_type": -7, + "attribution": null, + "created": "2008-04-22", + "updated": "2020-05-06T09:19:44.883323", + "publication_id": 6, + "publication_authors": "Albertson DN, Schmidt CJ, Kapatos G, Bannon MJ", + "publication_title": "Distinctive profiles of gene expression in the human nucleus accumbens associated with cocaine and heroin abuse.", + "publication_abstract": "Drug abuse is thought to induce long-term cellular and behavioral adaptations as a result of alterations in gene expression. Understanding the molecular consequences of addiction may contribute to the development of better treatment strategies. This study utilized high-throughput Affymetrix microarrays to identify gene expression changes in the post-mortem nucleus accumbens of chronic heroin abusers. These data were analyzed independently and in relation to our previously reported data involving human cocaine abusers, in order to determine which expression changes were drug specific and which may be common to the phenomenon of addiction. A significant decrease in the expression of numerous genes encoding proteins involved in presynaptic release of neurotransmitter was seen in heroin abusers, a finding not seen in the cocaine-abusing cohort. Conversely, the striking decrease in myelin-related genes observed in cocaine abusers was not evident in our cohort of heroin subjects. Overall, little overlap in gene expression profiles was seen between the two drug-abusing cohorts: out of the approximately 39,000 transcripts investigated, the abundance of only 25 was significantly changed in both cocaine and heroin abusers, with nearly one-half of these being altered in opposite directions. These data suggest that the profiles of nucleus accumbens gene expression associated with chronic heroin or cocaine abuse are largely unique, despite what are thought to be common effects of these drugs on dopamine neurotransmission in this brain region. A re-examination of our current assumptions about the commonality of molecular mechanisms associated with substance abuse seems warranted.", + "publication_journal": "Neuropsychopharmacology : official publication of the American College of Neuropsychopharmacology", + "publication_volume": "31", + "publication_pages": "2304-12", + "publication_month": "Oct", + "publication_year": "2006", + "publication_pubmed_id": "16710320" + } + } } diff --git a/tests/services/test_genset.py b/tests/services/test_genset.py index ee67369..d22bd9a 100644 --- a/tests/services/test_genset.py +++ b/tests/services/test_genset.py @@ -11,6 +11,7 @@ geneset_by_id_resp = test_geneset_data.get("geneset_by_id_resp") geneset_w_gene_id_type_resp = test_geneset_data.get("geneset_w_gene_id_type_resp") +geneset_metadata_w_pub_info = test_geneset_data.get("geneset_metadata_w_pub_info") @patch("geneweaver.api.services.geneset.db_geneset") @@ -107,3 +108,14 @@ def test_get_geneset_metadata(mock_genset_readable_func, mock_db_geneset): response = geneset.get_geneset_metadata(None, 1234, None) assert response.get("geneset") == geneset_by_id_resp["geneset"] + + +@patch("geneweaver.api.services.geneset.db_geneset") +@patch("geneweaver.api.services.geneset.is_geneset_readable_by_user") +def test_get_geneset_metadata_w_pub_info(mock_genset_readable_func, mock_db_geneset): + """Test get geneset metadata by geneset id with publication info.""" + mock_genset_readable_func.return_value = True + mock_db_geneset.by_id.return_value = geneset_metadata_w_pub_info + response = geneset.get_geneset_metadata(None, 1234, None, True) + + assert response.get("geneset") == geneset_metadata_w_pub_info From e683cc96e2542318b0e0a430558fb9cb8634fdeb Mon Sep 17 00:00:00 2001 From: francastell Date: Tue, 6 Feb 2024 10:13:47 -0500 Subject: [PATCH 2/2] version update --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2919eca..4a90902 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "geneweaver-api" -version = "0.2.0a0" +version = "0.2.0a3" description = "description" authors = ["Jax Computational Sciences "] packages = [