### Development Install with uv Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Clones the repository and installs development dependencies using uv. ```bash git clone https://github.com/qwerty239qwe/scTenifoldpy cd scTenifoldpy uv sync --group test --group dev --group docs ``` -------------------------------- ### Optional Extras Install with uv Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Installs scTenifoldpy with the 'scanpy' extra using uv. ```bash uv pip install "scTenifoldpy[scanpy]" ``` -------------------------------- ### Fetching remote example datasets Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/1_data.ipynb Demonstrates how to list and fetch example datasets from a remote repository. Network access is required. ```python from scTenifold.data import list_data # Requires network access: # list_data() # datasets = fetch_data("AD") ``` -------------------------------- ### Build Docs with uv Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Builds the documentation using uv. ```bash uv run mkdocs build --strict ``` -------------------------------- ### Optional Extras Install with pip Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Installs scTenifoldpy with the 'scanpy' extra using pip. ```bash pip install "scTenifoldpy[scanpy]" ``` -------------------------------- ### scTenifoldKnk Initialization and Build Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/quickstart.md Initializes a scTenifoldKnk object and executes the build() method. ```python from scTenifold import get_test_df from scTenifold import scTenifoldKnk df = get_test_df(n_cells=1000) sc = scTenifoldKnk(data=df, ko_method="default", ko_genes=["NG-1"], # the gene you wants to knock out qc_kws={"min_lib_size": 10}) result = sc.build() ``` -------------------------------- ### scTenifoldNet Initialization and Build Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/quickstart.md Initializes a scTenifoldNet object and executes the build() method. ```python from scTenifold import get_test_df from scTenifold import scTenifoldNet df_1, df_2 = get_test_df(n_cells=1000), get_test_df(n_cells=1000) sc = scTenifoldNet(df_1, df_2, "X", "Y", qc_kws={"min_lib_size": 10}) result = sc.build() ``` -------------------------------- ### Hello World Example Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/index.md A basic example demonstrating how to use the compare_networks function with test data and printing the head of the result. ```python from scTenifold import compare_networks from scTenifold.data import get_test_df x = get_test_df(n_cells=200, n_genes=300, random_state=0) y = get_test_df(n_cells=200, n_genes=300, random_state=1) result = compare_networks( x, y, qc_kws={"min_lib_size": 1}, network_kws={"n_nets": 3, "n_samp_cells": 100}, ) print(result.head()) ``` -------------------------------- ### Run Test Suite with uv Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Runs the test suite using uv. ```bash uv run pytest ``` -------------------------------- ### Install scTenifold using pip Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/installation.md This command installs the scTenifold package using pip. ```console $ pip install sctenifold ``` -------------------------------- ### Parallel Backends example Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/README.md Examples of using different parallel backends for network construction. ```python from scTenifold import make_networks networks = make_networks(df_1, backend="serial", n_jobs=1) networks = make_networks(df_1, backend="joblib-loky", n_jobs=4) ``` -------------------------------- ### Development Install with pip Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Installs scTenifoldpy in editable mode with development dependencies using pip. ```bash pip install -e ".[scanpy,parallel-ray,docs]" pip install pytest pytest-cov ruff build ``` -------------------------------- ### Installation with uv Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/index.md Installs scTenifoldpy using uv for virtual environment and package management. ```bash uv venv uv pip install scTenifoldpy ``` -------------------------------- ### Example DataFrame creation Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/1_data.ipynb Demonstrates creating sample expression data as a pandas DataFrame with genes as rows and cells as columns. ```python import pandas as pd from scTenifold.data import get_test_df x = get_test_df(n_cells=80, n_genes=120, random_state=0) y = get_test_df(n_cells=80, n_genes=120, random_state=1) x.shape, y.shape ``` -------------------------------- ### Build Default Docker Image Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Builds the default Docker image for scTenifoldpy. ```bash docker build -t sctenifoldpy . ``` -------------------------------- ### Build Docker Image with Optional Extras Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Builds a Docker image with specific optional extras included. ```bash docker build --build-arg EXTRAS=scanpy -t sctenifoldpy:scanpy . docker build --build-arg EXTRAS=parallel-ray -t sctenifoldpy:ray . ``` -------------------------------- ### Installation with pip Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/index.md Installs scTenifoldpy using pip. ```bash pip install scTenifoldpy ``` -------------------------------- ### High-Level API example Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/README.md Example usage of the compare_networks and virtual_knockout high-level APIs. ```python from scTenifold import compare_networks, virtual_knockout result = compare_networks( df_1, df_2, qc_kws={"min_lib_size": 10, "plot": False}, network_kws={"n_nets": 3, "n_samp_cells": 100}, backend="joblib-threading", n_jobs=4, ) knockout = virtual_knockout( df_1, ko_genes=["NG-1"], qc_kws={"min_lib_size": 10, "min_percent": 0.001}, ) ``` -------------------------------- ### Step-Wise: ``scTenifoldNet`` / ``scTenifoldKnk`` Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/quickstart.md This code snippet demonstrates the step-wise usage of the `scTenifoldNet` class for pipeline processing. It shows initialization, running individual steps, printing intermediate results, and saving the model. ```python from scTenifold import scTenifoldNet model = scTenifoldNet( x, y, x_label="ctrl", y_label="cond", qc_kws={"min_lib_size": 1}, nc_kws={"n_nets": 3, "n_samp_cells": 100, "backend": "serial"}, ) model.run_step("qc") model.run_step("nc") model.run_step("td") model.run_step("ma") model.run_step("dr") print(model.QC_dict["ctrl"].shape) # genes x cells after QC print(len(model.network_dict["ctrl"])) # n_nets PC networks print(model.tensor_dict["ctrl"].shape) # genes x genes print(model.manifold.shape) # (2 * shared_genes) x d print(model.d_regulation.head()) model.save("./run-ctrl-vs-cond") ``` -------------------------------- ### AnnData Input Examples Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/anndata.md Examples demonstrating how to use AnnData objects with compare_networks and virtual_knockout functions. ```python from scTenifold import compare_networks, virtual_knockout # compare_networks with two AnnData objects result = compare_networks(adata_x, adata_y, layer="counts") # virtual_knockout reads adata.X if layer is omitted result = virtual_knockout(adata, ko_genes=["GeneA"]) ``` -------------------------------- ### Class API example Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/README.md Example usage of the scTenifoldNet class API. ```python from scTenifold.data import get_test_df from scTenifold import scTenifoldNet df_1 = get_test_df(n_cells=1000) df_2 = get_test_df(n_cells=1000) sc = scTenifoldNet( df_1, df_2, "X", "Y", qc_kws={"min_lib_size": 10}, nc_kws={"backend": "serial", "n_jobs": 1}, ) result = sc.build() ``` -------------------------------- ### Compare Two Conditions: ``compare_networks`` Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/quickstart.md This code snippet demonstrates how to compare two conditions using the `compare_networks` function from the scTenifold library. It includes data loading, network comparison, and printing the head of the results. ```python from scTenifold import compare_networks from scTenifold.data import get_test_df x = get_test_df(n_cells=200, n_genes=300, random_state=0) y = get_test_df(n_cells=200, n_genes=300, random_state=1) result = compare_networks( x, y, x_label="ctrl", y_label="cond", qc_kws={"min_lib_size": 1}, network_kws={"n_nets": 3, "n_samp_cells": 100}, backend="serial", ) print(result.head()) ``` -------------------------------- ### Optional extras installation with uv Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/README.md Install scTenifoldpy with optional extras like scanpy or parallel-ray using uv. ```bash uv venv uv add "scTenifoldpy[scanpy]" uv add "scTenifoldpy[parallel-ray]" ``` -------------------------------- ### Run CLI from Docker Container Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Runs the scTenifold CLI from a Docker container, mounting the current directory. ```bash docker run --rm -v "$PWD:/workspace" sctenifoldpy scTenifold --help ``` -------------------------------- ### Virtual Knockout: ``virtual_knockout`` Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/quickstart.md This code snippet shows how to perform a virtual knockout experiment using the `virtual_knockout` function. It involves loading data, specifying genes to knockout, and printing the sorted results by p-value. ```python from scTenifold import virtual_knockout from scTenifold.data import get_test_df data = get_test_df(n_cells=300, n_genes=300, random_state=0) result = virtual_knockout( data, ko_genes=["NG-1"], qc_kws={"min_lib_size": 1, "min_exp_avg": 0, "min_exp_sum": 0}, network_kws={"n_nets": 3, "n_samp_cells": 100}, ko_method="default", ) print(result.sort_values("p-value").head()) ``` -------------------------------- ### CLI commands Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/README.md Example commands for using the scTenifold Command Line Interface. ```bash scTenifold config -t 1 -p ./net_config.yml scTenifold net -c ./net_config.yml -o ./output_folder scTenifold knk -c ./knk_config.yml -o ./output_folder ``` -------------------------------- ### Run CLI from Docker Container (PowerShell) Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/installation.md Runs the scTenifold CLI from a Docker container using PowerShell, mounting the current directory. ```powershell docker run --rm -v "${PWD}:/workspace" sctenifoldpy scTenifold --help ``` -------------------------------- ### Optional extras installation with pip Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/README.md Install scTenifoldpy with optional extras like scanpy or parallel-ray using pip. ```bash pip install "scTenifoldpy[scanpy]" pip install "scTenifoldpy[parallel-ray]" ``` -------------------------------- ### d_regulation example 1 Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Example of calling d_regulation with default parameters. ```python d_reg_df = d_regulation(ma_df) ``` -------------------------------- ### compare_networks usage Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/parallel-backends.md Example of using the compare_networks function, demonstrating how backend and n_jobs are propagated, and how network_kws can be used. ```python result = compare_networks( x, y, backend="joblib-loky", n_jobs=8, network_kws={"n_nets": 10}, # backend/n_jobs propagated automatically ) ``` -------------------------------- ### d_regulation example 2 Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Example of calling d_regulation with custom boxcox and chi2 parameters. ```python d_reg_df = d_regulation(ma_df, boxcox_kws={\"lmbda\": 0}, chi2_kws={\"df\": 1}) ``` -------------------------------- ### Merging overrides Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/pipeline-steps.md Example of how to merge keyword arguments into the stored configuration for a step. ```python model.nc_kws["n_jobs"] = 4 model.run_step("nc") ``` -------------------------------- ### Running a single step with overrides Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/pipeline-steps.md Example of how to run a single pipeline step and pass keyword arguments that override default settings for that specific call. ```python model.run_step("nc", n_nets=5, backend="joblib-loky", n_jobs=4) ``` -------------------------------- ### make_networks usage Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/parallel-backends.md Example of using the make_networks function with the 'joblib-loky' backend and specifying the number of jobs. ```python from scTenifold import make_networks nets = make_networks(data, n_nets=10, backend="joblib-loky", n_jobs=4) ``` -------------------------------- ### Inspecting state after a step Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/pipeline-steps.md Examples of inspecting the populated attributes after running specific pipeline steps. ```python model.run_step("qc") print(model.QC_dict["ctrl"].shape) model.run_step("nc") print([net.shape for net in model.network_dict["ctrl"]]) ``` -------------------------------- ### AnnData Round-trip Conversion Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/anndata.md Example showing how to convert an AnnData object to a pandas DataFrame using anndata_to_dataframe and verifying the index and columns. ```python import anndata as ad from scTenifold.core._networks import anndata_to_dataframe adata = ad.read_h5ad("sample.h5ad") df = anndata_to_dataframe(adata, layer="counts") assert df.index.equals(adata.var_names) assert df.columns.equals(adata.obs_names) ``` -------------------------------- ### Data Preparation Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/3_knock_out.ipynb Imports necessary libraries and loads test data. ```python from scTenifold import scTenifoldKnk, virtual_knockout from scTenifold.data import get_test_df data = get_test_df(n_cells=80, n_genes=40, random_state=2) ko_genes = ["NG-1"] ``` -------------------------------- ### Step-wise workflow using scTenifoldNet class Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/2_build_network.ipynb Initializes the scTenifoldNet model and runs through the analysis steps sequentially. ```python model = scTenifoldNet( x, y, x_label="control", y_label="condition", qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0}, nc_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0, "backend": "serial"}, td_kws={"K": 2, "max_iter": 20, "init": "random"}, ma_kws={"d": 2}, ) for step in ["qc", "nc", "td", "ma", "dr"]: model.run_step(step) model.d_regulation.head() ``` -------------------------------- ### Build a small result using the class API Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/4_visualization.ipynb Initializes and builds a scTenifoldNet model with specified parameters for quality control, network construction, tensor decomposition, and manifold alignment. ```python model = scTenifoldNet( x, y, "control", "condition", qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0}, nc_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0, "backend": "serial"}, td_kws={"K": 2, "max_iter": 20, "init": "random"}, ma_kws={"d": 2}, ) model.build() ``` -------------------------------- ### Import necessary libraries and load test data Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/2_build_network.ipynb Imports scTenifold components and loads sample expression data for two conditions. ```python from scTenifold import compare_networks, scTenifoldNet from scTenifold.data import get_test_df x = get_test_df(n_cells=80, n_genes=40, random_state=0) y = get_test_df(n_cells=80, n_genes=40, random_state=1) ``` -------------------------------- ### Import necessary libraries and load test data Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/4_visualization.ipynb Imports plotting and data handling functions from scTenifold and loads test dataframes. ```python %matplotlib inline from scTenifold import compare_networks, scTenifoldNet from scTenifold.data import get_test_df from scTenifold.plotting import plot_hist, plot_network_heatmap, plot_qqplot x = get_test_df(n_cells=80, n_genes=40, random_state=0) y = get_test_df(n_cells=80, n_genes=40, random_state=1) ``` -------------------------------- ### Displaying gene and cell names Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/1_data.ipynb Shows how to inspect the first few gene and cell names from the DataFrame. ```python x.index[:5].tolist(), x.columns[:5].tolist() ``` -------------------------------- ### build() Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Runs the entire scTenifoldKnk pipeline. ```python build() -> DataFrame ``` -------------------------------- ### One-call workflow using compare_networks() Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/2_build_network.ipynb Compares two networks using the `compare_networks` function with specified parameters for a quick analysis. ```python result = compare_networks( x, y, x_label="control", y_label="condition", qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0}, network_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0}, backend="serial", td_kws={"K": 2, "max_iter": 20, "init": "random"}, ma_kws={"d": 2}, ) result.head() ``` -------------------------------- ### Run scTenifoldKnk Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/cli.md Command to run scTenifoldKnk using a specified configuration file. ```shell python -m scTenifold knk -c ./knk_config.yml -o ./outputs ``` -------------------------------- ### load_config() Class Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Constructs a scTenifoldKnk instance from a configuration dictionary, loading data from disk as specified. ```python load_config(config: Dict[str, object]) -> [scTenifoldKnk](#scTenifold.scTenifoldKnk) ``` -------------------------------- ### AnnData to DataFrame conversion Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/1_data.ipynb Illustrates converting a custom AnnData-like object to a pandas DataFrame using scTenifoldpy's utility function. ```python from scTenifold.core._networks import anndata_to_dataframe class MiniAnnData: def __init__(self, matrix, obs_names, var_names): self.X = matrix self.obs_names = obs_names self.var_names = var_names self.layers = {} adata = MiniAnnData(x.T.to_numpy(), obs_names=x.columns, var_names=x.index) converted = anndata_to_dataframe(adata) converted.equals(x) ``` -------------------------------- ### Run scTenifoldNet Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/cli.md Command to run scTenifoldNet using a specified configuration file. ```shell python -m scTenifold net -c ./net_config.yml -o ./outputs ``` -------------------------------- ### Step-wise workflow Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/3_knock_out.ipynb Utilizes the class API for a step-by-step workflow, exposing intermediate results. ```python knk = scTenifoldKnk( data=data, ko_genes=ko_genes, qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0, "min_exp_avg": 0, "min_exp_sum": 0}, nc_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0, "backend": "serial"}, td_kws={"K": 2, "max_iter": 20, "init": "random"}, ma_kws={"d": 2}, ko_method="default", ) for step in ["qc", "nc", "td", "ko", "ma", "dr"]: knk.run_step(step) knk.d_regulation.head() ``` -------------------------------- ### One-call workflow Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/3_knock_out.ipynb Uses the `virtual_knockout` function for a simplified workflow. ```python result = virtual_knockout( data, ko_genes=ko_genes, qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0, "min_exp_avg": 0, "min_exp_sum": 0}, network_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0}, ko_method="default", td_kws={"K": 2, "max_iter": 20, "init": "random"}, ma_kws={"d": 2}, ) result.sort_values("p-value").head() ``` -------------------------------- ### Run Workflows Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/cli.md Commands to execute the scTenifoldNet and scTenifoldKnk workflows using generated configuration files. ```bash scTenifold net --config net_config.yml --output ./saved_net scTenifold knk --config knk_config.yml --output ./saved_knk ``` -------------------------------- ### get_empty_config() Class Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Returns a blank configuration dictionary for scTenifoldKnk, pre-populated with default values for each step. ```python get_empty_config() -> Dict[str, object] ``` -------------------------------- ### scTenifoldKnk Constructor Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Initializes the scTenifoldKnk class for single-sample virtual knockout analysis. It outlines the pipeline order and parameters for various steps. ```python class scTenifold.scTenifoldKnk(data: DataFrame | AnnDataLike, strict_lambda: float = 0, ko_method: Literal['default', 'propagation'] = 'default', ko_genes: str | Iterable[str] | None = None, qc_kws: Dict[str, object] | None = None, nc_kws: Dict[str, object] | None = None, td_kws: Dict[str, object] | None = None, ma_kws: Dict[str, object] | None = None, dr_kws: Dict[str, object] | None = None, ko_kws: Dict[str, object] | None = None) ``` -------------------------------- ### Generate Config File Template Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/cli.md Command to generate a configuration file template for scTenifold. ```shell python -m scTenifold config -t 1 -p ./net_config.yml ``` -------------------------------- ### Intermediate model outputs Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/2_build_network.ipynb Displays shapes of intermediate data structures within the scTenifoldNet model after running the steps. ```python { "qc_shape": model.QC_dict["control"].shape, "n_networks": len(model.network_dict["control"]), "tensor_shape": model.tensor_dict["control"].shape, "manifold_shape": model.manifold.shape, } ``` -------------------------------- ### Generate Configuration Files Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/cli.md Commands to generate YAML configuration files for scTenifoldNet and scTenifoldKnk. ```bash scTenifold config --type 1 --path net_config.yml # scTenifoldNet scTenifold config --type 2 --path knk_config.yml # scTenifoldKnk ``` -------------------------------- ### scTenifoldNet.load_config() Class Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Constructs a scTenifoldNet object from a configuration dictionary, loading data from specified paths. ```python load_config(config: Dict[str, object]) -> [scTenifoldNet](#scTenifold.scTenifoldNet) ``` -------------------------------- ### scTenifoldNet Class Constructor Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Initializes a two-sample scTenifoldNet workflow. The pipeline includes QC, network construction, tensor decomposition, manifold alignment, and differential regulation. ```python scTenifoldNet(x_data: DataFrame | AnnDataLike, y_data: DataFrame | AnnDataLike, x_label: str, y_label: str, qc_kws: Dict[str, object] | None = None, nc_kws: Dict[str, object] | None = None, td_kws: Dict[str, object] | None = None, ma_kws: Dict[str, object] | None = None, dr_kws: Dict[str, object] | None = None) ``` -------------------------------- ### scTenifoldKnk Pipeline Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/pipeline-steps.md The sequence of steps in the scTenifoldKnk pipeline, highlighting differences from scTenifoldNet. ```text data_dict -> qc -> QC_dict -> nc -> network_dict["WT"] -> td -> tensor_dict["WT"] -> ko -> tensor_dict["KO"] -> ma -> manifold -> dr -> d_regulation ``` -------------------------------- ### run_step() Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Executes a single step within the scTenifoldKnk pipeline. Steps must be run sequentially. ```python run_step(step_name: Literal['qc', 'nc', 'td', 'ko', 'ma', 'dr'], **kwargs: object) -> None ``` -------------------------------- ### Plot histogram of control data Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/4_visualization.ipynb Generates and displays a histogram for the control dataset. ```python plot_hist(x, "control") ``` -------------------------------- ### Intermediate Tensor Shapes Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/3_knock_out.ipynb Displays the shapes of the WT tensor, KO tensor, and manifold. ```python { "wt_tensor": knk.tensor_dict["WT"].shape, "ko_tensor": knk.tensor_dict["KO"].shape, "manifold": knk.manifold.shape, } ``` -------------------------------- ### scTenifoldNet.run_step() Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Executes a single step within the scTenifoldNet pipeline. Steps must be run sequentially. ```python run_step(step_name: Literal['qc', 'nc', 'td', 'ma', 'dr'], **kwargs: object) -> None ``` -------------------------------- ### Plot network heatmap Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/4_visualization.ipynb Visualizes the network structure of the control data as a heatmap. ```python plot_network_heatmap(model.tensor_dict["control"].to_numpy()) ``` -------------------------------- ### Differential regulation QQ plot Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/4_visualization.ipynb Generates a QQ plot to visualize the differential regulation between conditions. ```python plot_qqplot(model.d_regulation) ``` -------------------------------- ### scTenifoldNet Pipeline Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/pipeline-steps.md The sequence of steps in the scTenifoldNet pipeline. ```text data_dict -> qc -> QC_dict -> nc -> network_dict -> td -> tensor_dict -> ma -> manifold -> dr -> d_regulation ``` -------------------------------- ### get_data method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Method to return simulated data packaged for downstream scorers. ```python def get_data(data_type: str, use_normalized: bool) -> Dict[str, object] ``` -------------------------------- ### fetch_data function Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Function to fetch and load a remote scTenifold dataset by name. ```python def fetch_data(ds_name: str, dataset_path: Path = PosixPath('/workspace/input/datasets'), owner: str = 'qwerty239qwe') -> Dict[str, DataFrame] ``` -------------------------------- ### list_data function Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Function to list available scTenifold datasets. ```python def list_data(owner: str = 'qwerty239qwe', return_list: bool = True) -> Dict[str, Dict[str, List[str]]] | List[str] ``` -------------------------------- ### Reload Model from Disk Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/cli.md Python code to load a saved scTenifoldNet model from disk and display the head of its d_regulation attribute. ```python from scTenifold import scTenifoldNet model = scTenifoldNet.load("./saved_net") print(model.d_regulation.head()) ``` -------------------------------- ### Selective Save Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/workflow-output.md By default save() writes every step that has run. Pass comps to restrict which components are saved. ```python model.save("./saved_net", comps=["qc", "dr"]) ``` -------------------------------- ### save_data method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Method to save the simulated count matrix as CSV. ```python def save_data(file_path: str | Path, use_normalized: bool) -> None ``` -------------------------------- ### get_test_df function Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Function to generate a test dataframe. ```python def get_test_df(n_cells: int = 100, n_genes: int = 1000, random_state: int | None = None) -> DataFrame ``` -------------------------------- ### save() Method Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Saves the current state of the scTenifoldKnk object, including KO-specific fields, to allow for later reconstruction using the load() method. ```python save(file_dir: str | Path, comps: str | List[str] = 'all', verbose: bool = True, **kwargs: object) -> None ``` -------------------------------- ### read_folder function Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Function to read mtx, genes, and barcodes from a directory. ```python def read_folder(file_dir: str | Path, matrix_fn: str = 'matrix', gene_fn: str = 'genes', barcodes_fn: str = 'barcodes') -> DataFrame ``` -------------------------------- ### Saving workflow output Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/workflow-output.md Persists all populated steps and configuration to disk. The load() function reconstructs the object, including intermediate state, without re-running any step. ```python scTenifoldNet.save(dir) scTenifoldKnk.save(dir) ``` -------------------------------- ### Reloading workflow output Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/workflow-output.md Reconstructs the object from a saved directory, including intermediate state. ```python from scTenifold import scTenifoldNet, scTenifoldKnk net = scTenifoldNet.load("./saved_net") knk = scTenifoldKnk.load("./saved_knk") ``` -------------------------------- ### read_mtx function Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Function to read mtx data from specified files. ```python def read_mtx(mtx_file_name: str | Path, gene_file_name: str | Path, barcode_file_name: str | Path | None) -> DataFrame ``` -------------------------------- ### TestDataGenerator Class Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/scTenifold.data.md Class for generating test data for cell scoring functions. ```python class scTenifold.data.TestDataGenerator(n_genes: int = 1000, n_samples: int = 100, pos_eff_ratio: float = 0.3, neg_eff_ratio: float = 0, target_pos: Sequence[str] | None = None, target_neg: Sequence[str] | None = None, n_bins: int = 25, n_ctrl: int = 50, random_state: int = 42) ``` -------------------------------- ### sc_QC Function Source: https://github.com/qwerty239qwe/sctenifoldpy/blob/master/docs/source/api.md Performs quality control and CPM normalization on single-cell RNA-seq data. ```python sc_QC(X: DataFrame, min_lib_size: float = 1000, remove_outlier_cells: bool = True, min_percent: float = 0.05, max_mito_ratio: float = 0.1, min_exp_avg: float = 0, min_exp_sum: float = 0) -> DataFrame ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.