def test_searcher_indirect_2(self):
        """testing the following query ahl and laci = gfp for the indirect traverse"""
        conn, cur = db.db_open("sbider.db")
        user_query = "ahl and laci = gfp"
        logic_dictionary = parse.parse_logic(cur, user_query)
        input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)
        repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)
        self.operon_path_list = search.get_sbider_path(input_dictionary,
                                                       repressor_dictionary,
                                                       output_dictionary,
                                                       ['13', '22'], ['11'],
                                                       True)

        for operon_path in self.operon_path_list:
            current_species = ['13', '22']
            input_species_set = set(current_species)
            output_species_set = set(current_species)
            for operon in operon_path:
                input_species = helper.uniquely_merge_list_of_lists(
                    input_dictionary[operon])
                output_species = helper.uniquely_merge_list_of_lists(
                    output_dictionary[operon])
                for species in input_species:
                    if species in output_species_set:
                        input_species_set.add(species)
                for species in output_species:
                    output_species_set.add(species)
                self.assertEquals(
                    input_species_set.issubset(output_species_set), True)
        db.db_close(conn, cur)
 def test_searcher_indirect_2(self):
     """testing the following query ahl and laci = gfp for the indirect traverse"""
     conn, cur = db.db_open("sbider.db")
     user_query =  "ahl and laci = gfp"
     logic_dictionary = parse.parse_logic(cur, user_query)
     input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)
     repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)
     self.operon_path_list = search.get_sbider_path(input_dictionary,
                                                    repressor_dictionary,
                                                    output_dictionary,
                                                    ['13', '22'],
                                                    ['11'],
                                                    True)
             
     for operon_path in self.operon_path_list:
         current_species = ['13', '22']
         input_species_set = set(current_species)
         output_species_set = set(current_species)
         for operon in operon_path:
             input_species = helper.uniquely_merge_list_of_lists(input_dictionary[operon])
             output_species = helper.uniquely_merge_list_of_lists(output_dictionary[operon])
             for species in input_species:
                 if species in output_species_set:
                     input_species_set.add(species)
             for species in output_species:
                 output_species_set.add(species)
             self.assertEquals(input_species_set.issubset(output_species_set), True)
     db.db_close(conn,cur)
Exemplo n.º 3
0
def testRunSBiDer(directory_path, user_query, indirect=False):

    # Access database
    database_file = directory_path + "/SBiDer.db"
    conn, cur = db.db_open(database_file)

    # Dictionary of fragmented user inputs that satisfy user query
    logic_dictionary = parser.parse_logic(cur, user_query)

    # Dictionaries of: Operon <-> InputSpecies, Operon <-> OutputSpecies, and Operon <-> Repressor
    input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)
    repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)
    #rint("** input dictionary")
    #BiDer_helper.printplus(input_dictionary)
    #rint("** output dictionary")
    #BiDer_helper.printplus(output_dictionary)
    #rint("** repressor dictionary")
    #BiDer_helper.printplus(repressor_dictionary)

    # Build operon path for each fragmented user input, which satisfies user query
    all_operon_path = []
    for input_species, output_species_list in logic_dictionary.items():

        operon_path_per_start_species = [input_species]
        for output_species in output_species_list:
            operon_path_list = searcher.get_sbider_path(
                input_dictionary, repressor_dictionary, output_dictionary,
                list(input_species), output_species, indirect)
            operon_path_per_start_species.extend(operon_path_list)

        all_operon_path.append(operon_path_per_start_species)

        return all_operon_path == [[('21', '22'), ['72-3'], ['82-1']]]
Exemplo n.º 4
0
def create_whole_network_json():
    """Generates the whole network json."""

    conn, cursor = db.db_open("sbider.db")
    json_info = get_whole_network(cursor)
    create_json_network("sbider_whole_network.json", *json_info)
    db.db_close(conn, cursor)
 def test_fail_parser(self):
     """testing faulty query."""
     conn, cur = db.db_open("sbider.db")
     try:
         self.logic = parse.parse_logic(cur, "A and B = C")
     except TypeError:
         pass
     db.db_close(conn,cur)
Exemplo n.º 6
0
def create_subnetwork_json(list_of_operon_paths, starting_species_list_of_lists):
    """Generates the subnetwork json."""
    
    conn, cursor = db.db_open("sbider.db")
    operon_input_transition_dictionary = get_input_transition_species_dictionary(cursor)
    json_info = get_subnetwork(cursor, list_of_operon_paths, starting_species_list_of_lists)
    create_json_network("sbider_subnetwork_hurrah.json", *json_info)
    db.db_close(conn, cursor)
def create_subnetwork_json(cursor, list_of_operon_paths, json_file_name = "test.json"):
    """Generates the subnetwork json."""
    
    conn, cursor = db.db_open("sbider.db")
    operon_input_transition_dictionary = get_input_transition_species_dictionary(cursor)
    json_info = get_subnetwork(cursor, list_of_operon_paths)
    create_json_network(json_file_name, *json_info)
    db.db_close(conn, cursor)
 def test_fail_parser(self):
     """testing faulty query."""
     conn, cur = db.db_open("sbider.db")
     try:
         self.logic = parse.parse_logic(cur, "A and B = C")
     except TypeError:
         pass
     db.db_close(conn, cur)
def main():
    web_path = sys.argv[1]
    database_file = web_path + "sbider.db"
    global rootPath 
    rootPath = web_path
    device_info = sys.argv[2::]
    conn, cur = db.db_open(database_file)
    sbol_files = insert_new_device(conn, cur, device_info, web_path)
    db.db_close(conn, cur)

    #conn, cur = db.db_open(database_file)
    #sg.create_network_json_file(cur, web_path + "whole_network.json")
    #db.db_close(conn, cur)
    #gn.create_whole_network_sbml()
    
    return sbol_files
    def test_searcher_direct(self):
        """testing the following query lara and arac to gfp for the direct traverse"""
        conn, cur = db.db_open("sbider.db")
        user_query =  "lara and arac = gfp"
        logic_dictionary = parse.parse_logic(cur, user_query)
        input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)
        repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)
        self.operon_path_list = search.get_sbider_path(input_dictionary,repressor_dictionary,\
                                                    output_dictionary, ['2', '38'], ['11'], False)

        for operon_path in self.operon_path_list:
            current_species = ['2', '38']
            for operon in operon_path:
                self.assertEquals(current_species in input_dictionary[operon], True)
                current_species = output_dictionary[operon][0]
        db.db_close(conn,cur)
    def test_searcher_direct(self):
        """testing the following query lara and arac to gfp for the direct traverse"""
        conn, cur = db.db_open("sbider.db")
        user_query = "lara and arac = gfp"
        logic_dictionary = parse.parse_logic(cur, user_query)
        input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)
        repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)
        self.operon_path_list = search.get_sbider_path(input_dictionary,repressor_dictionary,\
                                                    output_dictionary, ['2', '38'], ['11'], False)

        for operon_path in self.operon_path_list:
            current_species = ['2', '38']
            for operon in operon_path:
                self.assertEquals(current_species in input_dictionary[operon],
                                  True)
                current_species = output_dictionary[operon][0]
        db.db_close(conn, cur)
def build_sbider_network(directory_path, user_query, indirect=False):

    print("** build_sbider_network")

    # Access database
    database_file = directory_path + "/SBiDer.db"
    conn, cur = db.db_open(database_file)

    # Dictionary of fragmented user inputs that satisfy user query
    logic_dictionary = parser.parse_logic(cur, user_query)

    # Dictionaries of: Operon <-> InputSpecies & Operon <-> OutputSpecies
    input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)

    print("** input dictionary")
    SBiDer_helper.printplus(input_dictionary)

    print("** output dictionary")
    SBiDer_helper.printplus(output_dictionary)

    # Dictionary of: Operon <-> Repressor
    repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)

    print("** repressor dictionary")
    SBiDer_helper.printplus(repressor_dictionary)

    # Build operon path for each fragmented user input, which satisfies user query
    all_operon_path = []
    for input_species, output_species_list in logic_dictionary.items():

        operon_path_per_start_species = [input_species]
        for output_species in output_species_list:
            operon_path_list = searcher.get_sbider_path(input_dictionary,
                                                        repressor_dictionary,
                                                        output_dictionary,
                                                        list(input_species),
                                                        output_species,
                                                        indirect)

            operon_path_per_start_species.extend(operon_path_list)
        all_operon_path.append(operon_path_per_start_species)

        # Create JSON file needed to display the found genetic circuit
        path_json = grapher.create_subnetwork_json_string(cur, operon_path_per_start_species, database_file)

        return path_json
Exemplo n.º 13
0
def testRunSBiDer(directory_path, user_query, indirect=False):

    # Access database
    database_file = directory_path + "/SBiDer.db"
    conn, cur = db.db_open(database_file)

    # Dictionary of fragmented user inputs that satisfy user query
    logic_dictionary = parser.parse_logic(cur, user_query)

    # Dictionaries of: Operon <-> InputSpecies, Operon <-> OutputSpecies, and Operon <-> Repressor
    input_dictionary, output_dictionary = db.make_ope_id_spe_id_dics(cur)
    repressor_dictionary = db.make_ope_id_rep_spe_id_dic(cur)
    #rint("** input dictionary")
    #BiDer_helper.printplus(input_dictionary)
    #rint("** output dictionary")
    #BiDer_helper.printplus(output_dictionary)
    #rint("** repressor dictionary")
    #BiDer_helper.printplus(repressor_dictionary)

    # Build operon path for each fragmented user input, which satisfies user query
    all_operon_path = []
    for input_species, output_species_list in logic_dictionary.items():

        operon_path_per_start_species = [input_species]
        for output_species in output_species_list:
            operon_path_list = searcher.get_sbider_path(input_dictionary,
                                                        repressor_dictionary,
                                                        output_dictionary,
                                                        list(input_species),
                                                        output_species,
                                                        indirect)
            operon_path_per_start_species.extend(operon_path_list)
            
        all_operon_path.append(operon_path_per_start_species)
        
        return all_operon_path == [[('21', '22'), ['72-3'], ['82-1']]]
def build_sbider_network(user_query, indirect=False):
    database_file = \
        "/cellar/users/hyeerna/Dropbox/Project/20140601_sbider/UCSD_IGEM/SBiDer/SBiDer_Database/sbider.db"
    conn, cur = db.db_open(database_file)

    logic_dictionary = parser.parse_logic(cur, user_query)
    print "build_sbider_network: logic_dictionary", logic_dictionary

    input_dictionary, output_dictionary = db.make_ope_id_spe_id_dicts(cur)

    all_operon_path_list_per_start_species = []
    file_name_idx = 1
    for input_species, output_species_list in logic_dictionary.items():
        operon_path_list_per_start_species = [input_species]

        for output_species in output_species_list:
            print "\t Path:", input_species, "--->", output_species, "="

            operon_path_list = searcher.get_sbider_path(input_dictionary,
                                                        output_dictionary,
                                                        list(input_species),
                                                        output_species,
                                                        indirect)

            operon_path_list_per_start_species.extend(operon_path_list)

            for operon_path in operon_path_list:
                print "\t\t build_sbider_network: operon_path =>", operon_path

        all_operon_path_list_per_start_species.append(operon_path_list_per_start_species)

        file_name = "test_json_file_%d.json" % file_name_idx

        grapher.create_subnetwork_json(cur, operon_path_list_per_start_species, file_name)

        file_name_idx += 1
Exemplo n.º 15
0
        ###print "Searching it_trans_list:", it_trans_id
        print "it_id_dict[it_trans_id]:", it_id_dict[it_trans_id]
        
        activating_species_set = set(it_id_dict[it_trans_id])
        
        print "activating_species_set:", activating_species_set
        
        if starting_species_set.issuperset(activating_species_set):
            activated_it_id_list.append(it_trans_id)
    return activated_it_id_list


# In[15]:

conn, cursor = db.db_open("sbider.db")
#db.db_print_table(cursor,"Species")

print determine_operon_activated_input_transition(cursor,['20', '21', '9', '32'] , "1-1", it_id_dict)


# In[16]:

def create_operon_node(cursor, operon_id):    
    """Create operon nodes from the corresponding operon_id."""    

    ###print "operon_id:", operon_id

    operon_node = get_node_from_id(cursor, "Operon", "'" + operon_id + "'", "ope_id")
    
    ###print "operon_node:", operon_node
 def test_successful_parser(self):
     """testing a successful query of the sbider network"""
     conn, cur = db.db_open("sbider.db")
     self.logic = parse.parse_logic(cur, "lara and arac = gfp")
     self.assertEquals(type(self.logic), dict)
     db.db_close(conn, cur)
 def test_successful_parser(self):
     """testing a successful query of the sbider network"""
     conn, cur = db.db_open("sbider.db")
     self.logic = parse.parse_logic(cur, "lara and arac = gfp")
     self.assertEquals(type(self.logic), dict)
     db.db_close(conn,cur)
//Description: 
    Access SBiDer database and retrieve all necessary SBML information 

*************************************************
@author: Fernando Contreras
@email: [email protected]
@project: SBiDer
@institution: University of California, San Diego
*************************************************
'''
import os
import sbider_database as sd
#open database
cwd = os.getcwd()
database_path = os.path.join(cwd,'sbider.db')
con,cursor = sd.db_open(database_path)

def get_sbml_miriam_ids():
    '''
    Access plasmid table and plasmid-operon relationship table to retrieve 
    the miriam ids of each operon
    
    @Output: dictionary = {operon id: miriam id}
        operon id: string type 
        miriam id: string type 
    '''
    devices = sd.db_select(cursor,'plasmid',['pla_id', 'PMID'])
    devices = devices.fetchall()
    plasmid_operon = sd.db_select(cursor,'plasmidoperon',['ope_id','pla_id'])
    plasmid_operon = plasmid_operon.fetchall()
    plasmid_miriam  = dict(devices)