示例#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)

    suffix = '_srg'
    if not output.endswith('.xgmml'):
        output = '{0}{1}.xgmml'.format(output, suffix)
    else:
        base_name = output.split('.xgmml')[0]
        output = "{0}{1}.{2}".format(base_name, suffix, 'xgmml')

    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 reaction species graph output...')
    reg_system = SpeciesReactionGraph(rxncon_system)
    graph = reg_system.to_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 reaction species graph file [{}] ...'.format(
            graph_filename))

        with open(graph_filename, "w") as graph_handle:
            graph_handle.write(graph)
    else:
        print('Writing reaction species graph file [{}] ...'.format(
            graph_filename))
        gml_system = XGMML(graph, "{}".format(output))
        gml_system.to_file(graph_filename)
示例#2
0
def test_file_exists() -> None:
    graph = DiGraph()
    graph.add_node('A', str_value='A', int_value=1, float_value=1.0)

    gml_system = XGMML(graph, "name")
    with pytest.raises(FileExistsError):
        gml_system.to_file(EXISTING_FILE)

    with pytest.raises(NotADirectoryError):
        gml_system.to_file(NOT_A_DIRECTORY)
示例#3
0
def test_write_output() -> None:
    digraph = _digraph_from_quick_str('''A_[b]_ppi+_B_[a]; ! A_[(x)]-{p}
                                      C_p+_A_[(x)]''')

    name = "test{0}".format(time.time())
    gml_system = XGMML(digraph, "name")

    path = "{0}/{1}.xgmml".format(tempfile.gettempdir(), name)
    gml_system.to_file(path)
    file_exists = os.path.exists(path)
    file_size = os.stat(path).st_size
    os.remove(path)
    assert file_exists and file_size > 0