Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.default_version = default_version
self.versions = versions
super().__init__(
path=versions[default_version].path,
import_args=versions[default_version].import_args,
import_func=versions[default_version].import_func
)
def __repr__(self):
return f'{self.__class__.__name__}(default_version={self.default_version}, default_resource={self.versions[self.default_version]}, versions={list(self.versions.keys())})'
class VersionedTableResource(BaseVersionedResource, TableResource):
"""
Versioned Table resource
The attributes (path, import_args and import_func) of the versioned resource are those of the default version of the resource.
In addition, all versions of the resource are stored in the `versions` attribute.
:param default_version: The default version of this Table resource (must to be in the `versions` dict)
:param versions: A dict of version name -> TableResource.
"""
def __init__(self, default_version: str, versions: Dict[str, TableResource]):
super().__init__(default_version, versions)
class VersionedMatrixTableResource(BaseVersionedResource, MatrixTableResource):
"""
Versioned MatrixTable resource
class VersionedMatrixTableResource(BaseVersionedResource, MatrixTableResource):
"""
Versioned MatrixTable resource
The attributes (path, import_args and import_func) of the versioned resource are those of the default version of the resource.
In addition, all versions of the resource are stored in the `versions` attribute.
:param default_version: The default version of this MatrixTable resource (must to be in the `versions` dict)
:param versions: A dict of version name -> MatrixTableResource.
"""
def __init__(self, default_version: str, versions: Dict[str, MatrixTableResource]):
super().__init__(default_version, versions)
class VersionedPedigreeResource(BaseVersionedResource, PedigreeResource):
"""
Versioned Pedigree resource
The attributes (path, import_args and import_func) of the versioned resource are those of the default version of the resource.
In addition, all versions of the resource are stored in the `versions` attribute.
:param default_version: The default version of this Pedigree resource (must be in the `versions` dict)
:param versions: A dict of version name -> PedigreeResource.
"""
def __init__(self, default_version: str, versions: Dict[str, PedigreeResource]):
super().__init__(default_version, versions)
class VersionedBlockMatrixResource(BaseVersionedResource, BlockMatrixResource):
"""
import gnomad.resources.grch37 as grch37
grch37_resources = get_module_importable_resources(grch37, prefix='grch37')
:param module: Input module
:param prefix:
:return:
"""
_prefix = f"{prefix}." if prefix else ""
resources = {}
for resource_name, resource in getmembers(
module, lambda x: isinstance(x, BaseResource)
):
if resource.path and resource.import_func:
arg_name = f"{_prefix}{resource_name}"
if isinstance(resource, BaseVersionedResource):
for version in resource.versions:
arg_name += f".{version}"
resource_name = f"{resource_name} version {version}"
resources[arg_name] = (resource_name, resource)
return resources
def __init__(self, default_version: str, versions: Dict[str, BaseResource]):
if type(self) is BaseVersionedResource:
raise TypeError("Can't instantiate abstract class BaseVersionedResource")
if default_version not in versions:
raise KeyError(
f"default_version {default_version} not found in versions dictionary passed to {self.__class__.__name__}.")
for version_name, version_resource in versions.items():
if version_resource.__class__ not in self.__class__.__bases__:
raise TypeError(f"Cannot create a {self.__class__.__name__} resource with version {version_name} of type {version_resource.__class__.__name__}")
self.default_version = default_version
self.versions = versions
super().__init__(
path=versions[default_version].path,
import_args=versions[default_version].import_args,
class VersionedPedigreeResource(BaseVersionedResource, PedigreeResource):
"""
Versioned Pedigree resource
The attributes (path, import_args and import_func) of the versioned resource are those of the default version of the resource.
In addition, all versions of the resource are stored in the `versions` attribute.
:param default_version: The default version of this Pedigree resource (must be in the `versions` dict)
:param versions: A dict of version name -> PedigreeResource.
"""
def __init__(self, default_version: str, versions: Dict[str, PedigreeResource]):
super().__init__(default_version, versions)
class VersionedBlockMatrixResource(BaseVersionedResource, BlockMatrixResource):
"""
Versioned BlockMatrix resource
The attributes (path, import_args and import_func) of the versioned resource are those of the default version of the resource.
In addition, all versions of the resource are stored in the `versions` attribute.
:param default_version: The default version of this BlockMatrix resource (must to be in the `versions` dict)
:param versions: A dict of version name -> BlockMatrixResource.
"""
def __init__(self, default_version: str, versions: Dict[str, BlockMatrixResource]):
super().__init__(default_version, versions)
class DataException(Exception):
pass