Skip to content

Commit

Permalink
[IBCDPE-795] Adds rna_distribution_data GX Suite (#144)
Browse files Browse the repository at this point in the history
* adds rna_dd gx suite

* pre-commit
  • Loading branch information
BWMac authored Jul 19, 2024
1 parent b5b2c65 commit 5d85d94
Show file tree
Hide file tree
Showing 4 changed files with 423 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ datasets:
custom_transformations: 1
provenance: *rna_diff_expr_data_provenance
destination: *dest
gx_enabled: true

- proteomics_distribution_data:
files:
Expand Down
243 changes: 243 additions & 0 deletions gx_suite_definitions/rna_distributinon_data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import synapseclient\n",
"\n",
"import great_expectations as gx\n",
"\n",
"context = gx.get_context(project_root_dir='../src/agoradatatools/great_expectations')\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create Expectation Suite for RNA Distribution Data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get Example Data File"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"syn = synapseclient.Synapse()\n",
"syn.login()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rna_distribution_data_file = syn.get(\"syn28094691\").path\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create Validator Object on Data File"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"validator = context.sources.pandas_default.read_json(\n",
" rna_distribution_data_file\n",
")\n",
"validator.expectation_suite_name = \"rna_distribution_data\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add Expectations to Validator Object For Each Column"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# model\n",
"validator.expect_column_values_to_be_of_type(\"model\", \"str\")\n",
"validator.expect_column_values_to_not_be_null(\"model\")\n",
"validator.expect_column_values_to_be_in_set(\"model\", [\"AD Diagnosis (males and females)\", \"AD Diagnosis x AOD (males and females)\",\"AD Diagnosis x Sex (females only)\", \"AD Diagnosis x Sex (males only)\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# tissue\n",
"validator.expect_column_values_to_be_of_type(\"tissue\", \"str\")\n",
"validator.expect_column_values_to_not_be_null(\"tissue\")\n",
"validator.expect_column_values_to_be_in_set(\"tissue\", [\"CBE\", \"DLPFC\", \"FP\", \"IFG\", \"PHG\", \"STG\", \"TCX\", \"ACC\", \"PCC\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# min\n",
"validator.expect_column_values_to_be_of_type(\"min\", \"float\")\n",
"validator.expect_column_values_to_not_be_null(\"min\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# max\n",
"validator.expect_column_values_to_be_of_type(\"max\", \"float\")\n",
"validator.expect_column_values_to_not_be_null(\"max\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# median\n",
"validator.expect_column_values_to_be_of_type(\"median\", \"float\")\n",
"validator.expect_column_values_to_not_be_null(\"median\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# first_quartile\n",
"validator.expect_column_values_to_be_of_type(\"first_quartile\", \"float\")\n",
"validator.expect_column_values_to_not_be_null(\"first_quartile\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# third_quartile\n",
"validator.expect_column_values_to_be_of_type(\"third_quartile\", \"float\")\n",
"validator.expect_column_values_to_not_be_null(\"third_quartile\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# multi-field\n",
"validator.expect_column_pair_values_a_to_be_greater_than_b(\"max\", \"third_quartile\")\n",
"validator.expect_column_pair_values_a_to_be_greater_than_b(\"third_quartile\", \"median\")\n",
"validator.expect_column_pair_values_a_to_be_greater_than_b(\"median\", \"first_quartile\")\n",
"validator.expect_column_pair_values_a_to_be_greater_than_b(\"first_quartile\", \"min\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save Expectation Suite"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"validator.save_expectation_suite(discard_failed_expectations=False)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create Checkpoint and View Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"checkpoint = context.add_or_update_checkpoint(\n",
" name=\"agora-test-checkpoint\",\n",
" validator=validator,\n",
")\n",
"checkpoint_result = checkpoint.run()\n",
"context.view_validation_result(checkpoint_result)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Build Data Docs - Click on Expectation Suite to View All Expectations"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"context.build_data_docs()\n",
"context.open_data_docs()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 5d85d94

Please sign in to comment.