Skip to content

Commit

Permalink
Merge pull request #27 from ga4gh/sra_logical_ids_ID5
Browse files Browse the repository at this point in the history
Sra logical ids id5
  • Loading branch information
ianfore authored Feb 7, 2021
2 parents 9252261 + db5de79 commit c8095de
Show file tree
Hide file tree
Showing 13 changed files with 2,393 additions and 37 deletions.
12 changes: 12 additions & 0 deletions fasp/loc/DRSClient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
import json
#from builtins import None

class DRSClient:
'''Basic DRS functions, no bundle handling'''
Expand Down Expand Up @@ -67,5 +68,16 @@ def getAccessURL(self, object_id, access_id=None):
print (response.content)
return None


def getAccessURLRegion(self, object_id, region):
''' get an access url for the object in the specified region'''
access_methods = self.getObject(object_id)['access_methods']
am = next((sub for sub in access_methods if sub['region'] == 's3.us-east-1'), None)
if am == None:
print ('object not in region {}'.format(region))
return None
return self.getAccessURL(object_id, am['access_id'])


def getHeaders(self):
return {'Authorization' : 'Bearer {0}'.format(self.access_token) }
4 changes: 2 additions & 2 deletions fasp/loc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from fasp.loc.gen3drsclient import anvilDRSClient
from fasp.loc.gen3drsclient import kfDRSClient

from fasp.loc.sbdrsclient import sbcgcDRSClient, cavaticaDRSClient, SBDRSClient
from fasp.loc.sbdrsclient import sbcgcDRSClient, cavaticaDRSClient, sbbdcDRSClient, SBDRSClient

from fasp.loc.sdl_drsclient import sdlDRSClient
from fasp.loc.sdl_drsclient import sdlDRSClient, SRADRSClient

from fasp.loc.ga4gh_registry_client import GA4GHRegistryClient

Expand Down
7 changes: 4 additions & 3 deletions fasp/loc/drs_metaresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from fasp.loc import crdcDRSClient, bdcDRSClient, Gen3DRSClient, anvilDRSClient
from fasp.loc import sdlDRSClient
from fasp.loc import sbcgcDRSClient, cavaticaDRSClient
from fasp.loc import sbcgcDRSClient, cavaticaDRSClient, sbbdcDRSClient
from fasp.loc import DRSClient
from fasp.loc import GA4GHRegistryClient

Expand All @@ -23,7 +23,8 @@ def __init__(self, debug=False, getReg=True):
"anv": anvilDRSClient('~/.keys/anvil_credentials.json', '', 'gs'),
"insdc": sdlDRSClient('~/.keys/prj_11218_D17199.ngc'),
"sbcgc": sbcgcDRSClient('~/.keys/sevenbridges_keys.json','s3'),
"sbcav": cavaticaDRSClient('~/.keys/sevenbridges_keys.json','s3'),
"sbcav": cavaticaDRSClient('~/.keys/sevenbridges_keys.json','gs'),
'sbbdc' : sbbdcDRSClient('~/.keys/sevenbridges_keys.json', 's3'),
"srapub": DRSClient('https://locate.ncbi.nlm.nih.gov', debug=False)
}
self.registeredClients = []
Expand All @@ -35,7 +36,7 @@ def __init__(self, debug=False, getReg=True):
def getObject(self, colonPrefixedID):
client, id = self.getClient(colonPrefixedID)
if client != None:
print('sending id {} to: {}'.format(id, client.__class__.__name__))
if self.debug: print('sending id {} to: {}'.format(id, client.__class__.__name__))
return client.getObject(id)
else:
return "prefix unrecognized"
Expand Down
10 changes: 8 additions & 2 deletions fasp/loc/sbdrsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,24 @@ def getHeaders(self):


class sbcgcDRSClient(SBDRSClient):
'''client for Seven Bridges Cancer Genomics Cloud DRS server'''
'''client for Cancer Genomics Cloud Seven Bridges DRS server'''

# Mostly done by the SBDRSClient, this just deals with url and end point specifics
def __init__(self, api_key_path, access_id, debug=False):
super().__init__('https://cgc-ga4gh-api.sbgenomics.com', api_key_path, 'cgc', access_id, debug=debug)

class cavaticaDRSClient(SBDRSClient):
'''client for Cavatica DRS Server'''
'''client for Cavatica Seven Bridges DRS Server'''
# init mostly done by the SBDRSClient, this just deals with url and end point specifics
def __init__(self, api_key_path, access_id, debug=False):
super().__init__('https://cavatica-ga4gh-api.sbgenomics.com', api_key_path, 'cavatica', access_id, debug=debug)

class sbbdcDRSClient(SBDRSClient):
'''client for BioDataCatalyst Seven Bridges DRS Server'''
# init mostly done by the SBDRSClient, this just deals with url and end point specifics
def __init__(self, api_key_path, access_id, debug=False):
super().__init__('https://ga4gh-api.sb.biodatacatalyst.nhlbi.nih.gov', api_key_path, 'bdc', access_id, debug=debug)



if __name__ == "__main__":
Expand Down
16 changes: 16 additions & 0 deletions fasp/loc/sdl_drsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@

from fasp.loc import DRSClient

class SRADRSClient(DRSClient):
'''SRA DRS client with ability to convert SRA accessions to DRS ids'''

def __init__(self, api_url_base, access_id=None, debug=False, public=False):
super().__init__(api_url_base, access_id, debug, public)


def acc2drs(self, accession, verbose=False):
''' get a drs id for an SRA accession id'''
url = '{}/idx/v1/{}'.format(self.api_url_base, accession)
if verbose: print(url)
response = requests.get(url)
if verbose: print(response)
idxResp = json.loads(response.content)
return idxResp

class sdlDRSClient(DRSClient):

def __init__(self, ngc_file, debug=False):
Expand Down
15 changes: 13 additions & 2 deletions fasp/search/discovery_search_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,19 @@ def listTableInfo(self, table, verbose=False):
print(json.dumps(info, indent=3))
return info

def listTableColumns(self, table, descriptions=False):
def listTableColumns(self, table, descriptions=False, enums=False):
''' List the columns in a table. More compact and practical for many purposes compared with listTableInfo '''
schema = self.listTableInfo(table)
for c, v in schema['data_model']['properties'].items():
print (c)
if descriptions: print (v['$comment'])
if descriptions:
if 'description' in v: print (v['description'])
if '$comment' in v: print (v['$comment'])
if enums:
if 'oneOf' in v:
for c in v['oneOf']:
print ('\t\t{}'.format(c['const']))
if '$comment' in v: print (v['$comment'])
print('_______________________________________')

def getMappingTemplate(self, table, propList=None):
Expand Down Expand Up @@ -142,6 +149,7 @@ def runQuery(self, query, returnType=None):
headers=self.headers, data = query2)
else:
response = requests.request("GET", next_url)
if self.debug: print(response.content)
result = (response.json())
if self.debug:
pprint.pprint(result)
Expand All @@ -162,6 +170,9 @@ def runQuery(self, query, returnType=None):
else:
return resultRows

def query2Frame(self, query):
return self.runQuery(query, returnType='dataframe')


def usage():
print (sys.argv[0] +' -l listTables -c listCatalog -t tableInfo -r registeredServices')
Expand Down
Loading

0 comments on commit c8095de

Please sign in to comment.