Manager

This module the database manager of ComPath.

class compath.manager.Manager(engine, session)[source]

Database manager.

Init ComPath manager.

static from_connection(connection=None)[source]

Initialize manager from connection string

create_all(check_first: bool = True)[source]

Create tables for ComPath.

drop_all(check_first: bool = True)[source]

Drop all tables for ComPath.

count_votes()int[source]

Count the votes in the database.

count_mappings()int[source]

Count the mappings in the database.

count_users()int[source]

Count the Users in the database.

count_mapping_user()int[source]

Count the UsersMappings table in the database.

Return type

int

get_all_mappings() → List[compath.models.PathwayMapping][source]

Get all mappings in the database.

get_all_accepted_mappings() → List[compath.models.PathwayMapping][source]

Get all accepted mappings in the database.

get_mappings_by_type(mapping_type: str) → List[compath.models.PathwayMapping][source]

Get all mappings in the database.

Parameters

mapping_type – type of the mapping

get_vote_by_id(vote_id: str) → Optional[compath.models.Vote][source]

Get a vote by its id.

Parameters

vote_id – identifier

get_vote(user: compath.models.User, mapping: compath.models.PathwayMapping) → Optional[compath.models.Vote][source]

Get a vote.

Parameters
  • user – User instance

  • mapping – Mapping instance

get_user_by_email(email: str) → Optional[compath.models.User][source]

Get a user by their email address.

get_mapping(service_1_name, pathway_1_id, pathway_1_name, service_2_name, pathway_2_id, pathway_2_name, mapping_type)[source]

Query mapping in the database.

Parameters
  • service_1_name (str) – manager name of the service 1

  • pathway_1_id (str) – pathway 1 id

  • pathway_1_name (str) – pathway 1 name

  • service_2_name (str) – manager name of the service 1

  • pathway_2_id (str) – pathway 2 id

  • pathway_2_name (str) – pathway 2 name

  • mapping_type (str) – mapping type (isPartOf or equivalentTo)

Return type

Optional[Mapping]

get_mapping_by_id(mapping_id: int) → Optional[compath.models.PathwayMapping][source]

Get a mapping by its id.

Parameters

mapping_id – mapping id

get_or_create_vote(user, mapping, vote_type=True)[source]

Get or create vote.

Parameters
  • user (User) – User instance

  • mapping (PathwayMapping) – Mapping instance

  • vote_type (Optional[Vote.type]) – vote type

Return type

Vote

get_or_create_mapping(service_1_name, pathway_1_id, pathway_1_name, service_2_name, pathway_2_id, pathway_2_name, mapping_type, user)[source]

Get or create a mapping.

Parameters
  • service_1_name (str) – manager name of the service 1

  • pathway_1_name (str) – pathway 1 name

  • pathway_1_id (str) – pathway 1 id

  • service_2_name (str) – manager name of the service 1

  • pathway_2_name (str) – pathway 2 name

  • pathway_2_id (str) – pathway 2 id

  • mapping_type (str) – type of mapping

  • user (User) – the user

Returns

PathwayMapping and boolean indicating if the mapping was created or not

Return type

tuple[PathwayMapping,bool]

delete_all_mappings()[source]

Delete all the votes then all the mappings.

delete_mapping_by_id(mapping_id)[source]

Delete a mapping by its id.

Parameters

mapping_id (int) – mapping id

Return type

bool

claim_mapping(mapping, user)[source]

Check if user has already established the mapping, if not claims it.

Parameters
Return type

bool

Returns

if mapping was assigned to user

accept_mapping(mapping_id)[source]

Accept established mapping (from user or curator consensus).

Parameters

mapping_id (int) – mapping id

Return type

tuple[PathwayMapping,bool]

Returns

mapping and boolean that indicates if transaction was made

get_mappings_from_pathway_with_relationship(type, service_name, pathway_id, pathway_name)[source]

Get all mappings matching pathway and service name.

Parameters
  • type (str) – mapping type

  • service_name (str) – service name

  • pathway_id (str) – original pathway identifier

  • pathway_name (str) – pathway name

Return type

list[PathwayMapping]

Returns

get_decendents_mappings_from_pathway_with_is_part_of_relationship(service_name, pathway_id, pathway_name)[source]

Get all mappings matching pathway and service name.

Parameters
  • type (str) – mapping type

  • service_name (str) – service name

  • pathway_id (str) – original pathway identifier

  • pathway_name (str) – pathway name

Return type

list[PathwayMapping]

Returns

get_ancestry_mappings_from_pathway_with_is_part_of_relationship(service_name, pathway_id, pathway_name)[source]

Get all mappings matching pathway and service name.

Parameters
  • type (str) – mapping type

  • service_name (str) – service name

  • pathway_id (str) – original pathway identifier

  • pathway_name (str) – pathway name

Return type

list[PathwayMapping]

Returns

get_all_mappings_from_pathway(service_name, pathway_id, pathway_name)[source]

Get all mappings matching pathway and service name.

Parameters
  • service_name (str) – service name

  • pathway_id (str) – original pathway identifier

  • pathway_name (str) – pathway name

Return type

list[PathwayMapping]

Returns

get_all_pathways_from_db_with_mappings(pathway_database)[source]

Get all mappings that contain a pathway from a given database.

Parameters
  • service_name (str) – service name

  • pathway_id (str) – original pathway identifer

  • pathway_name (str) – pathway name

Return type

list[PathwayMapping]

Returns

infer_hierarchy(resource, pathway_id, pathway_name)[source]

Infer the possible hierarchy of a given pathway based on its equivalent mappings.

Parameters
  • type (str) – mapping type

  • resource (str) – service name

  • pathway_id (str) – pathway original identifier

  • pathway_name (str) – pathway name

Returns