-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #85 - data release helper code
- Loading branch information
Showing
3 changed files
with
68 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
__version__ = "0.2.21" | ||
__version__ = "0.2.26" | ||
|
||
|
||
def get_data_schema_int(version: str) -> int: | ||
|
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,56 @@ | ||
import re | ||
import requests | ||
import cdot | ||
|
||
from cdot import get_data_schema_int | ||
|
||
|
||
def get_latest_data_release_tag_name(): | ||
latest_data_release = get_latest_data_release() | ||
return latest_data_release.get('tag_name') | ||
|
||
def _get_version_from_tag_name(tag_name, data_version=False): | ||
""" Returns None if doesn't match required prefix """ | ||
release_prefix = "v" | ||
if data_version: | ||
release_prefix = "data_" + release_prefix | ||
|
||
if not tag_name.startswith(release_prefix): | ||
return None | ||
return tag_name.lstrip(release_prefix) | ||
|
||
|
||
def get_latest_data_release(): | ||
client_data_schema = get_data_schema_int(cdot.__version__) | ||
|
||
url = "https://api.github.com/repos/SACGF/cdot/releases" | ||
response = requests.get(url) | ||
json_data = response.json() | ||
for release in json_data: | ||
tag_name = release['tag_name'] # Should look like 'v0.2.25' for code or 'data_v0.2.25' for data | ||
# We require a data version | ||
data_version = _get_version_from_tag_name(tag_name, data_version=True) | ||
if data_version is None: | ||
continue | ||
|
||
data_schema = get_data_schema_int(data_version) | ||
if data_schema != client_data_schema: | ||
continue | ||
return release | ||
return {} | ||
|
||
def get_latest_combo_file_urls(annotation_consortia, genome_builds): | ||
# lower case everything to be case insensitive | ||
annotation_consortia = {x.lower() for x in annotation_consortia} | ||
genome_builds = {x.lower() for x in genome_builds} | ||
|
||
file_urls = [] | ||
if latest_data_release := get_latest_data_release(): | ||
for asset in latest_data_release["assets"]: | ||
browser_download_url = asset["browser_download_url"] | ||
filename = browser_download_url.rsplit("/")[-1] | ||
if m := re.match(r"cdot-(\d+\.\d+\.\d+)\.(refseq|ensembl)\.(.+)\.json\.gz", filename): | ||
_version, annotation_consortium, genome_build = m.groups() | ||
if annotation_consortium.lower() in annotation_consortia and genome_build.lower() in genome_builds: | ||
file_urls.append(browser_download_url) | ||
return file_urls |