Пример #1
0
def test_grouping_block_targeting_block():
    st1 = Phosphorylation(Agent('A'), Agent('B'))
    st2 = Phosphorylation(Agent('A'), Agent('C'))
    st3 = Phosphorylation(Agent('D'), Agent('B'))
    st4 = Phosphorylation(Agent('D'), Agent('C'))
    cja = CyJSAssembler()
    cja.add_statements([st1, st2, st3, st4])
    cja.make_model(grouping=True)
    for node in cja._nodes:
        if node['data']['name'] == 'A':
            parent_a = node['data']['parent']
        if node['data']['name'] == 'B':
            parent_b = node['data']['parent']
        if node['data']['name'] == 'C':
            parent_c = node['data']['parent']
        if node['data']['name'] == 'D':
            parent_d = node['data']['parent']
    assert_element_properties(cja)
    assert (parent_b == parent_c)
    assert (parent_a == parent_d)
    parent_b_name = [
        x['data']['name'] for x in cja._nodes if x['data']['id'] == parent_b
    ][0]
    parent_a_name = [
        x['data']['name'] for x in cja._nodes if x['data']['id'] == parent_a
    ][0]
    assert (parent_b_name.startswith('Group'))
    assert (parent_a_name.startswith('Group'))
    assert (len(cja._edges) == 5)
    virtual_edges = [x for x in cja._edges if x['data']['i'] == 'Virtual']
    assert (len(virtual_edges) == 4)
    real_edges = [x for x in cja._edges if x['data']['i'] != 'Virtual']
    assert (len(real_edges) == 1)
Пример #2
0
def test_print_cyjs_graph():
    cja = CyJSAssembler()
    cja.add_statements([st_act, st_act2])
    cja.make_model()
    cyjs_str = cja.print_cyjs_graph()
    # assert output is not empty
    assert (len(cyjs_str) > len('{\n "edges": [],\n "nodes": []\n}'))
Пример #3
0
def test_grouping_node_targeting_block():
    st1 = Phosphorylation(Agent('A'), Agent('B'))
    st2 = Phosphorylation(Agent('A'), Agent('C'))
    cja = CyJSAssembler()
    cja.add_statements([st1, st2])
    cja.make_model(grouping=True)
    for node in cja._nodes:
        if node['data']['name'] == 'A':
            parent_a = node['data']['parent']
            assert(parent_a == '')
        if node['data']['name'] == 'B':
            parent_b = node['data']['parent']
        if node['data']['name'] == 'C':
            parent_c = node['data']['parent']
        assert_has_id(node)
    for edge in cja._edges:
        assert_has_id(edge)
    assert(parent_b == parent_c)
    parent_b_name = [x['data']['name'] for x in cja._nodes if
                     x['data']['id']==parent_b][0]
    assert(parent_b_name.startswith('Group'))
    assert(len(cja._edges) == 3)
    virtual_edges = [x for x in cja._edges if
                     x['data']['i'] == 'Virtual']
    assert(len(virtual_edges) == 2)
    real_edges = [x for x in cja._edges if
                  x['data']['i'] != 'Virtual']
    assert(len(real_edges) == 1)
Пример #4
0
def test_complex():
    cja = CyJSAssembler()
    cja.add_statements([st_complex])
    cja.make_model()
    assert (len(cja._nodes) == 3)
    assert (len(cja._edges) == 3)
    polarities = [edge['data']['polarity'] for edge in cja._edges]
    assert (len(set(polarities)) == 1)
    assert ('none' in polarities)
Пример #5
0
def test_selfmod():
    cja = CyJSAssembler()
    cja.add_statements([st_selfmod])
    cja.make_model()
    assert (len(cja._nodes) == 1)
    assert (len(cja._edges) == 1)
    polarities = [edge['data']['polarity'] for edge in cja._edges]
    assert (len(polarities) == 1)
    assert (polarities[0] == 'positive')
Пример #6
0
def test_complex():
    cja = CyJSAssembler()
    cja.add_statements([st_complex])
    cja.make_model()
    assert(len(cja._nodes) == 3)
    assert(len(cja._edges) == 3)
    polarities = [edge['data']['polarity'] for edge in cja._edges]
    assert(len(set(polarities))==1)
    assert('none' in polarities)
Пример #7
0
def test_ras():
    cja = CyJSAssembler()
    cja.add_statements([st_gef, st_gap])
    cja.make_model()
    assert (len(cja._nodes) == 3)
    assert (len(cja._edges) == 2)
    polarities = [edge['data']['polarity'] for edge in cja._edges]
    assert (len(set(polarities)) == 2)
    assert ('positive' in polarities)
    assert ('negative' in polarities)
Пример #8
0
def test_no_grouping():
    st1 = Phosphorylation(Agent('A'), Agent('B'))
    st2 = Phosphorylation(Agent('A'), Agent('C'))
    st3 = Phosphorylation(Agent('C'), Agent('B'))
    cja = CyJSAssembler()
    cja.add_statements([st1, st2, st3])
    cja.make_model(grouping=True)
    parents = [node['data']['parent'] for node in cja._nodes]
    for parent in parents:
        assert parent == ''
Пример #9
0
def test_edge_grouping_between_nongroup_nodes():
    cja = CyJSAssembler()
    cja.add_statements([st_phos_Y, st_phos_T])
    cja.make_model(grouping=True)
    assert(len(cja._nodes) == 2)
    assert(len(cja._edges) == 1)
    for edge in cja._edges:
        assert(len(edge['data']['uuid_list']) == 2)
    for node in cja._nodes:
        assert(len(node['data']['uuid_list']) == 2)
Пример #10
0
def test_no_grouping():
    st1 = Phosphorylation(Agent('A'), Agent('B'))
    st2 = Phosphorylation(Agent('A'), Agent('C'))
    st3 = Phosphorylation(Agent('C'), Agent('B'))
    cja = CyJSAssembler()
    cja.add_statements([st1, st2, st3])
    cja.make_model(grouping=True)
    parents = [node['data']['parent'] for node in cja._nodes]
    for parent in parents:
        assert parent == ''
Пример #11
0
def assemble_cyjs():
    """Assemble INDRA Statements and return Cytoscape JS network."""
    response = request.body.read().decode('utf-8')
    body = json.loads(response)
    stmts_json = body.get('statements')
    stmts = stmts_from_json(stmts_json)
    cja = CyJSAssembler()
    cja.add_statements(stmts)
    cja.make_model(grouping=True)
    model_str = cja.print_cyjs_graph()
    return model_str
Пример #12
0
def test_act():
    cja = CyJSAssembler()
    cja.add_statements([st_act, st_act2])
    cja.make_model()
    assert (len(cja._nodes) == 3)
    assert (len(cja._edges) == 2)
    polarities = [edge['data']['polarity'] for edge in cja._edges]
    assert (len(set(polarities)) == 2)
    assert ('positive' in polarities)
    assert ('negative' in polarities)
    db_refs = [node['data']['db_refs'] for node in cja._nodes]
    for node in cja._nodes:
        if node['data']['name'] == 'MAP2K1':
            assert (node['data']['db_refs'].get('HGNC'))
        if node['data']['name'] == 'MAPK1':
            assert (node['data']['db_refs'].get('UniProt'))
        if node['data']['name'] == 'DUSP4':
            assert (not node['data']['db_refs'])
Пример #13
0
def test_act():
    cja = CyJSAssembler()
    cja.add_statements([st_act, st_act2])
    cja.make_model()
    assert(len(cja._nodes) == 3)
    assert(len(cja._edges) == 2)
    polarities = [edge['data']['polarity'] for edge in cja._edges]
    assert(len(set(polarities))==2)
    assert('positive' in polarities)
    assert('negative' in polarities)
    db_refs = [node['data']['db_refs'] for node in cja._nodes]
    for node in cja._nodes:
        if node['data']['name'] == 'MAP2K1':
            assert(node['data']['db_refs'].get('HGNC'))
        if node['data']['name'] == 'MAPK1':
            assert(node['data']['db_refs'].get('UniProt'))
        if node['data']['name'] == 'DUSP4':
            assert(not node['data']['db_refs'])
Пример #14
0
def make_cyjs_network(results, model, stmts):
    path_stmts = get_path_stmts(results, model, stmts)
    path_genes = get_path_genes(path_stmts)
    path_uuids = [list(path.keys()) for path in path_stmts]
    all_path_uuids = []
    for p in path_uuids:
        all_path_uuids += p
    print(json.dumps(path_uuids, indent=1))
    #filtered_stmts = ac.filter_gene_list(stmts, path_genes, 'one')
    filtered_stmts = ac.filter_uuid_list(stmts, all_path_uuids)
    ca = CyJSAssembler(filtered_stmts)
    cm = ca.make_model()
    ca.set_CCLE_context(['SKMEL28_SKIN'])
    ca.save_json('output/korkut_model')
Пример #15
0
def make_cyjs_network(results, model, stmts):
    path_stmts = get_path_stmts(results, model, stmts)
    path_genes = get_path_genes(path_stmts)
    # Get UUIDs to use as filter
    path_uuids = [list(path.keys()) for path in path_stmts]
    all_path_uuids = []
    for p in path_uuids:
        all_path_uuids += p
    #filtered_stmts = ac.filter_gene_list(stmts, path_genes, 'one')
    filtered_stmts = ac.filter_uuid_list(stmts, all_path_uuids)
    ac.dump_statements(filtered_stmts, 'output/korkut_cyjs_model.pkl')
    ca = CyJSAssembler(filtered_stmts)
    cm = ca.make_model()
    ca.set_CCLE_context(['SKMEL28_SKIN'])
    ca.save_json('output/korkut_model')
Пример #16
0
def test_print_cyjs():
    cja = CyJSAssembler()
    cja.add_statements([st_act, st_act2])
    cja.make_model()
    cyjs_str = cja.print_cyjs()
    print(cyjs_str)