Skip to content

Instantly share code, notes, and snippets.

@DailyDreaming
Last active May 4, 2021 19:43
Show Gist options
  • Save DailyDreaming/993417a8d00798ec6423f4e80b570410 to your computer and use it in GitHub Desktop.
Save DailyDreaming/993417a8d00798ec6423f4e80b570410 to your computer and use it in GitHub Desktop.
check_picsure_status
import PicSureClient, PicSureHpdsLib
# Based on: https://github.com/hms-dbmi/pic-sure-python-client
# and: https://terra.biodatacatalyst.nhlbi.nih.gov/#workspaces/biodata-catalyst/BioData%20Catalyst%20PIC-SURE%20API%20Python%20examples/notebooks
#
# +--------------------------------------+------------------------------------------------------+
# | Resource UUID | Resource Name |
# +--------------------------------------+------------------------------------------------------+
# | 02e23f52-f354-4e8b-992c-d37c8b9ba140 | |
# | 70c837be-5ffc-11eb-ae93-0242ac130002 | |
# +--------------------------------------+------------------------------------------------------+
def picsure_health_check():
token = 'somethingsomething'
domain = 'https://picsure.biodatacatalyst.nhlbi.nih.gov/info/resources'
resource_id = '02e23f52-f354-4e8b-992c-d37c8b9ba140'
try:
client = PicSureClient.Client()
connection = client.connect(domain, token)
adapter = PicSureHpdsLib.Adapter(connection)
resource = adapter.useResource(resource_id)
# TODO: Check contents of this and only return True if something is there:
copdgene_data = resource.dictionary().find("Genetic Epidemiology of COPD (COPDGene)").DataFrame()
header_seen = 'Genetic Epidemiology of COPD (COPDGene)' in str(copdgene_data)
# last line looks like: "[353 rows x 7 columns]"; parse this to determine a non-zero # of rows
rows_are_non_zero = int(str(copdgene_data).split('\n')[-1].split(' ')[0][1:]) > 0
return header_seen and rows_are_non_zero
except Exception: # if not authorized, this returns a KeyError
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment