Development¶
This page is a quick reference for contributors who want to extend SFA with new algorithms, datasets, or analyses.
Package layout¶
| Path | Purpose |
|---|---|
sfa/base.py |
Algorithm, Data, Result, ContainerItem base types. |
sfa/containers.py |
AlgorithmSet and DataSet singletons. |
sfa/fileio.py |
read_sif, read_inputs, create_from_sif. |
sfa/utils.py |
Matrix utilities, randomization, singleton helper. |
sfa/topology.py |
max_spl, splo (shortest path lengths). |
sfa/stats.py |
Accuracy helpers (calc_accuracy). |
sfa/algorithms/ |
One module per algorithm; np.py and sp.py shipped. |
sfa/data/<dataset>/ |
One subpackage per dataset, with network.sif, etc. |
sfa/analysis/ |
Perturbation analysis and random batch simulators. |
sfa/control/ |
Influence matrix and target prioritization. |
sfa/plot/ |
Matplotlib-based plotters. |
sfa/vis/ |
Graph annotation and the optional SFV integration. |
Adding a new algorithm¶
- Create
sfa/algorithms/<name>.py. The filename, uppercased, becomes the key used byAlgorithmSet. - Define a
create_algorithm(abbr)factory that returns an instance of a subclass ofsfa.base.Algorithm(typicallyNetworkPropagation). - Implement
compute(b)andcompute_batch(), or — for network propagation variants — overridepropagate_iterativeand optionallypropagate_exact. - Reuse
NetworkPropagationParameterSetand add any custom hyperparameters as properties on aFrozenClasssubclass.
AlgorithmSet().create('YOURALG') will discover the module
automatically. See the Algorithm page for a full
template.
Adding a new dataset¶
- Create
sfa/data/<name>/__init__.pyand add at leastnetwork.sifand anyconds.tsv,exp.tsv,ptb.tsvfiles you wantDataSetto load. The directory name, uppercased, becomes the key (borisov_2009→BORISOV_2009). - The
__init__.pymust expose acreate_data()factory. It may return:- a single
sfa.base.Datasubclass instance, - a
listof instances (will be keyed by eachdata.abbr.upper()), - or a
dictof pre-built instances.
- a single
- Use
sfa.read_sif(fpath, as_nx=True)to populate_A,_n2i, and_dg; usepd.read_csv(..., sep='\t')for the TSV files.
See sfa/data/borisov_2009/__init__.py and
sfa/data/korkut_2015a/__init__.py for working examples.
Coding conventions¶
- Target Python 3.7 and newer; the codebase no longer carries Python 2 compatibility shims.
- Prefer explicit dtypes (
np.float64,int) over the legacy aliasesnp.float/np.int, which were removed in NumPy 1.20. - Use
pd.read_csv(..., sep='\t')instead of the deprecatedpd.read_table. - For matrix-shape operations on adjacency matrices, work with NumPy
ndarrays directly —.to_numpy()is apandasmethod and does not exist onndarray.
Building the documentation¶
Documentation is written in Markdown and built by MkDocs with the Material theme and mkdocstrings for the API reference.
$ pip install -r docs-requirements.txt
$ mkdocs serve # Local preview on http://127.0.0.1:8000/
$ mkdocs build # Static site in ./site/
Read the Docs picks up .readthedocs.yaml automatically; pushing to the
default branch triggers a fresh build at https://sfa.readthedocs.io.