Network Functions
Core functions for expression conversion, PC network construction, manifold alignment, differential regulation, and edge-direction pruning.
Inputs and Network Construction
anndata_to_dataframe
anndata_to_dataframe(
data: ExpressionData, layer: LayerName = None
) -> pd.DataFrame
Convert a pandas or AnnData-like object to genes x cells DataFrame.
Source code in scTenifold/core/_networks.py
22 23 24 25 26 27 28 29 30 31 32 33 | |
make_networks
make_networks(
data: ExpressionData,
n_nets: int = 10,
n_samp_cells: Optional[int] = 500,
n_comp: int = 3,
scale_scores: bool = True,
symmetric: bool = False,
q: float = 0.95,
random_state: int = 42,
backend: Backend = "serial",
n_jobs: int = 1,
n_cpus: Optional[int] = None,
replace: bool = True,
layer: LayerName = None,
**kwargs: object,
) -> List[coo_matrix]
Make PCNets from a data frame by subsampling the cells
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ExpressionData
|
Input dataframe |
required |
n_nets
|
int
|
Number of subsampling times |
10
|
n_samp_cells
|
Optional[int]
|
Number of sampled cells, if None than select all cells |
500
|
n_comp
|
int
|
Number of PCNets composition |
3
|
scale_scores
|
bool
|
To scale the final PCNets scores or not |
True
|
symmetric
|
bool
|
To make the final PCNets symmetric or not |
False
|
q
|
float
|
The quantile value used to determine PCNet's threshold |
0.95
|
random_state
|
int
|
Random seed of constructing PCNets |
42
|
backend
|
Backend
|
Parallel backend: "serial", "joblib-loky", "joblib-threading", or "ray" |
'serial'
|
n_jobs
|
int
|
Number of workers for parallel backends. -1 uses the backend default. |
1
|
n_cpus
|
Optional[int]
|
Deprecated alias for n_jobs. |
None
|
kwargs
|
object
|
Keyword arguments |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
networks |
List[coo_matrix]
|
A list contains PCNets (in coo sparse matrix format) |
Source code in scTenifold/core/_networks.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
cal_pcNet
cal_pcNet(
data: ExpressionData,
n_comp: int = 3,
scale_scores: bool = True,
symmetric: bool = False,
q: float = 0.95,
random_state: int = 42,
**kwargs: object,
) -> coo_matrix
Calculate one pcNet without sampling. An API for getting one PCNet instead of many.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ExpressionData
|
Input dataframe |
required |
n_comp
|
int
|
Number of PCNets composition |
3
|
scale_scores
|
bool
|
To scale the final PCNets scores or not |
True
|
symmetric
|
bool
|
To make the final PCNets symmetric or not |
False
|
q
|
float
|
The quantile value used to determine PCNet's threshold |
0.95
|
random_state
|
int
|
Random seed of constructing PCNets |
42
|
kwargs
|
object
|
Keyword arguments |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
pcNet |
coo_matrix
|
|
Result network
|
|
See Also
make_networks
Source code in scTenifold/core/_networks.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
Alignment and Differential Regulation
manifold_alignment
manifold_alignment(
X: DataFrame,
Y: DataFrame,
d: int = 30,
tol: float = 1e-08,
**kwargs: object,
) -> pd.DataFrame
Performing manifold alignment on two dataframes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
A gene regulatory network X, expected shape = (n_genes, n_genes) |
required |
Y
|
DataFrame
|
A gene regulatory network Y, expected shape = (n_genes, n_genes) |
required |
d
|
int
|
The dimension of the low-dimensional feature space |
30
|
tol
|
float
|
The tolerance of eigen values |
1e-08
|
Returns:
| Name | Type | Description |
|---|---|---|
ma_df |
DataFrame
|
A dataframe contains manifold alignment result, expected shape = (n_genes * 2, d) |
Source code in scTenifold/core/_networks.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
d_regulation
d_regulation(
data: DataFrame,
sorted_by: Union[str, list] = "p-value",
ascending: Union[bool, list] = True,
**kwargs: object,
) -> pd.DataFrame
Evaluates the difference in regulation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
A dataframe contains manifold alignment results, expected shape = (n_genes * 2, d) |
required |
sorted_by
|
Union[str, list]
|
Name or list of names to sort by |
'p-value'
|
ascending
|
Union[bool, list]
|
Sorted ascending (otherwise descending) |
True
|
**kwargs
|
object
|
Keyword arguments for statistic analyses, and n_ko_genes (if any) boxcox_kws - kwargs for boxcox test chi2_kws - kwargs for chi-square test n_ko_genes - int, indicating the number of KO genes |
{}
|
Examples:
d_reg_df = d_regulation(ma_df)
d_reg_df = d_regulation(ma_df, boxcox_kws={"lmbda": 0}, chi2_kws={"df": 1})
Returns:
| Name | Type | Description |
|---|---|---|
d_reg_df |
DataFrame
|
A dataFrame contains difference in regulation result sorted by p-value columns: ["Gene", "Distance", "boxcox-transformed distance", "Z", "FC", "p-value", "adjusted p-value"] |
Source code in scTenifold/core/_networks.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
strict_direction
strict_direction(
data: ndarray, lambd: float = 1
) -> np.ndarray
Enforce edge directionality by zeroing the weaker of each (i, j) / (j, i) pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Square adjacency matrix. |
required |
lambd
|
float
|
Interpolation weight between the original and strict matrix (0 = original, 1 = strict). |
1
|
Returns:
| Type | Description |
|---|---|
Adjacency with directionality applied.
|
|
Source code in scTenifold/core/_networks.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |