예제 #1
0
    def create_biana_database(dbname,dbhost,dbuser,dbpassword,description,dbport=None):
        """
        Creates the BIANA database in the mysql server

        "dbname": Desired database name. It must not exist a database with the same name in the same database server (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)

        In order to make parsers faster, it creates tables without indices and addicional checkings. Biana automatically enable indices when necessary. If user wants to enable indices manually, it is necessary to use the method "enable_indices"
        """

        OutBianaInterface.send_process_message("Creating new biana database...")

        import BianaDB

        try:
            dbaccess = BianaDB.BianaDBaccess( dbhost = dbhost,
                                              dbuser = dbuser,
                                              dbpassword = dbpassword,
                                              dbport = dbport )
            databases_list = dbaccess.db.select_db_content( sql_query = "SHOW DATABASES", answer_mode = "list" )

            if dbname in databases_list:
                OutBianaInterface.send_error_notification("ERROR: Duplicated database name %s at %s" %(dbname, dbhost), "Database %s exists at %s. If it is a biana database, import it by using the \"Add existing database\" option" %(dbname, dbhost) )

            else:
                dbaccess.db.insert_db_content( sql_query = "CREATE DATABASE IF NOT EXISTS %s DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci" %dbname )
                dbaccess.db.insert_db_content( sql_query = "USE %s" %dbname )
                dbaccess.create_database(description=description,ignore_primary_keys=True,dbname=dbname)
                dbaccess.close()
                administration.check_database(dbname,dbhost,dbuser,dbpassword,dbport)
                OutBianaInterface.send_info_message("BIANA Database correctly created. You can start now populating it using \"Parse external databases\" option")

        except:
            OutBianaInterface.send_error_notification("Error while creating database %s at %s" %(dbname, dbhost), traceback.format_exc())

        OutBianaInterface.send_end_process_message()
예제 #2
0
    def create_unification_protocol(unification_protocol_name,
                                    list_unification_atom_elements,
                                    dbname,
                                    dbhost,
                                    dbuser,
                                    dbpassword,
                                    dbport=None,
                                    unify_self=True):
        """
        Creates a new unification protocol
        
        "unification_protocol_name" is the name of the unification protocol (it can be a string). It cannot contain blank spaces. It must be unique (required)
        
        "listUnifiationAtomElements" is a list of tuples. Each tuple consists on two elements: the list of database to cross and the list of attributes as for example [([1,2],["uniprotAccession"]),([1],["geneSymbol"])]
        
        "dbname": Biana database name
        
        "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)

        "unify_self" Unify the external entities in one database with themselves (default = True)
        """

        import BianaDB, BianaObjects

        OutBianaInterface.send_process_message(
            "Creating unification protocol. This process can take long time.")

        try:

            # create a temporal session to make all database checkings

            import BianaObjects.BianaSessionManager as BianaSessionManager

            import tempfile

            tfile = tempfile.TemporaryFile('w', bufsize=10000)
            temp_session = BianaSessionManager.BianaSessionManager(
                pSessionID="temp_session",
                unification_protocol_name="No unification",
                dbname=dbname,
                dbhost=dbhost,
                dbuser=dbuser,
                dbport=dbport,
                dbpassword=dbpassword,
                out_method=tfile.write)

            tfile.close()

            temp_session.close()
            del temp_session

            # Commented because it generated an error in the GUI, as we only allow a session. If a session was started when creating a unification protocol, it generated some conflicts
            #create_new_session("temp_session", dbname,dbhost,dbuser,dbpassword,unification_protocol="No unification",dbport=None)

            dbaccess = BianaDB.BianaDBaccess(dbname=dbname,
                                             dbhost=dbhost,
                                             dbuser=dbuser,
                                             dbpassword=dbpassword,
                                             dbport=dbport)

            uProtocol = BianaObjects.UnificationProtocol(
                unification_protocol_name,
                "x")  #in X should go the biana database version

            for db_ids, attr_list in list_unification_atom_elements:
                # Add all databases, for adding those databases that are not unified with anything else
                for current_db in db_ids:
                    uProtocol.add_database(current_db)

                if len(attr_list) > 0:
                    for current_db1_pos in xrange(len(db_ids)):
                        k = current_db1_pos
                        if unify_self:
                            k += 1
                        for current_db2_pos in xrange(k):
                            #for current_db2_pos in xrange(current_db1_pos): # before was not unifying the database with itself (emre)
                            uProtocol.add_unification_atom_elements(
                                BianaObjects.UnificationAtomElement(
                                    externalDatabaseID_A=db_ids[
                                        current_db1_pos],
                                    externalDatabaseID_B=db_ids[
                                        current_db2_pos],
                                    externalAttribute=attr_list))
            dbaccess.create_new_user_entities(uProtocol)

            OutBianaInterface.send_info_message(
                "New unification protocol successfully created. You can start a working session with it by using \"Create session\" option and selecting database and unification protocol."
            )

            #OutBianaInterface.send_data(uProtocol.get_xml()) # TO CHECK WHY IS IT COMMENTED

            dbaccess.close()
        except:
            OutBianaInterface.send_error_notification(
                "Error while creating unification protocol",
                traceback.format_exc())

        OutBianaInterface.send_end_process_message()

        return
예제 #3
0
    def create_unification_protocol(unification_protocol_name, list_unification_atom_elements, dbname,dbhost,dbuser,dbpassword,dbport=None):
        """
        Creates a new unification protocol
        
        "unification_protocol_name" is the name of the unification protocol (it can be a string). It cannot contain blank spaces. It must be unique (required)
        
        "listUnifiationAtomElements" is a list of tuples. Each tuple consists on two elements: the list of database to cross and the list of attributes as for example [([1,2],["uniprotAccession"]),([1],["geneSymbol"])]
        
        "dbname": Biana database name
        
        "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)
        """

        import BianaDB, BianaObjects

        OutBianaInterface.send_process_message("Creating unification protocol. This process can take long time.")

        try:

            # create a temporal session to make all database checkings
            
            import BianaObjects.BianaSessionManager as BianaSessionManager

            import tempfile

            tfile = tempfile.TemporaryFile('w', bufsize=10000)
            temp_session = BianaSessionManager.BianaSessionManager( pSessionID = "temp_session",
                                                                    unification_protocol_name = "No unification",
                                                                    dbname = dbname,
                                                                    dbhost = dbhost,
                                                                    dbuser = dbuser,
                                                                    dbport = dbport,
                                                                    dbpassword = dbpassword,
                                                                    out_method = tfile.write )

            tfile.close()

            temp_session.close()
            del temp_session

            # Commented because it generated an error in the GUI, as we only allow a session. If a session was started when creating a unification protocol, it generated some conflicts
            #create_new_session("temp_session", dbname,dbhost,dbuser,dbpassword,unification_protocol="No unification",dbport=None)

            dbaccess = BianaDB.BianaDBaccess( dbname = dbname,
                                              dbhost = dbhost,
                                              dbuser = dbuser,
                                              dbpassword = dbpassword,
                                              dbport = dbport )

            uProtocol = BianaObjects.UnificationProtocol(unification_protocol_name, "x")  #in X should go the biana database version

            for db_ids, attr_list in list_unification_atom_elements:
                # Add all databases, for adding those databases that are not unified with anything else
                for current_db in db_ids:
                    uProtocol.add_database(current_db)

                if len(attr_list)>0:
                    for current_db1_pos in xrange(len(db_ids)):
                        for current_db2_pos in xrange(current_db1_pos+1): 
                        #for current_db2_pos in xrange(current_db1_pos): # before was not unifying the database with itself (emre)
			    uProtocol.add_unification_atom_elements( BianaObjects.UnificationAtomElement(externalDatabaseID_A=db_ids[current_db1_pos],
                                                                                                         externalDatabaseID_B=db_ids[current_db2_pos],
                                                                                                         externalAttribute=attr_list) )        
            dbaccess.create_new_user_entities(uProtocol)

            OutBianaInterface.send_info_message("New unification protocol successfully created. You can start a working session with it by using \"Create session\" option and selecting database and unification protocol.")

            #OutBianaInterface.send_data(uProtocol.get_xml()) # TO CHECK WHY IS IT COMMENTED

            dbaccess.close()
        except:
            OutBianaInterface.send_error_notification("Error while creating unification protocol",traceback.format_exc())

        OutBianaInterface.send_end_process_message()

        return