sfa package

Subpackages

Module contents

class sfa.Algorithm(abbr)[source]

Bases: sfa.base.ContainerItem

The base class of Algorithm classes.

Examples

>>> class AnAlgorithm(sfa.base.Algorithm):
        # Definition of algorithm ...
        ...
>>> alg = AnAlgorithm()
>>> alg.params = params_obj # Parameters of the algorithm
>>> alg.data = data_obj # Data to be analyzed by the algorithm
>>> alg.initialize()
>>> res = alg.compute()
Attributes
abbrstr

Abbreviation or symbol representing this item.

namestr

Full name or description of this item.

datasfa.base.Data

The object of sfa.base.Data.

paramssfa.base.ParameterSet

The object of sfa.base.ParameterSet.

resultsfa.base.Result

The object of sfa.base.Result.

Methods

compute(self, b)

Process the assigned data

compute_batch(self)

Process the assigned data that contains a batch data.

initialize_basal_activity(self)

Initialize the basal activity, \(b\).

initialize_network(self)

Initialize the data structures related to network.

copy

initialize

compute(self, b)[source]
Process the assigned data

with the given basal activity, \(b\).

Parameters
bnumpy.ndarray

1D array of basal activity.

Returns
xnumpy.ndarray

1D-array object of activity at steady-state.

compute_batch(self)[source]

Process the assigned data that contains a batch data. The result is stored in result member.

copy(self, is_deep=False)[source]
data

The object of sfa.base.Data. Data to be processed based on the algorithm can accessed through this member.

initialize(self, network=True, ba=True)[source]
initialize_basal_activity(self)[source]

Initialize the basal activity, \(b\).

initialize_network(self)[source]

Initialize the data structures related to network.

params

The object of sfa.base.ParameterSet. Parameters of the algorithm can accessed through this member.

result

The object of sfa.base.Result. The result of computing the batch.

class sfa.Data[source]

Bases: sfa.base.ContainerItem

Attributes
A
abbr

Abbreviation or symbol representing this item.

df_conds
df_exp
df_ptb
dg
has_link_perturb
i2n
iadj_to_idf
inputs
n2i
name

Full name or description of this item.

names_ptb
vals_ptb

Methods

initialize

A
df_conds
df_exp
df_ptb
dg
i2n
iadj_to_idf
initialize(self, fpath, fname_network='network.sif', fname_ptb='ptb.tsv', fname_conds='conds.tsv', fname_exp='exp.tsv', inputs={})[source]
inputs
n2i
names_ptb
vals_ptb
class sfa.Result[source]

Bases: sfa.utils.FrozenClass

Attributes
df_sim
df_sim
class sfa.AlgorithmSet(*args, **kwargs)

Bases: sfa.containers.AlgorithmSet

Methods

clear(self)

create(self[, keys])

Create a single or multiple objects according to keys.

get(self, key[, default])

items(self)

keys(self)

pop(self, key[, default])

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem(self)

as a 2-tuple; but raise KeyError if D is empty.

setdefault(self, key[, default])

update(\*args, \*\*kwds)

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values(self)

get_all_keys

class sfa.DataSet(*args, **kwargs)

Bases: sfa.containers.DataSet

Methods

clear(self)

create(self[, keys])

Create a single or multiple objects according to keys.

get(self, key[, default])

items(self)

keys(self)

pop(self, key[, default])

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem(self)

as a 2-tuple; but raise KeyError if D is empty.

setdefault(self, key[, default])

update(\*args, \*\*kwds)

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values(self)

get_all_keys

sfa.calc_accuracy(df1, df2, get_cons=False)[source]

Count the same sign of each element between df1 and df2

df1: pandas.DataFrame or numpy.ndarray to be compared df2: pandas.DataFrame or numpy.ndarray to be compared getcons: decide whether to return consensus array in DataFrame or not

class sfa.FrozenClass[source]

Bases: object

sfa.Singleton(_class)[source]
sfa.to_networkx_digraph(A, n2i=None)[source]
sfa.normalize(A, norm_in=True, norm_out=True)[source]
sfa.rand_swap(A, nsamp=10, noself=True, pivots=None, inplace=False)[source]

Randomly rewire the network connections by swapping.

Parameters
Anumpy.ndarray

Adjacency matrix (connection matrix).

nsampint, optional

Number of sampled connections to rewire

noselfbool, optional

Whether to allow self-loop link.

pivotslist, optional

Indices of pivot nodes

inplacebool, optional

Modify the given adjacency matrix for rewiring.

Returns
Bnumpy.ndarray

The randomized matrix. The reference of the given W is returned, when inplace is True.

sfa.rand_flip(A, nsamp=10, pivots=None, inplace=False)[source]

Randomly flip the signs of connections.

Parameters
Anumpy.ndarray

Adjacency matrix (connection matrix).

nsampint, optional

Number of sampled connections to be flipped.

pivotslist, optional

Indices of pivot nodes

inplacebool, optional

Modify the given adjacency matrix for rewiring.

Returns
Bnumpy.ndarray

The randomized matrix. The reference of the given W is returned, when inplace is True.

sfa.rand_weights(W, lb=-3, ub=3, inplace=False)[source]

Randomly sample the weights of connections in W from 10^(lb, ub).

Parameters
Wnumpy.ndarray

Adjacency (connection) or weight matrix.

lbfloat, optional

The 10’s exponent for lower bound

inplacebool, optional

Modify the given adjacency matrix for rewiring.

Returns
Bnumpy.ndarray

The randomly sampled weight matrix. The reference of the given W is returned, when inplace is True.

sfa.rand_structure(A, nswap=10, nflip=10, noself=True, pivots=None, inplace=False)[source]
sfa.get_akey(d)[source]

Get a key from a given dictionary. It returns the first key in d.keys().

Parameters
ddict

Dictionary of objects.

Returns
objobject

First item of iter(d.keys()).

sfa.get_avalue(d)[source]

Get a value from a given dictionary. It returns the value designated by sfa.get_akey().

Parameters
ddict

Dictionary of objects.

Returns
objobject

First item of d[iter(d.keys())].

sfa.max_spl(nxdg)[source]

Find the maximum length of the shortest path

sfa.splo(nxdg, sources, outputs, rtype='df')[source]

Calculate the shortest path length from each source node to the outputs. SPLO represents ‘shortest path length to output’.

Parameters
nxdg: NetworkX.DiGraph

A directed network in NetworkX.

sources: list (or iterable) of str

Names of source nodes in nxdg.

outputs: list (or iterable) of str

Names of output nodes in nxdg.

rtype: str (optional)

Return object type: ‘df’ or ‘dict’.

Returns
splo: dict

All the shortest path lengths to the outputs.

sfa.read_inputs(fpath)[source]
sfa.read_sif(fpath, signs={'+': 1, '-': -1}, sort=True, as_nx=False)[source]
sfa.create_from_sif(fpath, abbr=None, inputs=None, outputs=None)[source]

Create sfv.base.Data object from SIF file.

Parameters
fpathstr

Absolute path of SIF file

abbrstr

Abbreviation to denote this data object for the network.

inputsdict, optional

Input information with default values

outputssequence, optional

Output information.

Returns
objsfv.base.Data

Data object with the information of network topology.