PianaGraphBuilder
index
../../../../piana/code/Graph/PianaGraph/PianaGraphBuilder.py

File       : PianaGraphBuilder.py
Author     : R. Aragues & D. Jaeggi
Creation   : 31.07.2003
Contents   : class for building a piana graph from a database
Called from: PianaGraph and piana.py
Comments :
=========================================================================
 
This class is used to populate a PianaGraph object with interactions and proteins from a piana database

 
Modules
       
Bio
MySQLdb
PianaGlobals
copy
os
re
sys
time
utilities

 
Classes
       
GraphBuilder.GraphBuilder
PianaGraphBuilder

 
class PianaGraphBuilder(GraphBuilder.GraphBuilder)
    Class that implements graph building methods specific to Piana
 
  Methods defined here:
__init__(self, piana_access_object, depth=0, hub_threshold=0, use_self_ints='yes', list_protein_codes=None, id_type=None, tax_id_value=0, list_source_dbs='all', inverse_dbs='no', list_source_methods='all', inverse_methods='no', use_secondary_db='no', piana_secondary_access_object=None, force_secondary_db='no')
Initilisation operations specific to Piana: mainly finding out the internal id (ie proteinPiana) for
protein given as argument, and then calling the general __init__ of superclass GraphBuilder
 
"depth" valid values are described in superclass GraphBuilder. It refers to the depth the graph should have.
 
"list_protein_codes" are protein identifiers of id_type . These protein codes will be used to build the graph. All codes must be
of the same type (e.g swissprot)
 
"id_type" is an easy-to-remember  protein type name: establishes the type of protein identifiers that are being passed as argument.
 
   It is used to retrieve the internal proteinPiana from the database, which is as well the identifier used for node_ids of the graph. 
   Valid id_type are those defined in PianaGlobals.py. There is a direct correspondance between these types and the
   column names in the database
 
   valid "id_type" values are those described in the PIANA reference card (read README.piana_tutorial)
 
 
 
"use_self_ints" is used to avoid adding self interactions in the network
              -> 'yes' adds all interactions
              -> 'no' doesn't add interactions between a protein and itself
 
              
"tax_id_value" can be used to fix the species we want to work on: only proteinPianas from that species will be used to build the graph
(this doesn't mean that 'a posteriori' added proteins will be limited as well to that species... it only concerns proteins in list_protein_codes)
If the database has an interaction between a protein of this species and a protein of another species, both proteins will appear in the network
regardless of this paramter: to control which proteins appear in your output you should use output-species-name in your piana configuration file
 
     --> valid values are 0 or a taxonomy id as defined by NCBI taxonomy
            - 0: retrieves all proteinPianas for protein_codes, regardless of species
 
"list_source_dbs" can be used to set which interaction databases will be used to build the network: only interactions from databases in the list
will be added to the network
 
  -> "list_source_dbs" can be "all" or a list of interactions databases
 
   - "all": uses all interactions in the piana database
   - [db1, db2, ...]: uses only interactions from databases listed (for example, [dip, string, posas]
      -> valid database names are those defined in PianaGlobals.interaction_databases
 
"inverse_dbs" can be:
               no (databases in list_source_dbs will be used to build the network)
               yes (all databases except those in list_source_dbs will be used to build the network)
               
 
 "list_source_methods" can be used to set which interaction detection methods will be used to build the network: only interactions
 that were detected through methods in the list will be added to the network
 
  -> "list_source_methods" can be "all" or a list of interactions methods
 
   - "all": uses all interaction detection methods in the piana database
   - [method1, method2, ...]: uses only interactions from methods listed (for example, [y2h, immuno]
      -> valid method names are those defined in PianaGlobals.method_names
 
"inverse_methods" can be:
               no (methods in list_source_methods will be used to build the network)
               yes (all methods except those in list_source_methods will be used to build the network)
build_graph(self, complete_taxID=None)
This is the specific building method for PianaGraphBuilder. If the graph is generated from a list of seed (root) nodes
it calls the generic build_graph method. Otherwise, if complete specie is selected, it will construct the complete network
for a specific specie
 
"complete_taxID" has only to be introduced when a complete network for a specie must be builded
check_all_ppis_empty(self)
Check if the internal buffer (all ppis dictionary) is empty or not
 
Returns None if it is empty. Otherwise, return the dictionary
create_node_attribute(self, node_id)
Overrides method from GraphBuilder
 
returns a PianaGraphNodeAttribute for node_id
empty_edges_buffer(self)
get_all_interactions_for_taxID(self, taxID, mem_mode='onDemand')
returns a list of all protein-protein interactions (proteinPiana,proteinPianaB,interactionPiana) for "taxID" and restrictions
get_link_details(self, node_id, use_ppi_memory='no', mem_mode='onDemand')
Overrides method from GraphBuilder: this method specifies how specific nodes and edges look like in PianaGraph
 
Before calling this method we are only dealing with node_id. get_links will create the node objects from node_id and return
linkDetail objects (container for two node_id, one edge and attributes of all of them). This linkDetails objects are specific
to PianaGraph, but can be used by GraphBuilder without knowing their internal structure.
 
This method uses self.list_source_dbs to limit the interactions found to those that were retrieved from databases that appear
in the list of databases given by the user when initializing the builder
 
This method uses self.list_source_methods to limit the interactions found to those that were found with methods that appear
in the list of methods given by the user when initializing the builder
 
returns empty list if no link_details are found or number of links is higher than hub_threshold
get_link_details_two_nodes(self, node_id1, node_id2, use_ppi_memory='no')
Overrides method from GraphBuilder: this method return a LinkDetail object between nodes "node_id1" and "node_id2"
 
"use_ppi_memory" if this method has to be used repeatedly, it is much faster to store all protein-protein interactions in memory
                 and check them here than to find them in database each time
                 "yes" load all interactions in memory (only first time) and then use them
                 "no" use database connection

Methods inherited from GraphBuilder.GraphBuilder:
build_graph_by_levels(self)
The main graph building method, building the graph by levels. This is called by Graph.build_graph()
 
Other difference with build_graph is that it will always go until depth+1, in order to check for interactions inner the last level, but
new nodes found in depth+1 will not be added to the graph (hub threshold will not be taken into account)
set_graph(self, graph_object)
Sets the graph to be built - this is called by Graph.build_graph()

Data and other attributes inherited from GraphBuilder.GraphBuilder:
LinkDetail = <class GraphBuilder.LinkDetail>
Internal class for storing and transmitting link details.
A LinkDetail must be composed of 2 nodes as a minimum.
Each node can have one attribute.
The link can also have any number of attributes.

 
Data
        verbose = 0
verbose_build = 0
verbose_build_shallow = 0
verbose_build_very_shallow = 0
verbose_get_all_links = 0
verbose_has_edge = 0
verbose_insert_interaction = 0
verbose_species = 0