Package biana :: Package BianaDB :: Module BianaDBaccess' :: Class BianaDBaccess
[hide private]
[frames] | no frames]

Class BianaDBaccess

source code


Class used as an interface with database biana

Instance Methods [hide private]
 
NEWget_user_entity_relations(self, unification_protocol_name, userEntityID_list, attribute_restrictions=[], negative_attribute_restrictions=[], listRelationType=[], dictRelationAttributeRestriction={}, use_self_relations=True, limit_to_userEntityID_list=False, use_nested_relations=True)
Returns the list of relations where the userEntity is involved use_nested_relations ==> Include relations greater than a nested level
source code
 
OLDget_user_entity_relations(self, unification_protocol_name, userEntityID_list, attribute_restrictions=[], negative_attribute_restrictions=[], listRelationType=[], dictRelationAttributeRestriction={}, use_self_relations=True, limit_to_userEntityID_list=False, use_nested_relations=True)
#! Nasty trick (not used anymore): to not to join externalEntityType table in the query in case sth is interacting with itself (see use_self_relations) there is an internal type called "self_type" which should be handled carefully whenever this method is called and type is going to be used
source code
 
__getnewargs__(self) source code
 
__getstate__(self) source code
 
__init__(self, dbname=None, dbhost=None, dbuser=None, dbpassword=None, dbport=None, dbsocket=None, use_buffer=False, lock_tables=False, check_integrity=False)
"dbname" is the database name to which you want to connect to (required) "dbhost" is the machine with the mysql server that holds the biana database (required) "dbuser" is the mysql user (not required in most systems) "dbpassword" is the mysql password (not required in most systems) "dbport" is the mysql port (not required in most systems)
source code
 
__setstate__(self, dict) source code
 
__str__(self)
str(x)
source code
 
_add_key_attribute(self, external_database_id, key_attribute)
Adds a key attribute, used in transfer attributes (key attribute) and ontologies (linked attribute)
source code
 
_add_transfer_attribute(self, externalDatabaseID, key_attribute, transfer_attribute) source code
 
_apply_negative_restrictions_to_query(self, query, unification_protocol_name, negative_attribute_restrictions, column_name_to_restrict='userEntityID') source code
 
_apply_relation_restrictions_to_query(self, query, attribute_restrictions_dict, column_name_to_restrict='externalEntityRelationID') source code
 
_apply_restrictions_to_query(self, query, unification_protocol_name, attribute_restrictions, column_name_to_restrict='userEntityID')
Applies the restrictions for a given query, where some user entites must be restricted
source code
 
_check_database_integrity(self)
Checks the integrity of the database
source code
 
_convertListSourceDBVersionToSourceDBIdList(self, source_databases) source code
 
_create_new_unification_protocol_tables(self, protocol) source code
 
_empty_sequences_table(self, type) source code
 
_get_attribute_restrictions_query(self, unification_protocol_name, negative_attribute_restrictions) source code
 
_get_attribute_value_list_for_transfer_attributes(self, attribute_identifier, field_values)
returns a list of (field, value) of the transferred attribute
source code
 
_get_db_versions_list(self) source code
 
_get_equivalent_external_entities(self, unification_atom_element)
returns the query to obtain the list of equivalent
source code
 
_get_equivalent_user_entities_by_sharing_attributes(self, unification_protocol_name, user_entity_id_list, attribute_list)
Returns a list of tuples with userEntityID1, userEntityID2 OBSOLETE - use get_user_entity_relations_by_sharing_attributes instead
source code
 
_get_expand_ontology_attribute_table_query(self, attribute_identifier, values_to_expand_list) source code
 
_get_externalDatabaseID_int(self, sourceDBName, sourceDBVersion)
Returns the decimal value assigned to the sourceDB (externalDatabaseID will be converted to lower_case)
source code
 
_get_key_attribute_table_name(self, key_id) source code
 
_get_last_external_entity_id(self) source code
 
_get_last_external_entity_relation_participant_id(self) source code
 
_get_last_key_id(self) source code
 
_get_last_sequenceNucleotide_id(self) source code
 
_get_last_sequenceProtein_id(self) source code
 
_get_last_stable_external_entity_id(self) source code
 
_get_last_stable_external_entity_relation_participant_id(self) source code
 
_get_last_stable_key_id(self) source code
 
_get_last_stable_sequenceNucleotide_id(self) source code
 
_get_last_stable_sequenceProtein_id(self) source code
 
_get_linked_attribute_ontology_name(self, attribute_identifier)
Returns the name of the ontology linked to an attribute
source code
 
_get_list_eE_for_uE(self, unification_protocol_name, userEntityID) source code
 
_get_list_external_entities_IDs_by_attribute_SQLstat(self, attribute_identifier, field_values, source_databases=[], attribute_restrictions=None, expand_ontology_attributes=True)
Gets a list of external entities that have an attribute with "attribute_value" value "field_value" is the field/S and value/S we want to obtain If a value is *, it will obtain all having this attribute
source code
 
_get_list_external_entities_for_user_entities(self, unification_protocol_name, userEntityID_list) source code
 
_get_list_user_entities_IDs_by_attribute_transfer_query(self, attribute_identifier, field_values, unification_protocol_name, source_databases=[], attribute_restrictions=None, include_type=False, restrict_to_user_entity_ids_list=[]) source code
 
_get_list_user_entities_for_external_entities(self, unification_protocol_name, externalEntityID_list) source code
 
_get_nested_queries_for_getting_equivalent_uE_by_sharing_attributes(self, unification_protocol_name, attribute_list, user_entity_ids_list, restrict_to_user_entity_ids_list=True, ontology_levels={})
Returns a string with a sql query.
source code
 
_get_new_external_entity_id(self) source code
 
_get_new_external_entity_relation_participant_id(self) source code
 
_get_new_key_id(self) source code
 
_get_new_sequenceNucleotide_id(self) source code
 
_get_new_sequenceProtein_id(self) source code
 
_get_similar_sequences(self, sequenceID, bit_score=None, identity_percent=None, similarity_percent=None, query_coverage_percent=None, match_coverage_percent=None)
Gets similar sequences from database
source code
 
_get_table_names(self) source code
 
_get_user_entity_table_name(self, unification_protocol_name) source code
 
_get_valid_source_databases_by_id(self) source code
 
_get_valid_source_dbs(self)
Returns a dictionary with current external databases stored in BIANA database
source code
 
_insert_blast_results_file(self, file_fd)
METHOD TO TEST
source code
 
_insert_external_entity_attribute(self, externalEntityID, externalEntityAttribute)
Adds a new attribute to the external entity externalEntityID must exist previously
source code
 
_insert_external_entity_relation_participant_attribute(self, pParticipantID, pExternalEntityRelationParticipantAttribute) source code
 
_insert_protein_sequence_cd_hit_cluster(self, cd_hit_cluster) source code
 
_insert_sequence(self, sequence)
Inserts a sequence object into BIANA database and returns its ID.
source code
 
_insert_sequence_file(self, input_fd, type, format='fasta', verbose=True)
Inserts a sequence file to the database
source code
 
_is_key_attribute(self, attribute_identifier, external_database_id) source code
 
_is_ontology_linked_attribute(self, attribute_identifier) source code
 
_is_transferred_attribute(self, attribute_identifier) source code
 
_load_available_unification_protocols(self)
Gets the information about available unification protocols
source code
 
_load_biana_database_information(self)
Method to load biana database information into this class
source code
 
_load_biana_types_and_attributes(self)
Method to load current biana database types and attributes
source code
 
_load_sequences(self, sequenceIdList, type='proteinsequence')
Gets multiple sequence object from BIANA database
source code
 
_rollback(self)
Method used to undo all the changes from an stable data insert
source code
 
_transform_attribute_value_data_type_to_biana_database_attribute_data_type(self, attribute_identifier, value) source code
 
_unify_promiscuous_external_entities(self, protocol) source code
 
_update_bianaDB_autoincrement_fields(self)
Method used internally to control biana autoincrement fields.
source code
 
_update_bianaDB_version(self)
Method used internally to control biana version to be able to control compatibilities between diffent database versions
source code
 
_update_relations_hierarchy(self)
Precalculates and stores in database relations hierachy
source code
 
add_hssp_info_to_pdb(self, pdb_code, chain, residue_pdb_number, residue_hssp_entropy, residue_hssp_norm_entropy, residue_hssp_variability, conservation_hssp, solvent_exposure_hssp, dssp)
Adds HSSP information to pdb files
source code
 
add_valid_external_entity_attribute_type(self, name, data_type, category) source code
 
add_valid_external_entity_relation_participant_attribute_type(self, name, data_type) source code
 
add_valid_external_entity_relation_type(self, type) source code
 
add_valid_external_entity_type(self, type) source code
 
add_valid_identifier_reference_types(self, current_reference_type) source code
 
close(self)
Close the connection with database
source code
 
create_database(self, dbname, description='BIANA DATABASE', optimize_for='parsing', ignore_primary_keys=False)
It creates necessary tables into a database server
source code
 
create_new_user_entities(self, protocol)
"protocol" is the UnificationProtocol object that has to be followed
source code
 
drop_unification_protocol(self, unification_protocol_name)
Drops from the database all the information of a protocol of unification
source code
 
get_alignment(self, externalEntityID, get_species=False, range=None)
Returns an alignment object identified by the externalEntityID used as parameter
source code
 
get_available_ontology_names(self, name=None) source code
 
get_available_unification_protocols_list(self) source code
 
get_default_external_entity_ids(self, externalEntityIDsList) source code
 
get_equivalent_user_entities_from_list(self, userEntitiesList, attribute, protocol_id) source code
 
get_expanded_entity_relations(self, unification_protocol_name, userEntityID_list, expansionAttributesList=[], listRelationType=[], use_self_relations=True, limit_to_userEntityID_list=False, expansionLevel=2, attribute_restrictions=[], negative_attribute_restrictions=[])
unification_protocol_name: name of the unification protocol to be used
source code
 
get_external_database(self, database_id) source code
 
get_external_database_list(self) source code
 
get_external_entities_dict(self, externalEntityIdsList, attribute_list=[], relation_attribute_list=[], participant_attribute_list=[], useTransferAttributes=True)
Returns a dict of external Entity Objects with the attributes specified in the "attribute_identifier_list"
source code
 
get_external_entities_dict_by_attribute(self, attribute_identifier, field_values, source_databases=None, attribute_restrictions=None, attribute_list=[], relation_attribute_list=[], participant_attribute_list=[]) source code
 
get_list_external_entities_IDs_by_attribute(self, attribute_identifier, field_values, source_databases=[], attribute_restrictions=None) source code
 
get_list_user_entities_IDs_by_attribute(self, unification_protocol_name, attribute_identifier, field_values, attribute_restrictions=None, negative_attribute_restrictions=None, restrict_to_user_entity_ids_list=[], include_type=False)
Returns a list of user entities that match with the attributes specified of type attribute_identifier
source code
 
get_ontology(self, ontology_name, root_attribute_values=[], load_external_entities=False)
Loads ontology object
source code
 
get_relations_hierarchy(self, externalEntityRelationIDs)
Returns a list of tuples (relationID1, relationID2) in where relationID1 is a child of relationID2
source code
 
get_sequence_from_sequenceID(self, sequenceID) source code
 
get_sequence_taxonomies(self, sequenceID) source code
 
get_taxonomies_from_species_name(self, species_name) source code
 
get_taxonomy_names_taxID_dict(self, tax_id_name_type=None)
name is lower cased
source code
 
get_unification_protocol_atoms(self, unification_protocol_name)
Fetchs from the database all the atom information of a protocol of unification
source code
 
get_user_entity_attributes(self, unification_protocol_name, listUserEntityID, attribute_identifier)
Returns a dictionary with { userEntityID: list of attributes }
source code
 
get_user_entity_id_and_type_tuple_list(self, unification_protocol_name, attribute_identifier, field_values, attribute_restrictions=[], restrict_to_user_entity_ids_list=[])
Gets a list of user entities
source code
 
get_user_entity_relations(self, unification_protocol_name, userEntityID_list, attribute_restrictions=[], negative_attribute_restrictions=[], listRelationType=[], dictRelationAttributeRestriction={}, use_self_relations=True, limit_to_userEntityID_list=False, use_nested_relations=True) source code
 
get_user_entity_relations_by_sharing_attributes(self, unification_protocol_name, userEntityID_list, listAttributes, limit_to_userEntityID_list=False, attribute_restrictions=[], negative_attribute_restrictions=[], ontology_expansion_level=None)
Returns a list of relations between user entities, in which the share attributes listed in listAttributes
source code
 
get_user_entity_type(self, unification_protocol_name, user_entity_ids)
Gets types associated with given user entity ids from database
source code
 
get_valid_external_entity_relation_types(self) source code
 
get_valid_external_entity_types(self) source code
 
insert_alignment(self, alignmentObject, externalEntityID, insert_aligned='no')
"insert_aligned" is used to insert exactly the aligned sequence (used in done alignments, as HSSP, as the sequences does not always is exactly the same...
source code
 
insert_cd_hit_clusters_to_biana_database(self, cd_hit_clusters_file)
Inserts information about CD-HIT clusters into database
source code
 
insert_new_attribute_description(self, attribute_identifier, field_values)
"attribute_identifier" must be an accepted one
source code
 
insert_new_external_database(self, externalDatabase)
Inserts into database the information of a new external database that is being integrated into BIANA database
source code
 
insert_new_external_entity(self, externalEntity)
Inserts a new external entity to the biana database
source code
 
insert_ontology(self, ontology)
Inserts to the database the complete ontology object
source code
 
insert_pdb_object(self, PDBObject, source_database, description=None) source code
 
isOptimizedForRunning(self) source code
 
load_hssp_alignment(self, pdb_id, chain, fragments=[], get_species=False)
Returns an alignment for an structure given in the hssp
source code
 
load_hssp_multiple_chains(self, pdb_id, fragments=[], get_species=False) source code
 
load_pdb_object(self, pdb_code, fragments=[], merge_fragments=False, request_information=None)
"pdb_code" is mandatory
source code
 
optimize_database_for(self, mode, optimize=False)
Performs some modifications in database in order to optimize database access efficiency for parsing or running
source code
 
output_sequences(self, outmethod, type='proteinsequence', format='fasta', sequenceIDs=None)
outmethod: destination where data in fasta format would be written type: either "proteinsequence" or "nucleotidesequence" - decides which type of sequence is desired format: either "fasta" or "seq" corresponding to fasta format or raw sequence format sequenceIDs: list of sequence ids whose sequence would be outputted - if None will output all sequences in the database
source code
 
reconnect(self) source code
 
refresh_database_information(self) source code
 
transform_expanded_attribute_restrictions(self, attribute_restriction_list) source code
 
update_external_database_external_entity_attributes(self, externalDatabase) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, dbname=None, dbhost=None, dbuser=None, dbpassword=None, dbport=None, dbsocket=None, use_buffer=False, lock_tables=False, check_integrity=False)
(Constructor)

source code 

"dbname" is the database name to which you want to connect to (required) "dbhost" is the machine with the mysql server that holds the biana database (required) "dbuser" is the mysql user (not required in most systems) "dbpassword" is the mysql password (not required in most systems) "dbport" is the mysql port (not required in most systems)

The following parameters should not be used by standard users, only for advanced users or developers: "use_buffer" must be set True when populating database due to performance issues. Automatically controlled by parsers "lock_tables" Allow Connector db to lock tables when using them. It is set to True when populating database due to performance issues "check_integrity" determines if integrity of the database must be checked (if there is any parser not finished or if some table definitions have been changed)

Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

_add_key_attribute(self, external_database_id, key_attribute)

source code 

Adds a key attribute, used in transfer attributes (key attribute) and ontologies (linked attribute)

Creates the necessary tables

_get_externalDatabaseID_int(self, sourceDBName, sourceDBVersion)

source code 

Returns the decimal value assigned to the sourceDB (externalDatabaseID will be converted to lower_case)

If "sourceDBVersion" is None, it returns a list with the all the identifiers assigned to the sourceDBName

_get_nested_queries_for_getting_equivalent_uE_by_sharing_attributes(self, unification_protocol_name, attribute_list, user_entity_ids_list, restrict_to_user_entity_ids_list=True, ontology_levels={})

source code 

Returns a string with a sql query. The sql query returns 2 columns: userEntityID1 and userEntityID2, because they share the combination of attributes in the attribute_list

_get_similar_sequences(self, sequenceID, bit_score=None, identity_percent=None, similarity_percent=None, query_coverage_percent=None, match_coverage_percent=None)

source code 

Gets similar sequences from database

In order to be able to run this method, is mandatory to fill before the table of blast or psi-blast results

All specified conditions are evaluated jointly, with AND

TO CHECK!!! The indices are optimized only for identity and coverage!!!

returns a list of sequenceIDs from similar sequences according to the requeriments.

_get_valid_source_dbs(self)

source code 

Returns a dictionary with current external databases stored in BIANA database

Database objects are accessed by its name and version

_load_biana_database_information(self)

source code 

Method to load biana database information into this class

It loads information about the database description, its optimization status, special attributes and special attributes

It is used when initializing a BianaDBaccess object

_load_sequences(self, sequenceIdList, type='proteinsequence')

source code 

Gets multiple sequence object from BIANA database

"sequenceID" can be a single id or a id list

"type" can be "protein" or "nucleotide"

_update_bianaDB_autoincrement_fields(self)

source code 

Method used internally to control biana autoincrement fields. Called by _update_bianaDB_version since updation of autoincrement fields is required before updating version stable ids.

_update_bianaDB_version(self)

source code 

Method used internally to control biana version to be able to control compatibilities between diffent database versions

It also stores the stable values for the database

add_hssp_info_to_pdb(self, pdb_code, chain, residue_pdb_number, residue_hssp_entropy, residue_hssp_norm_entropy, residue_hssp_variability, conservation_hssp, solvent_exposure_hssp, dssp)

source code 

Adds HSSP information to pdb files

If the PDB information does not exist, inserts the data

close(self)

source code 

Close the connection with database

Although it is only necessary to close the BianaDBaccess object when parsing, is highly recommended to use it always as maybe in the future this requirite may change

create_database(self, dbname, description='BIANA DATABASE', optimize_for='parsing', ignore_primary_keys=False)

source code 

It creates necessary tables into a database server

"description" is a tag for label the new database

"optimize_for" can take two distinct values: "parsing" and "running". By default, it creates a database optimized for parsing (as it will be created empty).

drop_unification_protocol(self, unification_protocol_name)

source code 

Drops from the database all the information of a protocol of unification

"protocol_description" corresponds to the description of the protocol to drop

get_expanded_entity_relations(self, unification_protocol_name, userEntityID_list, expansionAttributesList=[], listRelationType=[], use_self_relations=True, limit_to_userEntityID_list=False, expansionLevel=2, attribute_restrictions=[], negative_attribute_restrictions=[])

source code 

unification_protocol_name: name of the unification protocol to be used

userEntityID_list: user entity ids to be searched for relations based on the shared attributes

expansionAttributesList: list of lists containing (attribute, list_of_parameters_and_values) where list_of_parameter_and_values contains tuples like (parameter, value). Each tuple in the inner list is an expansion criterion (anded with the other expansion criteria in the inner list whereas all inner lists are ored in the query). List contains all the attributes that must be used together for the expansion.

listRelationType: type of relations between attribute sharing entry and its partners to be inferred

use_self_relations: including self relations or not

limit_to_userEntityID_list: use given user entity ids only in inference # TODO!!! NOT USED NOW.

expansionLevel: number of relations (edges) to look further during inference based on shared attributes

attribute_restrictions: restrictions to be applied on the attributes # TODO!!!! NOT USED NOW.

get_external_entities_dict(self, externalEntityIdsList, attribute_list=[], relation_attribute_list=[], participant_attribute_list=[], useTransferAttributes=True)

source code 

Returns a dict of external Entity Objects with the attributes specified in the "attribute_identifier_list"

The key in the dictionary corresponds to the external Entity ID

The external entity can be of any type (included relations)

"attribute_field_restrictions" is to restrict the attributes by additional fields. Sintaxis: [(attribute_identifier, field, value)]

get_list_user_entities_IDs_by_attribute(self, unification_protocol_name, attribute_identifier, field_values, attribute_restrictions=None, negative_attribute_restrictions=None, restrict_to_user_entity_ids_list=[], include_type=False)

source code 

Returns a list of user entities that match with the attributes specified of type attribute_identifier

If include_type is set to True, it returns a list of tuples

get_unification_protocol_atoms(self, unification_protocol_name)

source code 

Fetchs from the database all the atom information of a protocol of unification

"unification_protocol_name" corresponds to the description of the protocol

get_user_entity_attributes(self, unification_protocol_name, listUserEntityID, attribute_identifier)

source code 

Returns a dictionary with { userEntityID: list of attributes }

This method is intended to be faster for getting user entity attributes than getting external entity objects and its attribute objects

Numerical values are stored as strings!!!

get_user_entity_id_and_type_tuple_list(self, unification_protocol_name, attribute_identifier, field_values, attribute_restrictions=[], restrict_to_user_entity_ids_list=[])

source code 

Gets a list of user entities

It returns a set with user entities objects

"attribute_restrictions" must be a list of (attribute_identifier, value)

#! Obselete: Not used by any method

get_user_entity_relations_by_sharing_attributes(self, unification_protocol_name, userEntityID_list, listAttributes, limit_to_userEntityID_list=False, attribute_restrictions=[], negative_attribute_restrictions=[], ontology_expansion_level=None)

source code 

Returns a list of relations between user entities, in which the share attributes listed in listAttributes

"listAttributes" is a list of lists of external entity attributes. Each sublist is a "sharing" restriction

"expand_ontology_attributes": Boolean to specify if ontology attributes should be expanded to lower levels

"ontology_expansion_level": Dictionary to specigy the category level to which should be considered equivalent two ontology attributes (for example, family level in scop)

get_user_entity_type(self, unification_protocol_name, user_entity_ids)

source code 

Gets types associated with given user entity ids from database

Returns a dictionary of user entity id and type

insert_alignment(self, alignmentObject, externalEntityID, insert_aligned='no')

source code 

"insert_aligned" is used to insert exactly the aligned sequence (used in done alignments, as HSSP, as the sequences does not always is exactly the same
                 In this case, the fragments are not inserted

insert_new_attribute_description(self, attribute_identifier, field_values)

source code 

"attribute_identifier" must be an accepted one

"field_values" must be a dictionary with the keys (accepted ones) and its values

insert_new_external_entity(self, externalEntity)

source code 

Inserts a new external entity to the biana database

If the externalEntity has been previously inserted in the database, it will show a message advertising about this. It won't insert the attributes, as an external entity can be inserted only once!

It is required to use this method once by each externalEntity.

insert_ontology(self, ontology)

source code 

Inserts to the database the complete ontology object

The external entities of the ontology must be inserted previously

load_hssp_alignment(self, pdb_id, chain, fragments=[], get_species=False)

source code 

Returns an alignment for an structure given in the hssp

For the moment, all the fragments must belong to the same chain

load_pdb_object(self, pdb_code, fragments=[], merge_fragments=False, request_information=None)

source code 

"pdb_code" is mandatory

"fragments" is a list of pdb fragments.

"merge_fragments" is used to merge all fragments or chains as a single chain or to mantain each chain as a different chain. If it is used, atom numbers and residue numbers are changed

"request_information" indicates which information has to be loaded. It is a list. It can be: It can be: "residue_type","atoms_info","hssp_conservation","hssp_entropy","hssp_exposure","hssp_norm_entropy","hssp_variability","dssp"

optimize_database_for(self, mode, optimize=False)

source code 

Performs some modifications in database in order to optimize database access efficiency for parsing or running

"mode" can take two different values: "running" or "parsing"

"optimize" parameter will be only used if mode is "running"