datasets_api package

Subpackages

Submodules

datasets_api.models module

class datasets_api.models.Dataset(*args, **kwargs)[source]

Bases: Model

Datasets and permissions on datasets.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

ancestor

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

broken: BooleanField

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

dataset_id: TextField

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

dataset_name: TextField

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property default_groups: list[str]
descendant

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

groups: ManyToManyField

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
classmethod recreate_dataset_perm(dataset_id: str) None[source]

Add the default groups to a dataset object.

classmethod set_broken(dataset_id: str, *, broken: bool) None[source]

Set a Dataset object’s broken status to the given value.

Datasets should be flagged broken before loading and checked after loading to be unflagged.

classmethod update_name(dataset_id: str, dataset_name: str) None[source]

Update a Dataset object’s name to the given value.

class datasets_api.models.DatasetHierarchy(*args, **kwargs)[source]

Bases: Model

Data for dataset hierarchy and inheritance.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

classmethod add_relation(instance_id: str, ancestor_id: str, descendant_id: str, *, direct: bool = False) None[source]

Add a relation to the hierarchy with provided dataset IDs.

ancestor: ForeignKey

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

ancestor_id
classmethod clear(instance_id: str) None[source]

Clear the model’s records.

descendant: ForeignKey

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

descendant_id
direct: BooleanField

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod get_children(instance_id: str, dataset: Dataset, *, direct: bool | None = None) list[Dataset][source]

Return all children of a given dataset.

classmethod get_direct_datasets_parents(instance_id: str, datasets: Iterable[Dataset]) dict[str, list[str]][source]

Return dictionary of parents for a list of DB datasets.

classmethod get_parents(instance_id: str, dataset: Dataset, *, direct: bool | None = None) list[Dataset][source]

Return all parents of a given dataset.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

instance_id: TextField

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod is_study(instance_id: str, dataset: Dataset) bool[source]

Return whether a dataset is a study.

A dataset without children is a study and not a group.

objects = <django.db.models.manager.Manager object>

datasets_api.permissions module

class datasets_api.permissions.IsDatasetAllowed[source]

Bases: BasePermission

Checks the permissions to a dataset.

has_object_permission(request: HttpRequest, _view: Any, obj: str) bool[source]

Return True if permission is granted, False otherwise.

has_permission(request: HttpRequest, view: Any) bool[source]

Return True if permission is granted, False otherwise.

static permitted_datasets(user: User, instance_id: str) Iterable[str][source]

Return list of allowed datasets for a specific user.

static prepare_allowed_datasets_query() str[source]

Return query for getting all datasets a user has access to.

This handles cases in the hierarchy where there are partial rights. Query is divided and abstracted into multiple Common Table Expressions. The query has a single parameter for user ID and returns rows of dataset DB ID and WDAE ID pairs.

user_to_group joins users with their respective groups. dataset_to_group joins datasets with their respective groups.

from_root and to_root are recursive and walk through the dataset hierarchy from a given dataset ID in the respective direction.

dataset_branch combines from_root and to_root to give all datasets present in a dataset hierarchy “branch”.

datasets_api.permissions.add_group_perm_to_dataset(group_name: str, dataset_id: str) None[source]
datasets_api.permissions.add_group_perm_to_user(group_name: str, user: User) None[source]
datasets_api.permissions.get_allowed_genotype_studies(instance_id: str, user: User, dataset_id: str) set[str][source]

Collect and return genotype study IDs the user has access to.

datasets_api.permissions.get_dataset_groups(dataset: str | Dataset) set[str][source]
datasets_api.permissions.get_dataset_info(dataset_id: str) dict[str, Any] | None[source]

Return a dictionary describing a Dataset object.

datasets_api.permissions.get_directly_allowed_genotype_data(user: User) list[dict[str, Any]][source]

Return list of genotype data the user has direct permissions to.

datasets_api.permissions.get_instance_timestamp_etag(_request: Request, **_kwargs: dict[str, Any]) str[source]
datasets_api.permissions.get_permissions_etag(request: Request, **_kwargs: dict[str, Any]) str[source]

Return E-Tag for queries dependant on user access permissions.

datasets_api.permissions.get_user_groups(user: User) set[str][source]
datasets_api.permissions.get_wdae_children(instance_id: str, dataset_id: str) list[Dataset][source]

Return list of child wdae dataset objects.

Given a dataset ID or DAE genotype data object or WDAE dataset object, returns list of direct childrens as WDAE dataset object (if ‘leaves’ parameter is ‘False’). If ‘leaves’ parameter is ‘True’, returns list of leaves of the datasets tree.

datasets_api.permissions.get_wdae_dataset(dataset: str) Dataset | None[source]

Return wdae dataset object.

Given a dataset ID or DAE genotype data object, returns WDAE dataset object.

datasets_api.permissions.get_wdae_parents(instance_id: str, dataset_id: str, *, direct: bool = False) list[Dataset][source]

Return list of parent wdae dataset objects.

Given a dataset ID or DAE genotype data object or WDAE dataset object, returns list of parents as WDAE dataset object.

datasets_api.permissions.handle_partial_permissions(instance_id: str, user: User, dataset_id: str, request_data: dict) None[source]

Handle partial permission on a dataset.

A user may have only partial access to a dataset based on which of its constituent studies he has rights to access. This method attaches these rights to the request as study filters in order to filter variants from studies the user cannot access.

datasets_api.permissions.user_has_permission(instance_id: str, user: User, dataset_id: str) bool[source]

Check if a user has permission to browse the given dataset.

datasets_api.urls module

datasets_api.views module

class datasets_api.views.BaseDatasetPermissionsView[source]

Bases: QueryBaseView

Base dataset permission view.

class datasets_api.views.DatasetDescriptionView[source]

Bases: QueryBaseView

Provide fetching and editing a dataset’s description.

get(_request: Request, dataset_id: str | None) Response[source]

Collect a dataset’s description.

post(request: Request, dataset_id: str) Response[source]

Overwrite a dataset’s description.

class datasets_api.views.DatasetHierarchyView[source]

Bases: QueryBaseView

Provide the hierarchy of one dataset configured in the instance.

get(request: Request, dataset_id: str | None = None) Response[source]

Return the hierarchy of one dataset in the instance.

produce_tree(dataset: WDAEStudy, selected: list[str], permitted_datasets: set[str]) dict[str, Any] | None[source]

Recursively collect a dataset’s id, children and access rights.

class datasets_api.views.DatasetPedigreeView[source]

Bases: QueryBaseView

Provide pedigree data for a given dataset.

get(_request: Request, dataset_id: str, column: str) Response[source]

Return response for a pedigree get request for pedigree column.

class datasets_api.views.DatasetPermissionsSingleView[source]

Bases: BaseDatasetPermissionsView

Single dataset permission view.

get(_request: Request, dataset_id: str) Response[source]

Return dataset permission details.

page_size = 25
class datasets_api.views.DatasetPermissionsView[source]

Bases: BaseDatasetPermissionsView

Dataset permissions view.

get(request: Request) Response[source]

Return dataset permissions details.

page_size = 25
class datasets_api.views.DatasetView[source]

Bases: QueryBaseView

General dataset view.

Provides either a summary of ALL available dataset configs or a specific dataset configuration in full, depending on whether the request is made with a dataset_id param or not.

get(request: Request, dataset_id: str | None = None) Response[source]

Return response to a get request for a dataset or all datasets.

class datasets_api.views.FederationDatasetsView[source]

Bases: QueryBaseView

Class used for federation-related dataset requests.

get(request: Request) Response[source]

Provide available datasets and their configurations.

class datasets_api.views.VisibleDatasetsView[source]

Bases: QueryBaseView

Provide a list of which datasets to show in the frontend.

get(_request: Request) Response[source]

Return the list of visible datasets.

datasets_api.views.augment_accessibility(dataset: dict[str, Any], allowed_datasets: Iterable[str]) dict[str, Any][source]

Augment a dataset response JSON with access_rights section.

datasets_api.views.augment_with_groups(dataset: dict[str, Any], db_dataset: Dataset | None = None) dict[str, Any][source]

Add groups to response object.

datasets_api.views.augment_with_parents(instance_id: str, dataset: dict[str, Any]) dict[str, Any][source]

Augment a dataset response JSON with parents section.

datasets_api.views.get_description_etag(request: Request, **_kwargs: dict[str, Any]) str | None[source]

Get description etag.

Module contents