-
Notifications
You must be signed in to change notification settings - Fork 26
[SCHEMATIC-360] Add script to write jsonschemas to a synapse table #1642
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
Draft
thomasyu888
wants to merge
5
commits into
develop
Choose a base branch
from
schematic-360-write-to-table
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b60b398
Add script to write jsonschemas to a synapse table
thomasyu888 105646f
Add in if else to skip some data models
thomasyu888 d0195c0
Go around jsonschema service bug
thomasyu888 8e6f934
Add MC2 schemas
thomasyu888 0b6cc54
Add NF
thomasyu888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,71 @@ | ||
| import synapseclient | ||
| from synapseclient.models import Table | ||
|
|
||
| import pandas as pd | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| The main entry point for this script. | ||
|
|
||
| This script logs in to Synapse, finds all the JSONschema organizations | ||
| and versions in the given list, and writes them to the Synapse table | ||
| with Synapse ID syn69735275. | ||
|
|
||
| The table will have the following columns: | ||
| - org: the name of the JSONschema organization | ||
| - name: the full name of the JSONschema version | ||
| - dcc: the name of the DCC | ||
| - datatype: the name of the datatype | ||
| - uri: the URI of the JSONschema version | ||
| - version: the semantic version of the JSONschema version | ||
| - link: a link to the JSONschema version in the Synapse repo | ||
| """ | ||
| syn = synapseclient.login() | ||
| # json_schema_organizations = ["sage.schemas.v2571", "sage.schemas.v2581"] | ||
| json_schema_organizations = ["sage.schemas.v2571", "sage.schemas.v2581"] | ||
| js = syn.service("json_schema") | ||
| to_write_schemas = [] | ||
| for organization_name in json_schema_organizations: | ||
| org = js.JsonSchemaOrganization(organization_name) | ||
| schemas = org.list_json_schemas() | ||
| for schema in schemas: | ||
| print(schema) | ||
| versions = schema.list_versions() | ||
| try: | ||
| for version in versions: | ||
| if ( | ||
| ( | ||
| version.name.startswith("ad") | ||
| and version.semantic_version == "0.1.0" | ||
| ) | ||
| or ( | ||
| version.name.startswith("el") | ||
| and version.semantic_version == "0.0.1" | ||
| ) | ||
| or ".validation." in version.name | ||
| ): | ||
| continue | ||
| to_write_schemas.append( | ||
| { | ||
| "org": organization_name, | ||
| "name": version.name, | ||
| "dcc": version.name.split(".")[0], | ||
| "datatype": version.name.split(".")[1], | ||
| "uri": version.uri, | ||
| "version": version.semantic_version, | ||
| "link": f"https://repo-prod.prod.sagebase.org/repo/v1/schema/type/registered/{version.uri}", | ||
| } | ||
| ) | ||
| except Exception as e: | ||
| print(e) | ||
|
|
||
| df = pd.DataFrame(to_write_schemas) | ||
| # exclude HTAN1, HTAN2, and NF schemas as they have their own JSONschema organizations | ||
| df = df[~df["dcc"].isin(["htan", "htan2", "nf"])] | ||
| table = Table(id="syn69735275").get(include_columns=True) | ||
| table.upsert_rows(values=df, primary_keys=["uri"]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great to see this upsert functionality getting some use! |
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have the orgs as a parameter to the main function so that if/when we add new orgs we wouldn't have to update this?