Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Add better feedback for broken files
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 17, 2019
1 parent 3518f5f commit 9ab9055
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/biokeen/cli_utils/bio_2_bel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import importlib
import os
import sys
from typing import Optional

import click
import pkg_resources
Expand Down Expand Up @@ -42,7 +43,7 @@ def _import_bio2bel_module(package: str):
return b_module


def install_bio2bel_module(name, connection, rebuild):
def install_bio2bel_module(name: str, connection: str, rebuild: bool) -> Optional[str]:
"""Install Bio2BEL module."""
if name == 'compath': # special case for compath
module_name = 'compath_resources'
Expand Down Expand Up @@ -83,10 +84,15 @@ def install_bio2bel_module(name, connection, rebuild):

click.secho(f'{EMOJI} generating BEL for {module_name}', bold=True)
graph = manager.to_bel()

click.echo(f'Summary: {graph.number_of_nodes()} nodes / {graph.number_of_edges()} edges')
to_json_path(graph, json_path, indent=2)

click.secho(f'{EMOJI} generating PyKEEN TSV for {module_name}', bold=True)
to_pykeen_file(graph, pykeen_df_path)
click.secho(f'{EMOJI} wrote PyKEEN TSV to {pykeen_df_path}', bold=True)
success = to_pykeen_file(graph, pykeen_df_path)

if success:
click.secho(f'{EMOJI} wrote PyKEEN TSV to {pykeen_df_path}', bold=True)
return pykeen_df_path

return pykeen_df_path
click.secho(f'{EMOJI} no statements generated', bold=True, fg='red')
7 changes: 6 additions & 1 deletion src/biokeen/convert/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
logger = logging.getLogger(__name__)


def to_pykeen_file(graph: BELGraph, file: Union[str, Path, TextIO]) -> None:
def to_pykeen_file(graph: BELGraph, file: Union[str, Path, TextIO]) -> bool:
"""Write the relationships in the BEL graph to a KEEN TSV file."""
df = to_pykeen_df(graph)

if len(df.index) == 0:
return False

df.to_csv(file, sep='\t', index=None, header=None)
return True


def to_pykeen_df(graph: BELGraph) -> pd.DataFrame:
Expand Down

0 comments on commit 9ab9055

Please sign in to comment.