def get_ontology(): from biana.biana_commands import available_sessions, create_new_session # Create a new BIANA session create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=DEFAULT_UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] ontology = objSession.get_ontology(ontology_name="psimiobo", root_attribute_values = [4]) print map(int, ontology.get_all_linked_attributes()) ontology = objSession.dbAccess.get_ontology(ontology_name="psimiobo", root_attribute_values = [45], load_external_entities=True) #ontology = objSession.dbAccess.get_ontology(ontology_name="psimiobo", root_attribute_values = [59, 109, 63], load_external_entities=True) print map(lambda x: (int(x[0]), x[1]), ontology.get_linked_attr_and_description_tuples()) return
def get_human_interactome(include_string=False): from biana.biana_commands import available_sessions, create_new_session identifier_description_list = [("taxid", "9606")] relation_type_list = ["interaction"] #,"reaction"] # ["interaction","reaction","complex","pathway"] level = 0 # Create a new BIANA session create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") uESet1 = objSession.get_user_entity_set("User_Entity_Set_1") print "# of nodes: ", uESet1.getSize() if include_string: # Duplicate the User Entity Set (group of biomolecules) in this session uESet2 = objSession.duplicate_user_entity_set(user_entity_set_id="User_Entity_Set_1", new_user_entity_set_id="User_Entity_Set_2") # Fetch relations (except STRING) of biomolecules in 1st set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[], include_relations_last_level=True, use_self_relations=True) print "# of experimental edges: ", uESet1.getNumberEdges() # Fetch relations (only STRING with scores > 700) of biomolecules in 2nd set relation_type_list = ["functional_association"] #objSession.create_network( user_entity_set_id = "User_Entity_Set_2" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[("stringscore",">700")], include_relations_last_level=True, use_self_relations=True) objSession.create_network( user_entity_set_id = "User_Entity_Set_2" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[], include_relations_last_level=True, use_self_relations=True) print "# of string edges: ", uESet2.getNumberEdges() uESet3 = objSession.get_union_of_user_entity_set_list(user_entity_set_list=["User_Entity_Set_1", "User_Entity_Set_2"], include_relations=True, new_user_entity_set_id="User_Entity_Set_3") objSession.remove_user_entity_set(user_entity_set_id="User_Entity_Set_1") objSession.remove_user_entity_set(user_entity_set_id="User_Entity_Set_2") # Export all the information of this set and its network to a file in a tab separated format #objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_3", out_method=open("network.out", "w").write, node_attributes = ["uniprotaccession"], participant_attributes = [], relation_attributes=["stringscore"], include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", include_participant_tags=False, include_relation_tags=False) objSession.output_user_entity_set_network_in_sif_format(user_entity_set_id = "User_Entity_Set_3", output_path = "./", output_prefix = "human_with_string", node_attributes = [], participant_attributes = [], relation_attributes=["pubmed", "method_id","stringscore"], output_1_value_per_attribute=False, include_tags=False) else: # Fetch relations (except STRING) of biomolecules in 1st set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[], include_relations_last_level=True, use_self_relations=True) print "# of experimental edges: ", uESet1.getNumberEdges() # Output set details - all nodes objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open("human_nodes.tsv", "w").write, attributes=["uniprotaccession", "geneid", "ensembl", "genesymbol", "go", "hgnc", "disease", "proteinsequence"], include_level_info=False, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False) # Export sequences of entries in this set as a FASTA file #objSession.output_user_entity_set_sequences_in_fasta(user_entity_set_id="User_Entity_Set_1", only_selected = False, out_method=open("human_fasta.txt",'w').write, type="proteinsequence") #, attributes=["uniprotaccession"]) # Export all the information of this set and its network to a file in a tab separated format objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method=open("human_network.out", "w").write, node_attributes = ["uniprotaccession"], participant_attributes = [], relation_attributes=[], include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", include_participant_tags=False, include_relation_tags=False) objSession.output_user_entity_set_network_in_sif_format(user_entity_set_id = "User_Entity_Set_1", output_path = "./", output_prefix = "human", node_attributes = [], participant_attributes = [], relation_attributes=["pubmed", "method_id"], output_1_value_per_attribute=False, include_tags=False) return
def select_and_create_subset_from_set(): from biana.biana_commands import administration, available_sessions, create_new_session from biana.BianaObjects import BianaSessionManager import sets identifier_description_list = [("genesymbol", "rad2"), ("genesymbol", "rad1")] identifier_description_list2 = [("genesymbol", "rad1")] relation_type_list = ["interaction"] # Create a new BIANA session objSession = create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list = identifier_description_list, external_entity_attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") # Create another User Entity Set (group of biomolecules) in this session uESet2 = objSession.create_new_user_entity_set( identifier_description_list = identifier_description_list2, external_entity_attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_2") # Select all User Entities in the second User Entity Set user_entities_to_select = uESet2.get_user_entity_ids() objSession.select_user_entities_from_user_entity_set("User_Entity_Set_1", user_entities_to_select, clear_previous_selection=True) # Create a new User Entity Set from selected User Entities in the first User Entity Set objSession.get_sub_user_entity_set(user_entity_set_id = "User_Entity_Set_1", include_relations=False, new_user_entity_set_id="User_Entity_Set_3") # Output set details objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_3", out_method = open("nodes.out", "w").write, attributes=["genesymbol", "uniprotaccession", "hgnc"], include_level_info=True, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=True, output_1_value_per_attribute=False, include_command_in_rows=False)
def duplicate_and_randomize_network(): from biana.biana_commands import create_new_session, administration, available_sessions from biana.BianaObjects import BianaSessionManager import sets identifier_description_list = [("genesymbol", "rad2")] identifier_description_list2 = [("genesymbol", "rad1")] relation_type_list = ["interaction"] # Create a new BIANA session objSession = create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list = identifier_description_list, external_entity_attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") # Get relations of biomolecules in this set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = 1, relation_type_list= relation_type_list, include_relations_last_level = False, use_self_relations = False) # Duplicate (could be used to keep a copy before randomization) the User Entity Set (group of biomolecules) in this session uESet2 = objSession.duplicate_user_entity_set(user_entity_set_id="User_Entity_Set_1", new_user_entity_set_id="User_Entity_Set_2") # Randomize the network of the User Entity Set based on the given randomization type objSession.randomize_user_entity_set_network(user_entity_set_id="User_Entity_Set_1", type_randomization="random") # Output network details objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes = ["uniprotaccession"], participant_attributes = [], relation_attributes=[], allowed_relation_types="all", include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", only_selected=True, substitute_node_attribute_if_not_exists=False)
def create_session(): from biana.biana_commands import available_sessions, create_new_session # Create a new BIANA session t1 = clock() create_new_session(sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=DEFAULT_UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] t2 = clock() print "Time: ", t2 - t1 return
def get_seed_connected_nodes(): from biana.biana_commands import administration, available_sessions, create_new_session from biana.BianaObjects import BianaSessionManager import sets import biana.utilities.identifier_utilities as id_utils t_init = time.clock() relation_type_list = ["interaction"] # ["reaction","complex","pathway","interaction"] # Create a new BIANA session create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] #identifier_description_list = id_utils.read_identifier_list_from_file("/home/emre/arastirma/colloboration/seeds_intracranial_and_aneurysm_and_mesh_genetics.txt", "genesymbol") identifier_description_list = id_utils.read_identifier_list_from_file("/home/emre/arastirma/colloboration/subarachnoid_and_hemorrhage_or_haemorrhage_and_mesh_genetics.seeds", "genesymbol") # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list = identifier_description_list, external_entity_attribute_restriction_list=[("taxid","9606")], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") t_1 = time.clock() # Get relations of biomolecules in this set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = 1, relation_type_list= relation_type_list, include_relations_last_level = False, use_self_relations = False) t_2 = time.clock() print "t_network:", t_2-t_1 # Select seeds and nodes connected by seeds in the network of this User Entity Set user_entities_to_print = sets.Set(uESet1.get_user_entity_ids(level=0))|uESet1.get_user_entity_ids_by_linker_degree_cutoff(2) objSession.select_user_entities_from_user_entity_set("User_Entity_Set_1", user_entities_to_print, clear_previous_selection=True) objSession.tag_selected_user_entities(user_entity_set_id="User_Entity_Set_1", tag="seed+connected") t_3 = time.clock() print "t_connected:", t_3-t_2 # Output set details - only selected nodes #objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open("nodes_selected.out", "w").write, attributes=["genesymbol", "uniprotaccession", "hgnc"], include_level_info=True, include_degree_info=True, level=None, only_selected=True, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=True, output_1_value_per_attribute=False, include_command_in_rows=False) # Output set details - all nodes objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open("nodes.out", "w").write, attributes=["genesymbol", "uniprotaccession", "hgnc"], include_level_info=True, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=True, output_1_value_per_attribute=False, include_command_in_rows=False) t_4 = time.clock() print "t_nodes:", t_4-t_3 # Output network details objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes = [], participant_attributes = [], relation_attributes=["Method_id"], allowed_relation_types="all", include_relation_ids=False, include_participant_ids=True, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", only_selected=False, substitute_node_attribute_if_not_exists=True, include_participant_tags=False, include_relation_tags = False, include_unconnected_nodes=False) t_5 = time.clock() print "t_network:", t_5-t_4
def create_session(): from biana.biana_commands import available_sessions, create_new_session # Create a new BIANA session t1 = clock() create_new_session( sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=DEFAULT_UNIFICATION_PROTOCOL, ) objSession = available_sessions["biana_session"] t2 = clock() print "Time: ", t2 - t1 return
def get_intersection_of_3_set(): from biana.biana_commands import administration, available_sessions, create_new_session from biana.BianaObjects import BianaSessionManager import biana.utilities.identifier_utilities as id_utils create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] objSession.create_new_user_entity_set( identifier_description_list = id_utils.read_identifier_list_from_file(BONE_FILE, id_type="uniprotaccession"), external_entity_attribute_restriction_list=[("taxid","9606")], id_type="embedded",new_user_entity_set_id="bone") objSession.create_new_user_entity_set( identifier_description_list = id_utils.read_identifier_list_from_file(LIVER_FILE, id_type="uniprotaccession"), external_entity_attribute_restriction_list=[("taxid","9606")], id_type="embedded",new_user_entity_set_id="liver") objSession.create_new_user_entity_set( identifier_description_list = id_utils.read_identifier_list_from_file(LUNG_FILE, id_type="uniprotaccession"), external_entity_attribute_restriction_list=[("taxid","9606")], id_type="embedded",new_user_entity_set_id="lung") print "Bone - Liver - Lung User Entity Sets are created..", objSession objSession.create_network( user_entity_set_id = "bone" , level = 1 , relation_type_list=["complex","interaction","pathway","reaction"] , include_relations_last_level = True , use_self_relations = False) objSession.create_network( user_entity_set_id = "liver" , level = 1 , relation_type_list=["complex","interaction","pathway","reaction"] , include_relations_last_level = True , use_self_relations = False) objSession.create_network( user_entity_set_id = "lung" , level = 1 , relation_type_list=["complex","interaction","pathway","reaction"] , include_relations_last_level = True , use_self_relations = False) print "Bone - Liver - Lung Networks are created..", objSession objSession.get_intersection_of_user_entity_set_list([objSession.get_user_entity_set("bone"), objSession.get_user_entity_set("liver"), objSession.get_user_entity_set("lung")], include_relations=True, new_user_entity_set_id="intersection") objSession.get_intersection_of_user_entity_set_list([objSession.get_user_entity_set("bone"), objSession.get_user_entity_set("liver")], include_relations=True, new_user_entity_set_id="bone_liver") objSession.get_intersection_of_user_entity_set_list([objSession.get_user_entity_set("bone"), objSession.get_user_entity_set("lung")], include_relations=True, new_user_entity_set_id="bone_lung") objSession.get_intersection_of_user_entity_set_list([objSession.get_user_entity_set("liver"), objSession.get_user_entity_set("lung")], include_relations=True, new_user_entity_set_id="liver_lung") print "Intersections are created..", objSession return
def create_interactome_using_biana(taxids = [9606], node_file_prefix="human_nodes", network_files_prefix="human_network", network_type="experimental", load_from_saved_session = False): """ Creates ppi specific to an organism network files using BIANA taxids: List of id(s) of taxonomy identifier of the organism(s) whose interactome (and in case of more than one organism) interactions between their interactome) will be created Node file: node_file_prefix.tsv (as tab seperated values) Edge files: network_files_prefix.sif (network in sif format), network_file_prefix_attribute.eda (Cytoscape edge attribute files for each attribute) Network type: "experimental" (type interaction, all ppi db but string) | "functional" (type functional_association, only string) | "all" (experimental + functional) """ from biana.biana_commands import available_sessions, create_new_session, save_session, load_session from biana.BianaObjects import BianaSessionManager #DB_NAME = "test_biana" #DB_HOST = "127.0.0.1" #DB_USER = "******" #DB_PASS = "******" #UNIFICATION_PROTOCOL = "(p2)(noself)(noprevious)uniprot_seqtax_geneid_scoppdb" identifier_description_list = [ ("taxid", taxid) for taxid in taxids ] level = 0 relation_type_list = [] relation_attribute_restriction_list = [] node_attributes=["uniprotaccession", "geneid", "ensembl", "genesymbol", "go", "hgnc", "disease", "proteinsequence"] relation_attributes=["pubmed", "method_id"] if network_type == "functional": relation_type_list = ["functional_association"] relation_attributes.extend(["stringscore", "stringscore_neighborhood", "stringscore_fusion", "stringscore_cooccurence", "stringscore_experimental", "stringscore_db", "stringscore_textmining"]) # Uncommet below for only relations from STRING with score > 700 #relation_attribute_restriction_list=[("stringscore",">700")] elif network_type == "experimental": relation_type_list = ["interaction"] #,"reaction"] # ["interaction","reaction","complex","pathway"] elif network_type == "all": relation_type_list ["interaction", "functional_association"] else: raise ValueError("Unrecognized network_type!") if load_from_saved_session: load_session(network_files_prefix + "_session.dat") objSession = available_sessions["biana_session"] else: # Create a new BIANA session create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") print "# of nodes: ", objSession.get_user_entity_set("User_Entity_Set_1").getSize() # Fetch relations of biomolecules in the set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list = relation_attribute_restriction_list, include_relations_last_level=True, use_self_relations=True) print "# of edges: ", objSession.get_user_entity_set("User_Entity_Set_1").getNumberEdges() # Save the session save_session("biana_session", network_files_prefix + "_session.dat") # Output set details - all nodes objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open(node_file_prefix + ".tsv", "w").write, attributes=node_attributes, include_level_info=False, include_degree_info=False, level=None, only_selected=False, output_format="tabulated", include_tags_info = False, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False, output_only_native_values=False) objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open(node_file_prefix + "_only_native.tsv", "w").write, attributes=["uniprotaccession"], include_level_info=False, include_degree_info=False, level=None, only_selected=False, output_format="tabulated", include_tags_info = False, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False, output_only_native_values=True) # Export all the information of this set and its network to a file in a tab separated format objSession.output_user_entity_set_network_in_sif_format(user_entity_set_id = "User_Entity_Set_1", output_path = "./", output_prefix = network_files_prefix, node_attributes = [], participant_attributes = [], relation_attributes = relation_attributes, output_1_value_per_attribute = False, include_tags = False) ## Export sequences of entries in this set as a FASTA file #objSession.output_user_entity_set_sequences_in_fasta(user_entity_set_id="User_Entity_Set_1", only_selected = False, out_method=open("human_fasta.txt",'w').write, type="proteinsequence") #, attributes=["uniprotaccession"]) ## Export all the information of this set and its network to a file in a tab separated format #available_sessions["biana_session"].output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method = open(network_files_prefix + ".tsv", "w").write, node_attributes = [], participant_attributes = [], relation_attributes = ["method_id"], allowed_relation_types = "all", include_relation_ids = False, include_participant_ids = True, include_relation_type = True, include_relation_sources = True, output_1_value_per_attribute = False, output_format = "tabulated", only_selected = False, substitute_node_attribute_if_not_exists = False, include_participant_tags = False, include_relation_tags = False, include_unconnected_nodes=False) return
def duplicate_and_randomize_network(): from biana.biana_commands import create_new_session, administration, available_sessions from biana.BianaObjects import BianaSessionManager import sets identifier_description_list = [("genesymbol", "rad2")] identifier_description_list2 = [("genesymbol", "rad1")] relation_type_list = ["interaction"] # Create a new BIANA session objSession = create_new_session( sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL, ) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, external_entity_attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1", ) # Get relations of biomolecules in this set objSession.create_network( user_entity_set_id="User_Entity_Set_1", level=1, relation_type_list=relation_type_list, include_relations_last_level=False, use_self_relations=False, ) # Duplicate (could be used to keep a copy before randomization) the User Entity Set (group of biomolecules) in this session uESet2 = objSession.duplicate_user_entity_set( user_entity_set_id="User_Entity_Set_1", new_user_entity_set_id="User_Entity_Set_2" ) # Randomize the network of the User Entity Set based on the given randomization type objSession.randomize_user_entity_set_network(user_entity_set_id="User_Entity_Set_1", type_randomization="random") # Output network details objSession.output_user_entity_set_network( user_entity_set_id="User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes=["uniprotaccession"], participant_attributes=[], relation_attributes=[], allowed_relation_types="all", include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", only_selected=True, substitute_node_attribute_if_not_exists=False, )
def get_intersection_of_3_set(): from biana.biana_commands import administration, available_sessions, create_new_session from biana.BianaObjects import BianaSessionManager import biana.utilities.identifier_utilities as id_utils create_new_session(sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] objSession.create_new_user_entity_set( identifier_description_list=id_utils.read_identifier_list_from_file( BONE_FILE, id_type="uniprotaccession"), external_entity_attribute_restriction_list=[("taxid", "9606")], id_type="embedded", new_user_entity_set_id="bone") objSession.create_new_user_entity_set( identifier_description_list=id_utils.read_identifier_list_from_file( LIVER_FILE, id_type="uniprotaccession"), external_entity_attribute_restriction_list=[("taxid", "9606")], id_type="embedded", new_user_entity_set_id="liver") objSession.create_new_user_entity_set( identifier_description_list=id_utils.read_identifier_list_from_file( LUNG_FILE, id_type="uniprotaccession"), external_entity_attribute_restriction_list=[("taxid", "9606")], id_type="embedded", new_user_entity_set_id="lung") print "Bone - Liver - Lung User Entity Sets are created..", objSession objSession.create_network( user_entity_set_id="bone", level=1, relation_type_list=["complex", "interaction", "pathway", "reaction"], include_relations_last_level=True, use_self_relations=False) objSession.create_network( user_entity_set_id="liver", level=1, relation_type_list=["complex", "interaction", "pathway", "reaction"], include_relations_last_level=True, use_self_relations=False) objSession.create_network( user_entity_set_id="lung", level=1, relation_type_list=["complex", "interaction", "pathway", "reaction"], include_relations_last_level=True, use_self_relations=False) print "Bone - Liver - Lung Networks are created..", objSession objSession.get_intersection_of_user_entity_set_list( [ objSession.get_user_entity_set("bone"), objSession.get_user_entity_set("liver"), objSession.get_user_entity_set("lung") ], include_relations=True, new_user_entity_set_id="intersection") objSession.get_intersection_of_user_entity_set_list( [ objSession.get_user_entity_set("bone"), objSession.get_user_entity_set("liver") ], include_relations=True, new_user_entity_set_id="bone_liver") objSession.get_intersection_of_user_entity_set_list( [ objSession.get_user_entity_set("bone"), objSession.get_user_entity_set("lung") ], include_relations=True, new_user_entity_set_id="bone_lung") objSession.get_intersection_of_user_entity_set_list( [ objSession.get_user_entity_set("liver"), objSession.get_user_entity_set("lung") ], include_relations=True, new_user_entity_set_id="liver_lung") print "Intersections are created..", objSession return
def simple_session(): from biana.biana_commands import administration, available_sessions, create_new_session, save_session, load_session from biana.BianaObjects import BianaSessionManager # Remove comment below to load data from previous session #load_session("/home/user/test.dat") identifier_description_list = [("gi", "1019412") ] #[("disease", "alzheimer")] relation_type_list = ["interaction" ] # ["reaction","complex","pathway","interaction"] # Create a new BIANA session create_new_session(sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") uESet1 = objSession.get_user_entity_set("User_Entity_Set_1") # Export sequences of entries in this set as a FASTA file objSession.output_user_entity_set_sequences_in_fasta( user_entity_set_id="User_Entity_Set_1", only_selected=False, out_method=open("test_fasta.txt", 'w').write, type="proteinsequence", attributes=["uniprotAccession"]) # Instead of exporting the set as a FASTA file, remove comment below to export it as a tab separated file #objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open("nodes.out", "w").write, attributes=["hgnc", "taxid"], include_level_info=True, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False) # Fetch relations of biomolecules in this set objSession.create_network(user_entity_set_id="User_Entity_Set_1", level=1, relation_type_list=relation_type_list, include_relations_last_level=True, use_self_relations=True) # Instead of creating network from existing relations, remove comment below make predictions based on shared attribute #objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = 1 , include_relations_last_level = False , use_self_relations = False , expansion_relation_type_list = ["interaction"] , expansion_attribute_list = [ [("cog", [])] ], expansion_level = 2 ) # Export all the information of this set and its network to a file in a tab separated format objSession.output_user_entity_set_network( user_entity_set_id="User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes=["uniprotaccession"], participant_attributes=[], relation_attributes=[], allowed_relation_types="all", include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", only_selected=False, substitute_node_attribute_if_not_exists=False) #objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes = ["uniprotaccession"], relation_attributes=["psimi_name"], include_relation_sources=True, output_format="tabulated") # Remove comment below to save this session for later use #save_session("biana_session", "/home/user/test.dat") return
def get_seed_connected_nodes(): from biana.biana_commands import administration, available_sessions, create_new_session from biana.BianaObjects import BianaSessionManager import sets import biana.utilities.identifier_utilities as id_utils t_init = time.clock() relation_type_list = ["interaction" ] # ["reaction","complex","pathway","interaction"] # Create a new BIANA session create_new_session(sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] #identifier_description_list = id_utils.read_identifier_list_from_file("/home/emre/arastirma/colloboration/seeds_intracranial_and_aneurysm_and_mesh_genetics.txt", "genesymbol") identifier_description_list = id_utils.read_identifier_list_from_file( "/home/emre/arastirma/colloboration/subarachnoid_and_hemorrhage_or_haemorrhage_and_mesh_genetics.seeds", "genesymbol") # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, external_entity_attribute_restriction_list=[("taxid", "9606")], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") t_1 = time.clock() # Get relations of biomolecules in this set objSession.create_network(user_entity_set_id="User_Entity_Set_1", level=1, relation_type_list=relation_type_list, include_relations_last_level=False, use_self_relations=False) t_2 = time.clock() print "t_network:", t_2 - t_1 # Select seeds and nodes connected by seeds in the network of this User Entity Set user_entities_to_print = sets.Set(uESet1.get_user_entity_ids( level=0)) | uESet1.get_user_entity_ids_by_linker_degree_cutoff(2) objSession.select_user_entities_from_user_entity_set( "User_Entity_Set_1", user_entities_to_print, clear_previous_selection=True) objSession.tag_selected_user_entities( user_entity_set_id="User_Entity_Set_1", tag="seed+connected") t_3 = time.clock() print "t_connected:", t_3 - t_2 # Output set details - only selected nodes #objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open("nodes_selected.out", "w").write, attributes=["genesymbol", "uniprotaccession", "hgnc"], include_level_info=True, include_degree_info=True, level=None, only_selected=True, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=True, output_1_value_per_attribute=False, include_command_in_rows=False) # Output set details - all nodes objSession.output_user_entity_set_details( user_entity_set_id="User_Entity_Set_1", out_method=open("nodes.out", "w").write, attributes=["genesymbol", "uniprotaccession", "hgnc"], include_level_info=True, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info=True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=True, output_1_value_per_attribute=False, include_command_in_rows=False) t_4 = time.clock() print "t_nodes:", t_4 - t_3 # Output network details objSession.output_user_entity_set_network( user_entity_set_id="User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes=[], participant_attributes=[], relation_attributes=["Method_id"], allowed_relation_types="all", include_relation_ids=False, include_participant_ids=True, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", only_selected=False, substitute_node_attribute_if_not_exists=True, include_participant_tags=False, include_relation_tags=False, include_unconnected_nodes=False) t_5 = time.clock() print "t_network:", t_5 - t_4
def old_create_human_interactome_using_biana(node_file_prefix="human_nodes", network_files_prefix="human_network", include_string=False): #, load_from_saved_session=False): """ Creates human ppi network files using BIANA Node file: node_file_prefix.tsv (as tab seperated values) Edge files: network_files_prefix.sif (network in sif format), network_file_prefix_attribute.eda (Cytoscape edge attribute files for each attribute) """ from biana.biana_commands import available_sessions, create_new_session, save_session, load_session from biana.BianaObjects import BianaSessionManager DB_NAME = "test_biana" DB_HOST = "127.0.0.1" DB_USER = "******" DB_PASS = "******" UNIFICATION_PROTOCOL = "(p2)(noself)(noprevious)uniprot_seqtax_geneid_scoppdb" identifier_description_list = [("taxid", "9606")] relation_type_list = ["interaction"] #,"reaction"] # ["interaction","reaction","complex","pathway"] level = 0 #if load_from_saved_session: # load_session(network_files_prefix + "_session.dat") # return # Create a new BIANA session create_new_session(sessionID="biana_session",dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") uESet1 = objSession.get_user_entity_set("User_Entity_Set_1") print "# of nodes: ", uESet1.getSize() if include_string: # Duplicate the User Entity Set (group of biomolecules) in this session uESet2 = objSession.duplicate_user_entity_set(user_entity_set_id="User_Entity_Set_1", new_user_entity_set_id="User_Entity_Set_2") # Fetch relations (except STRING) of biomolecules in 1st set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[], include_relations_last_level=True, use_self_relations=True) print "# of experimental edges: ", uESet1.getNumberEdges() # Fetch relations (only STRING with scores > 700) of biomolecules in 2nd set relation_type_list = ["functional_association"] #objSession.create_network( user_entity_set_id = "User_Entity_Set_2" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[("stringscore",">700")], include_relations_last_level=True, use_self_relations=True) objSession.create_network( user_entity_set_id = "User_Entity_Set_2" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[], include_relations_last_level=True, use_self_relations=True) print "# of string edges: ", uESet2.getNumberEdges() uESet3 = objSession.get_union_of_user_entity_set_list(user_entity_set_list=["User_Entity_Set_1", "User_Entity_Set_2"], include_relations=True, new_user_entity_set_id="User_Entity_Set_3") objSession.remove_user_entity_set(user_entity_set_id="User_Entity_Set_1") objSession.remove_user_entity_set(user_entity_set_id="User_Entity_Set_2") # Output set details - all nodes objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_3", out_method = open(node_file_prefix+".tsv", "w").write, attributes=["uniprotaccession", "geneid", "ensembl", "genesymbol", "go", "hgnc", "disease", "proteinsequence"], include_level_info=False, include_degree_info=False, level=None, only_selected=False, output_format="tabulated", include_tags_info = False, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False) # Export all the information of this set and its network to a file in a tab separated format #objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_3", out_method=open("network.out", "w").write, node_attributes = ["uniprotaccession"], participant_attributes = [], relation_attributes=["stringscore"], include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", include_participant_tags=False, include_relation_tags=False) objSession.output_user_entity_set_network_in_sif_format(user_entity_set_id = "User_Entity_Set_3", output_path = "./", output_prefix = network_files_prefix, node_attributes = [], participant_attributes = [], relation_attributes=["pubmed", "method_id","stringscore"], output_1_value_per_attribute=False, include_tags=False) else: # Fetch relations (except STRING) of biomolecules in 1st set objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = level, relation_type_list=relation_type_list, relation_attribute_restriction_list=[], include_relations_last_level=True, use_self_relations=True) print "# of experimental edges: ", uESet1.getNumberEdges() ## Get tags for each node - seed, connected, whatever... #user_entities_to_print = set(available_sessions["biana_session"].get_user_entity_set(user_entity_set_id = "User_Entity_Set_1").get_user_entity_ids(level=0)) | set(available_sessions["biana_session"].get_user_entity_set(user_entity_set_id = "User_Entity_Set_1").get_user_entity_ids_by_linker_degree_cutoff(2)) #available_sessions["biana_session"].select_user_entities_from_user_entity_set("User_Entity_Set_1", user_entities_to_print, clear_previous_selection = True) #objSession.tag_selected_user_entities(user_entity_set_id="User_Entity_Set_1", tag="seed+connected") # Output set details - all nodes objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open(node_file_prefix + ".tsv", "w").write, attributes=["uniprotaccession", "geneid", "ensembl", "genesymbol", "go", "hgnc", "disease", "proteinsequence"], include_level_info=False, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False) ## Export sequences of entries in this set as a FASTA file #objSession.output_user_entity_set_sequences_in_fasta(user_entity_set_id="User_Entity_Set_1", only_selected = False, out_method=open("human_fasta.txt",'w').write, type="proteinsequence") #, attributes=["uniprotaccession"]) # Export all the information of this set and its network to a file in a tab separated format objSession.output_user_entity_set_network_in_sif_format(user_entity_set_id = "User_Entity_Set_1", output_path = "./", output_prefix = network_files_prefix, node_attributes = [], participant_attributes = [], relation_attributes=["pubmed", "method_id"], output_1_value_per_attribute=False, include_tags=False) available_sessions["biana_session"].output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method = open(network_files_prefix + ".tsv", "w").write, node_attributes = [], participant_attributes = [], relation_attributes = ["method_id"], allowed_relation_types = "all", include_relation_ids = False, include_participant_ids = True, include_relation_type = True, include_relation_sources = True, output_1_value_per_attribute = False, output_format = "tabulated", only_selected = False, substitute_node_attribute_if_not_exists = False, include_participant_tags = False, include_relation_tags = False, include_unconnected_nodes=False) # Save the session save_session("biana_session", network_files_prefix + "_session.dat") return
def select_and_create_subset_from_set(): from biana.biana_commands import administration, available_sessions, create_new_session from biana.BianaObjects import BianaSessionManager import sets identifier_description_list = [("genesymbol", "rad2"), ("genesymbol", "rad1")] identifier_description_list2 = [("genesymbol", "rad1")] relation_type_list = ["interaction"] # Create a new BIANA session objSession = create_new_session(sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, external_entity_attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1") # Create another User Entity Set (group of biomolecules) in this session uESet2 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list2, external_entity_attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_2") # Select all User Entities in the second User Entity Set user_entities_to_select = uESet2.get_user_entity_ids() objSession.select_user_entities_from_user_entity_set( "User_Entity_Set_1", user_entities_to_select, clear_previous_selection=True) # Create a new User Entity Set from selected User Entities in the first User Entity Set objSession.get_sub_user_entity_set( user_entity_set_id="User_Entity_Set_1", include_relations=False, new_user_entity_set_id="User_Entity_Set_3") # Output set details objSession.output_user_entity_set_details( user_entity_set_id="User_Entity_Set_3", out_method=open("nodes.out", "w").write, attributes=["genesymbol", "uniprotaccession", "hgnc"], include_level_info=True, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info=True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=True, output_1_value_per_attribute=False, include_command_in_rows=False)
def simple_session(): from biana.biana_commands import administration, available_sessions, create_new_session, save_session, load_session from biana.BianaObjects import BianaSessionManager # Remove comment below to load data from previous session # load_session("/home/user/test.dat") identifier_description_list = [("gi", "1019412")] # [("disease", "alzheimer")] relation_type_list = ["interaction"] # ["reaction","complex","pathway","interaction"] # Create a new BIANA session create_new_session( sessionID="biana_session", dbname=DB_NAME, dbhost=DB_HOST, dbuser=DB_USER, dbpassword=DB_PASS, unification_protocol=UNIFICATION_PROTOCOL, ) objSession = available_sessions["biana_session"] # Create a new User Entity Set (group of biomolecules) in this session uESet1 = objSession.create_new_user_entity_set( identifier_description_list=identifier_description_list, attribute_restriction_list=[], id_type="embedded", new_user_entity_set_id="User_Entity_Set_1", ) uESet1 = objSession.get_user_entity_set("User_Entity_Set_1") # Export sequences of entries in this set as a FASTA file objSession.output_user_entity_set_sequences_in_fasta( user_entity_set_id="User_Entity_Set_1", only_selected=False, out_method=open("test_fasta.txt", "w").write, type="proteinsequence", attributes=["uniprotAccession"], ) # Instead of exporting the set as a FASTA file, remove comment below to export it as a tab separated file # objSession.output_user_entity_set_details(user_entity_set_id = "User_Entity_Set_1", out_method = open("nodes.out", "w").write, attributes=["hgnc", "taxid"], include_level_info=True, include_degree_info=True, level=None, only_selected=False, output_format="tabulated", include_tags_info = True, include_tags_linkage_degree_info=[], substitute_node_attribute_if_not_exists=False, output_1_value_per_attribute=False, include_command_in_rows=False) # Fetch relations of biomolecules in this set objSession.create_network( user_entity_set_id="User_Entity_Set_1", level=1, relation_type_list=relation_type_list, include_relations_last_level=True, use_self_relations=True, ) # Instead of creating network from existing relations, remove comment below make predictions based on shared attribute # objSession.create_network( user_entity_set_id = "User_Entity_Set_1" , level = 1 , include_relations_last_level = False , use_self_relations = False , expansion_relation_type_list = ["interaction"] , expansion_attribute_list = [ [("cog", [])] ], expansion_level = 2 ) # Export all the information of this set and its network to a file in a tab separated format objSession.output_user_entity_set_network( user_entity_set_id="User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes=["uniprotaccession"], participant_attributes=[], relation_attributes=[], allowed_relation_types="all", include_relation_ids=False, include_participant_ids=False, include_relation_type=True, include_relation_sources=True, output_1_value_per_attribute=False, output_format="tabulated", only_selected=False, substitute_node_attribute_if_not_exists=False, ) # objSession.output_user_entity_set_network(user_entity_set_id = "User_Entity_Set_1", out_method=open("network.out", "w").write, node_attributes = ["uniprotaccession"], relation_attributes=["psimi_name"], include_relation_sources=True, output_format="tabulated") # Remove comment below to save this session for later use # save_session("biana_session", "/home/user/test.dat") return