-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from Sage-Bionetworks/bwmac/IBCDPE-688/gx-meta…
…bolomics [IBCDPE-688] Great Expectations Implementation for Metabolomics Data
- Loading branch information
Showing
27 changed files
with
5,039 additions
and
677 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ensure that /great_expectations and all of its contents are included when the package is installed | ||
graft src/agoradatatools/great_expectations/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
{ | ||
"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", | ||
"\n", | ||
"from expectations.expect_column_values_to_have_list_length import ExpectColumnValuesToHaveListLength\n", | ||
"from expectations.expect_column_values_to_have_list_members import ExpectColumnValuesToHaveListMembers\n", | ||
"from expectations.expect_column_values_to_have_list_members_of_type import ExpectColumnValuesToHaveListMembersOfType\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Create Expectation Suite for Metabolomics 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": [ | ||
"metabolomics_data_file = syn.get(\"syn19276330\").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", | ||
" metabolomics_data_file\n", | ||
")\n", | ||
"validator.expectation_suite_name = \"metabolomics\"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Add Expectations to Validator Object For Each Column" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# ad_diagnosis_p_value\n", | ||
"validator.expect_column_values_to_be_of_type(\"ad_diagnosis_p_value\", \"list\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"ad_diagnosis_p_value\")\n", | ||
"# for custom and experimental expectations you have to pass args as kwargs\n", | ||
"validator.expect_column_values_to_have_list_length(column=\"ad_diagnosis_p_value\", list_length=1)\n", | ||
"validator.expect_column_values_to_have_list_members_of_type(column=\"ad_diagnosis_p_value\", member_type=\"float\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# associated gene name\n", | ||
"validator.expect_column_values_to_be_of_type(\"associated_gene_name\", \"str\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"associated_gene_name\")\n", | ||
"validator.expect_column_value_lengths_to_be_between(\"associated_gene_name\", min_value=2, max_value=100)\n", | ||
"# allows all alphanumeric characters, underscores, periods, and dashes\n", | ||
"validator.expect_column_values_to_match_regex(\"associated_gene_name\", \"^[A-Za-z0-9_.-]+$\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# association p\n", | ||
"validator.expect_column_values_to_be_of_type(\"association_p\", \"float\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"association_p\")\n", | ||
"validator.expect_column_values_to_be_between(\"association_p\", strict_min_value=0, max_value=1)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# boxplot_group_names\n", | ||
"validator.expect_column_values_to_be_of_type(\"boxplot_group_names\", \"list\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"boxplot_group_names\")\n", | ||
"validator.expect_column_values_to_have_list_length(column=\"boxplot_group_names\", list_length=2)\n", | ||
"validator.expect_column_values_to_have_list_members(column=\"boxplot_group_names\", list_members={\"AD\", \"CN\"})\n", | ||
"validator.expect_column_values_to_have_list_members_of_type(column=\"boxplot_group_names\", member_type=\"str\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# ensembl gene id\n", | ||
"validator.expect_column_values_to_be_of_type(\"ensembl_gene_id\", \"str\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"ensembl_gene_id\")\n", | ||
"validator.expect_column_value_lengths_to_equal(\"ensembl_gene_id\", 15)\n", | ||
"# checks format and allowed chatacters\n", | ||
"validator.expect_column_values_to_match_regex(\"ensembl_gene_id\", \"^ENSG\\d{11}$\")\n", | ||
"validator.expect_column_values_to_be_unique(\"ensembl_gene_id\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# gene_wide_p_threshold_1kgp\n", | ||
"validator.expect_column_values_to_be_of_type(\"gene_wide_p_threshold_1kgp\", \"float\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"gene_wide_p_threshold_1kgp\")\n", | ||
"validator.expect_column_values_to_be_between(\"gene_wide_p_threshold_1kgp\", strict_min_value=0, max_value=0.05)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# metabolite full name\n", | ||
"validator.expect_column_values_to_be_of_type(\"metabolite_full_name\", \"str\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"metabolite_full_name\")\n", | ||
"validator.expect_column_value_lengths_to_be_between(\"metabolite_full_name\", min_value=2, max_value=100) \n", | ||
"# allows all alphanumeric characters, dashes, parentheses, hyphens and spaces\n", | ||
"validator.expect_column_values_to_match_regex(\"metabolite_full_name\", \"^[A-Za-z0-9\\s\\-:.()+]+$\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# metabolite ID\n", | ||
"validator.expect_column_values_to_be_of_type(\"metabolite_id\", \"str\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"metabolite_id\")\n", | ||
"validator.expect_column_value_lengths_to_be_between(\"metabolite_id\", min_value=2, max_value=100)\n", | ||
"# allows all alphanumeric characters and periods\n", | ||
"validator.expect_column_values_to_match_regex(\"metabolite_id\", \"^[A-Za-z0-9.]+$\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# n_per_group\n", | ||
"validator.expect_column_values_to_be_of_type(\"n_per_group\", \"list\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"n_per_group\")\n", | ||
"validator.expect_column_values_to_have_list_length(column=\"n_per_group\", list_length=2)\n", | ||
"validator.expect_column_values_to_have_list_members_of_type(column=\"n_per_group\", member_type=\"int\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# transposed_boxplot_stats\n", | ||
"validator.expect_column_values_to_be_of_type(\"transposed_boxplot_stats\", \"list\")\n", | ||
"validator.expect_column_values_to_not_be_null(\"transposed_boxplot_stats\")\n", | ||
"validator.expect_column_values_to_have_list_length(column=\"transposed_boxplot_stats\", list_length=2)\n", | ||
"validator.expect_column_values_to_have_list_members_of_type(column=\"transposed_boxplot_stats\", member_type=\"list\")\n" | ||
] | ||
}, | ||
{ | ||
"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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.