-
Notifications
You must be signed in to change notification settings - Fork 10
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 #31 from solvebio/feature/annotate-broken
Feature/annotate broken
- Loading branch information
Showing
21 changed files
with
191 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ipython | ||
nose |
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,77 @@ | ||
"""Dataset Class""" | ||
import re | ||
|
||
# __package__ = 'solvebio.resource' | ||
from ..client import client | ||
from ..help import open_help | ||
from ..query import Query, PagingQuery | ||
|
||
from .solveobject import convert_to_solve_object | ||
from .resource import CreateableAPIResource, ListableAPIResource, \ | ||
UpdateableAPIResource | ||
from .datasetfield import DatasetField | ||
|
||
|
||
class Dataset(CreateableAPIResource, ListableAPIResource, | ||
UpdateableAPIResource): | ||
""" | ||
Datasets are access points to data. Dataset names are unique | ||
within versions of a depository. | ||
""" | ||
ALLOW_FULL_NAME_ID = True | ||
FULL_NAME_REGEX = r'^([\w\d\-\.]+/){2}[\w\d\-\.]+$' | ||
|
||
@classmethod | ||
def retrieve(cls, id, **params): | ||
"""Supports lookup by full name""" | ||
if isinstance(id, unicode) or isinstance(id, str): | ||
_id = unicode(id).strip() | ||
id = None | ||
if re.match(cls.FULL_NAME_REGEX, _id): | ||
params.update({'full_name': _id}) | ||
else: | ||
raise Exception('Unrecognized full name.') | ||
|
||
return super(Dataset, cls).retrieve(id, **params) | ||
|
||
def depository_version(self): | ||
from .depositoryversion import DepositoryVersion | ||
return DepositoryVersion.retrieve(self['depository_version']) | ||
|
||
def depository(self): | ||
from .depository import Depository | ||
return Depository.retrieve(self['depository']) | ||
|
||
def fields(self, name=None, **params): | ||
if 'fields_url' not in self: | ||
raise Exception( | ||
'Please use Dataset.retrieve({ID}) before doing looking ' | ||
'up fields') | ||
|
||
if name: | ||
# construct the field's full_name if a field name is provided | ||
return DatasetField.retrieve( | ||
'/'.join([self['full_name'], name])) | ||
|
||
response = client.request('get', self.fields_url, params) | ||
return convert_to_solve_object(response) | ||
|
||
def _data_url(self): | ||
if 'data_url' not in self: | ||
if 'id' not in self or not self['id']: | ||
raise Exception( | ||
'No Dataset ID was provided. ' | ||
'Please instantiate the Dataset ' | ||
'object with an ID or full_name.') | ||
# automatically construct the data_url from the ID | ||
return self.instance_url() + u'/data' | ||
return self['data_url'] | ||
|
||
def query(self, paging=False, **params): | ||
self._data_url() # raises an exception if there's no ID | ||
query_klass = PagingQuery if paging else Query | ||
q = query_klass(self['id'], **params) | ||
return q.filter(params.get('filters')) if params.get('filters') else q | ||
|
||
def help(self): | ||
open_help(self['full_name']) |
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,39 @@ | ||
"""DatasetField Class""" | ||
import re | ||
|
||
from ..client import client | ||
|
||
from .solveobject import convert_to_solve_object | ||
from .resource import CreateableAPIResource, ListableAPIResource, \ | ||
UpdateableAPIResource | ||
|
||
|
||
class DatasetField(CreateableAPIResource, ListableAPIResource, | ||
UpdateableAPIResource): | ||
""" | ||
Each SolveBio dataset has a different set of fields, some of | ||
which can be used as filters. Dataset field resources provide | ||
users with documentation about each field. | ||
""" | ||
ALLOW_FULL_NAME_ID = True | ||
FULL_NAME_REGEX = r'^([\w\d\-\.]+/){3}[\w\d\-\.]+$' | ||
|
||
@classmethod | ||
def retrieve(cls, id, **params): | ||
"""Supports lookup by ID or full name""" | ||
if isinstance(id, unicode) or isinstance(id, str): | ||
_id = unicode(id).strip() | ||
id = None | ||
if re.match(cls.FULL_NAME_REGEX, _id): | ||
params.update({'full_name': _id}) | ||
else: | ||
raise Exception('Unrecognized full name.') | ||
|
||
return super(DatasetField, cls).retrieve(id, **params) | ||
|
||
def facets(self, **params): | ||
response = client.request('get', self.facets_url, params) | ||
return convert_to_solve_object(response) | ||
|
||
def help(self): | ||
return self.facets() |
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
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,5 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
from ..client import client | ||
|
||
from .util import json | ||
|
||
|
||
|
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,6 @@ | ||
# -*- coding: utf-8 -*- | ||
from .resource import SingletonAPIResource | ||
|
||
|
||
class User(SingletonAPIResource): | ||
pass |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import os | ||
import re | ||
import unittest | ||
|
||
import solvebio | ||
|
||
TEST_DATASET_NAME = 'ClinVar/2.0.0-1/Variants' | ||
|
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
Oops, something went wrong.