Skip to content

Output

write_cytoscape(predictions: list, path: str | Path) -> None

Write Cytoscape-compatible SIF format.

Writes rows as: source \t pp \t target where pp indicates a phosphorylation interaction. Weighted by NetworKIN score.

Source code in src/pynetworkin/output.py
def write_cytoscape(predictions: list, path: str | Path) -> None:
    r"""Write Cytoscape-compatible SIF format.

    Writes rows as:
        source \t pp \t target
    where pp indicates a phosphorylation interaction.
    Weighted by NetworKIN score.
    """
    rows = []
    for p in predictions:
        rows.append(
            {
                "source": p.get("Kinase/Phosphatase/Phospho-binding domain", ""),
                "interaction": "pp",
                "target": p.get("Name", ""),
                "weight": p.get("NetworKIN score", 0.0),
            }
        )
    pd.DataFrame(rows).to_csv(path, sep="\t", index=False)

write_output(predictions: list, path: str | Path, fmt: str = 'tsv') -> None

Dispatcher — call write_tsv or write_cytoscape based on fmt.

Source code in src/pynetworkin/output.py
def write_output(predictions: list, path: str | Path, fmt: str = "tsv") -> None:
    """Dispatcher — call write_tsv or write_cytoscape based on fmt."""
    fmt = fmt.lower().strip()
    if fmt in ("tsv", "tab"):
        write_tsv(predictions, path)
    elif fmt in ("cytoscape", "sif"):
        write_cytoscape(predictions, path)
    else:
        raise ValueError(f"Unknown output format: {fmt!r}. Use 'tsv' or 'cytoscape'.")

write_tsv(predictions: list, path: str | Path) -> None

Write predictions to a tab-separated file.

Columns follow STANDARD_COLUMNS order. Missing optional fields are filled with None.

Source code in src/pynetworkin/output.py
def write_tsv(predictions: list, path: str | Path) -> None:
    """Write predictions to a tab-separated file.

    Columns follow STANDARD_COLUMNS order.
    Missing optional fields are filled with None.
    """
    df = pd.DataFrame(predictions)
    for col in STANDARD_COLUMNS:
        if col not in df.columns:
            df[col] = None
    df = df[STANDARD_COLUMNS]
    df.to_csv(path, sep="\t", index=False)