Esempio n. 1
0
def write_xgmml(excel_filename: str, output=None, layout_template_file=None):
    """
    creating the xgmml file from an excel input and writing it into a new file.

    Args:
        excel_filename: Name of the excel input file.
        output: Name of the new output.
        layout_template_file: Name of the layout template file.

    Returns:
        None

    """
    if not output:
        output = os.path.splitext(os.path.basename(excel_filename))[0]

    base_path = os.path.dirname(excel_filename)

    if not output.endswith('.xgmml'):
        output =  '{0}.xgmml'.format(output)

    graph_filename = os.path.join(base_path, '{0}'.format(output))

    print('graph_filename: ', graph_filename)
    _file_path_existence(graph_filename)


    print('Reading in Excel file [{}] ...'.format(excel_filename))
    excel_book = ExcelBook(excel_filename)

    rxncon_system = excel_book.rxncon_system
    print('Constructed rxncon system: [{} reactions], [{} contingencies]'
          .format(len(rxncon_system.reactions), len(rxncon_system.contingencies)))

    print('Generating regulatory graph output...')
    rxngraph_system = rxngraph_from_rxncon_system(rxncon_system)
    graph = rxngraph_system.reaction_graph

    if layout_template_file:
        print('Writing layout information from [{0}] to graph file [{1}] ...'.format(layout_template_file, graph_filename))
        gml_system = XGMML(graph, "{}".format(output))
        graph = map_layout2xgmml(gml_system.to_string(), layout_template_file)
        print('Writing regulatory graph file [{}] ...'.format(graph_filename))

        with open(graph_filename, "w") as graph_handle:
            graph_handle.write(graph)
    else:
        print('Writing regulatory graph file [{}] ...'.format(graph_filename))
        gml_system = XGMML(graph, "{}".format(output))
        gml_system.to_file(graph_filename)
Esempio n. 2
0
def test_format_attributes() -> None:
    """
    Testing attribute annotation in xgmml.

    Returns:
        None

    Raises:
        AssertionError if an expected attribute type is not within the node attributes.

    """
    graph = DiGraph()
    graph.add_node('A', str_value='A', int_value=1, float_value=1.0)
    format_attribute_system_str = XGMML(graph, "graph").to_string()

    expected_attribute_type = ['integer', 'double', 'string']
    xmldoc_actual = minidom.parseString(format_attribute_system_str)
    actual_node_attribute_types = [_get_node_att_type(xmldoc_actual.getElementsByTagName('node')[0], attribute_name=attribute)
                                   for attribute in ['int_value', 'float_value', 'str_value']]
    while expected_attribute_type:
        attribute_type = expected_attribute_type.pop()
        assert attribute_type in actual_node_attribute_types