Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting fields for automated QC labelling #134

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/interface/BindingAPI.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: yeastdnnexplorer.interface.BindingAPI.BindingAPI
::: yeastdnnexplorer.interface.BindingAPI.BindingAPI
1 change: 1 addition & 0 deletions docs/interface/BindingConcatenatedAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: yeastdnnexplorer.interface.BindingConcatenatedAPI.BindingConcatenatedAPI
1 change: 1 addition & 0 deletions docs/interface/DtoAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: yeastdnnexplorer.interface.DtoAPI.DtoAPI
78 changes: 76 additions & 2 deletions docs/tutorials/database_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from yeastdnnexplorer.interface import *\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt\n",
"import json\n",
"import pandas as pd"
]
},
{
Expand Down Expand Up @@ -2227,6 +2229,78 @@
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## DTO API\n",
"\n",
"There is now an endpoint to submit jobs to run\n",
"[dual_threshold_optimization](https://github.com/BrentLab/Dual_Threshold_Optimization/tree/dev).\n",
"Submitting a job, and retrieving the result, can be achieved with `submit` and `retrieve`,\n",
"similar to rankresponse. `read()` will retrieve the records in the `metadata`. The DTO\n",
"results are in the `results` field, stored as a json.\n",
"\n",
"```python\n",
"dto_api = DtoAPI()\n",
"\n",
"# submit a DTO job like this. Note -- this can take ~30 minutes to run. It will fail\n",
"# if that promotersetsig_id and expression_id already exist in the DTO table\n",
"args = [\n",
" {\n",
" \"promotersetsig_id\": \"40\",\n",
" \"expression_id\": \"77\",\n",
" \"pss_rename_metric_columns\": False,\n",
" \"pss_col1_ascending\": True,\n",
" \"pss_col2_ascending\": False,\n",
" \"pss_ranker_col1\": \"poisson_pval\",\n",
" \"pss_ranker_col2\": \"callingcards_enrichment\",\n",
" \"expression_col1_ascending\": False,\n",
" \"expression_ranker_col1\": \"effect\",\n",
" \"expression_ranker_col2\": None,\n",
" \"expression_ranker_col1_abs\": True,\n",
" \"n_permutations\": 1000,\n",
" \"n_threads\": 28,\n",
" }\n",
"]\n",
"\n",
"group_id = await dto_api.submit(post_dict=args)\n",
"\n",
"res = await dto_api.retrieve(group_id)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# retrieve a DTO result with `read` to get records from the database\n",
"dto_api = DtoAPI()\n",
"dto_records = await dto_api.read()\n",
"\n",
"print(f'dto metadata results: {dto_records.get(\"metadata\")}')\n",
"\n",
"dto_results_list = []\n",
"\n",
"for i, row in dto_records.get(\"metadata\").iterrows():\n",
" dto_results = json.loads(row.result.replace(\"'\", '\"'))\n",
"\n",
" dto_results['id'] = row.id\n",
" dto_results['promotersetsig_id'] = row.promotersetsig\n",
" dto_results['expression_id'] = row.expression\n",
" dto_results['regulator'] = row.regulator_symbol\n",
" dto_results['binding_source'] = row.binding_source\n",
" dto_results['expression_effect'] = row.expression_source\n",
"\n",
" dto_results_list.append(dto_results)\n",
"\n",
"dto_results_df = pd.DataFrame(dto_results_list)\n",
"\n",
"print(f'dto results: {dto_results_df}')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
13 changes: 8 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ nav:
- Visualizing and Testing Data Generation Methods: tutorials/visualizing_and_testing_data_generation_methods.ipynb
- Generalized Logistic Models: tutorials/generalized_logistic_models.ipynb
- LassoCV: tutorials/lassoCV.ipynb
- Interactor Modeling Workflow: tutorials/interactor_modeling_workflow.ipynb
- API:
- Data Loaders:
- Synthetic Data Loader: data_loaders/synthetic_data_loader.md
Expand All @@ -75,16 +76,18 @@ nav:
- Records Only Classes:
- interface/BindingManualQCAPI.md
- interface/DataSourceAPI.md
- interface/DtoAPI.md
- interface/ExpressionManualQCAPI.md
- interface/FileFormatAPI.md
- interface/GenomicFeatureAPI.md
- interface/RegulatorAPI.md
- Records and Files Classes:
- interface/BindingAPI.md
- interface/CallingCardsBackgroundAPI.md
- interface/ExpressionAPI.md
- interface/PromoterSetAPI.md
- interface/PromoterSetSigAPI.md
- BindingAPI: interface/BindingAPI.md
- BindingConcatenatedAPI: interface/BindingConcatenatedAPI.md
- CallingCardsBackgroundAPI: interface/CallingCardsBackgroundAPI.md
- ExpressionAPI: interface/ExpressionAPI.md
- PromoterSetAPI: interface/PromoterSetAPI.md
- PromoterSetSigAPI: interface/PromoterSetSigAPI.md
- Developer Classes:
- interface/AbstractAPI.md
- interface/AbstractRecordsAndFilesAPI.md
Expand Down
6 changes: 5 additions & 1 deletion yeastdnnexplorer/interface/AbstractRecordsAndFilesAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ async def read(
:param retrieve_files: Boolean. Whether to retrieve the files associated with
the records. Defaults to False.
:type retrieve_files: bool
:param kwargs: The following kwargs are used by the read() function. Any
others are passed onto the callback function
- timeout: The timeout for the GET request. Defaults to 120.

:return: The result of the callback function.
:rtype: Any
Expand All @@ -157,7 +160,8 @@ async def read(
export_url = f"{self.url.rstrip('/')}/{self.export_url_suffix}"
self.logger.debug("read() export_url: %s", export_url)

async with aiohttp.ClientSession() as session:
timeout = aiohttp.ClientTimeout(kwargs.pop("timeout", 120))
async with aiohttp.ClientSession(timeout=timeout) as session:
try:
async with session.get(
export_url, headers=self.header, params=self.params
Expand Down
7 changes: 4 additions & 3 deletions yeastdnnexplorer/interface/AbstractRecordsOnlyAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ async def read(
include `metadata`, `data`, and `cache` as parameters.
:param export_url_suffix: The URL suffix for the export endpoint. This will
return a response object with a csv file.
:param kwargs: Additional arguments to pass to the callback function.
:return: The result of the callback function.
:param kwargs: This can be used to pass "params" to the request to use in place
of `self.params`. If those are passed, they will be popped off and then
the remaining kwargs will be passed to the callback function

"""
if not callable(callback) or {"metadata", "data", "cache"} - set(
Expand All @@ -66,7 +67,7 @@ async def read(
async with session.get(
export_url,
headers=self.header,
params=self.params,
params=kwargs.pop("params", self.params),
) as response:
response.raise_for_status()
content = await response.content.read()
Expand Down
62 changes: 62 additions & 0 deletions yeastdnnexplorer/interface/BindingConcatenatedAPI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
from typing import Any

import pandas as pd

from yeastdnnexplorer.interface.AbstractRecordsAndFilesAPI import (
AbstractRecordsAndFilesAPI,
)


class BindingConcatenatedAPI(AbstractRecordsAndFilesAPI):
"""Class to interact with the BindingConcatenatedAPI endpoint."""

def __init__(self, **kwargs) -> None:
"""
Initialize the BindingConcatenatedAPI object.

:param kwargs: parameters to pass through AbstractRecordsAndFilesAPI to
AbstractAPI.

"""
valid_param_keys = kwargs.pop(
"valid_param_keys",
[
"id",
"regulator",
"regulator_locus_tag",
"regulator_symbol",
"batch",
"replicate",
"source",
"strain",
"condition",
"lab",
"assay",
"workflow",
"data_usable",
],
)

url = kwargs.pop("url", os.getenv("BINDINGCONCATENATED_URL", None))

super().__init__(url=url, valid_keys=valid_param_keys, **kwargs)

def create(self, data: dict[str, Any], **kwargs) -> Any:
raise NotImplementedError("The BindingConcatenatedAPI does not support create.")

def update(self, df: pd.DataFrame, **kwargs) -> Any:
raise NotImplementedError("The BindingConcatenatedAPI does not support update.")

def delete(self, id: str, **kwargs) -> Any:
raise NotImplementedError("The BindingConcatenatedAPI does not support delete.")

def submit(self, post_dict: dict[str, Any], **kwargs) -> Any:
raise NotImplementedError("The BindingConcatenatedAPI does not support submit.")

def retrieve(
self, group_task_id: str, timeout: int, polling_interval: int, **kwargs
) -> Any:
raise NotImplementedError(
"The BindingConcatenatedAPI does not support retrieve."
)
Loading
Loading