Skip to main content

PyNetCor is a fast Python C++ extension for correlation and network analysis

Project description

pyNetCor

PyNetCor is a fast Python C++ extension for correlation and network analysis on high-dimensional datasets. It aims to serve as a scalable foundational package to accelerate large-scale computations.

Features

  • Calculate correlation matrix using Pearson, Spearman, or Kendall methods
  • Processing large-scale computation in chunks (larger than RAM)
  • Find top-k and differential correlations between each row of two arrays
  • Efficient P-value approximation and multiple testing correction
  • Handle missing values
  • Multi-thread

Installation

You can install pyNetCor using pip:

pip install pynetcor

Quick Start

Create Data

import numpy as np

features = 100000
sampes = 100
arr1 = np.random.random((features, samples))
arr2 = np.random.random((features, samples))

Calculate correlation matrix

Compute and return the full matrix at once.

from pynetcor.cor import corrcoef

# using 8 threads
# Pearson correlations between `arr1` and itself
cor_result = corrcoef(arr1, threads=8)

Compute the matrix in chunks and return an Iterator, recommended for large-scale analysis that exceed RAM.

from pynetcor.cor import chunked_corrcoef

# Calculate and return `chunk_size=1024` rows of the correlation matrix with each iteration.
cor_iter = chunked_corrcoef(arr1, chunk_size=1024, threads=8)
for cor_chunk_matrix in cor_iter:
    ...

Top-k correlation search

Identify the accurate top k correlations (Spearman correlation).

from pynetcor.cor import cor_topk

# top 1% correlations
cor_topk_result = cor_topk(arr1, method="spearman", k=0.001, threads=8)

# top 100 correlations
cor_topk_result = cor_topk(arr1, method="spearman", k=100, threads=8)

# Return a 2D array with 4 columns: [row_index, col_index, correlation, pvalue]

Top-k differential correlation search

Identify the accurate top k differences in correlation between pairs of features across two states or time points.

# Compute the pairwise correlations separately for `arr1` with `arr1`, and `arr2` with `arr2`, then identify the feature pairs with the largest difference
from pynetcor.cor import cor_topkdiff

# top 1% differential correlations
cor_topkdiff_result = cor_topkdiff(x1=arr1, y1=arr2, x2=arr1, y2=arr2, k=0.001, threads=8)

# top 100 differential correlations
cor_topkdiff_result = cor_topkdiff(x1=arr1, y1=arr2, x2=arr1, y2=arr2, k=100, threads=8)

# Return a 2D array with 5 columns: [row_index, col_index, diffCor, cor1, cor2]

P-value computation

Compute the P-values for correlations (Pearson or Spearman) using the Student's t-distribution. The approximation method is significantly faster than the classical method, with the absolute errors are nearly less than 1e-8.

from pynetcor.cor import corrcoef, pvalue_student_t
samples = arr1.shape[1]

# Generate the Pearson correlation matrix
cor_result = corrcoef(arr1, threads=8)

# P-value approximation
pvalue_result = pvalue_student_t(cor_result, df=samples-2, approx=True, threads=8)

# P-value classic
pvalue_result = pvalue_student_t(cor_result, df=samples-2, approx=False, threads=8)

Unified implementation for calculating correlations and P-values.

from pynetcor.cor import cortest, chunked_cortest

# Pearson correlation & P-value approximation
cortest_result = cortest(arr1, approx=True, threads=8)

# chunking computation, recommended for large-scale analysis that exceed RAM
for iter in chunked_cortest(arr1, approx=True, threads=8):
    for (row_index, col_index, correlation, pvalue) in iter:
        ...
        
# Return a 2D array with 4 columns: [row_index, col_index, correlation, pvalue]

Multiple testing correction: holm, hochberg, bonferroni, BH, BY.

from pynetcor.cor import cortest, chunked_cortest

# Pearson correlation & multiple testing correction
cortest_result = cortest(arr1, adjust_pvalue=True, adjust_method="BH", threads=8)

# chunking computation, recommended for large-scale analysis that exceed RAM
for iter in chunked_cortest(arr1, adjust_pvalue=True, adjust_method="BH", threads=8):
    for (row_index, col_index, correlation, pvalue) in iter:
        ...
        
# Return a 2D array with 5 columns: [row_index, col_index, correlation, pvalue, adjusted_pvalue]       

NOTE: chunked function only supports approximate adjusted P-value. PyNetCor utilizes approximation methods to achieve effective FDR control before computing all P-values.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pynetcor-0.1.1-cp312-cp312-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.12Windows x86-64

pynetcor-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pynetcor-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pynetcor-0.1.1-cp311-cp311-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.11Windows x86-64

pynetcor-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pynetcor-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

pynetcor-0.1.1-cp310-cp310-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.10Windows x86-64

pynetcor-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pynetcor-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

pynetcor-0.1.1-cp39-cp39-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.9Windows x86-64

pynetcor-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pynetcor-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

pynetcor-0.1.1-cp38-cp38-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.8Windows x86-64

pynetcor-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

pynetcor-0.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

pynetcor-0.1.1-cp37-cp37m-win_amd64.whl (7.8 MB view details)

Uploaded CPython 3.7mWindows x86-64

pynetcor-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

pynetcor-0.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

File details

Details for the file pynetcor-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pynetcor-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pynetcor-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cd6af35920ed710a256b14af9584a4618c792efdff0e3e1f6653252a8f30fce6
MD5 d553b2f9c85d8dd9c866f0489f0bc9a2
BLAKE2b-256 9f1d794ac9ffc22062b4b3c5ce0bbb04e4b98ea69d57817eb4a0200af38c3833

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5044bf50d7b9b66f6867158fd5773b849308c2ae78ccbaf7844956272653162a
MD5 0b6fab524c470f3980bb83f69c94bf9e
BLAKE2b-256 33e9b12f2c200ca1bd0a10f0fc8b0f8e0c9f73d946b8b16d20b74b124acbf417

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 479f2012e6812de01f199d8fda970517abbb3a328b256d28bfff9a7618939451
MD5 e02e3a2b7f19122ac728faf892f63810
BLAKE2b-256 e9b16a007bf931adb2d5965a252850a95c2668b74ee1b49d4ec8b92fbef812c8

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pynetcor-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pynetcor-0.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 86e51c99007382df35d5d8a357832b32acba10da8fd9e7ffb3874f00c2c9125b
MD5 951a14845eaeb315512acc9878385c70
BLAKE2b-256 d1e2055739eba24acf7d55357fe1a303d4445640550454875f8a631bd0f35f00

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea1633d0210195af1f58e2e86f7e32d3520f60af908be25a65b4d7ea1e120346
MD5 243eb869b8a783493fc6324a6285d55f
BLAKE2b-256 5e368e1a0fdb4c7ef7a7855ae72dc976f75e91289e73b7f88aebedc116015ed9

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a6c0f19b269c2819a7f4ca5d200c5c45622054323b2c8fc5e07dd676bd1fa803
MD5 1421dbd69a91e6e1919bd839f8da9796
BLAKE2b-256 603cbe303a1dd79a17549307e1a6d05947300b5bc8952a01e7ba2fc75903dd78

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pynetcor-0.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pynetcor-0.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 12fabf5b9ac41df54a8a1c0bae306c272dccd0643b774dd768b76b0cd991852c
MD5 678de7eaafa8be9b571ebce1e0871e3b
BLAKE2b-256 4d9480096a55858b175d8577eb145cce3ad922eb1a6f4b38f34b42e387982099

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1296b199b7b87200539ef53ec8bfcdc259fa08d1ff4372a5d758b07cd5d9b7dd
MD5 6bafff83aed3d53fc7a9fb62917d8281
BLAKE2b-256 3e589f9e50e66044b37eb83f6e1883284b8604c6bf4ca7515c98c0efe51b051a

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f0dda03e1cb56cbd88392a0bd3a788d2c9be1553b8d17cbdd6aa75cf32c4d2b
MD5 992429d197c16088289a1bfdcab1dc38
BLAKE2b-256 43c98b4f9c9ac3f60b17b5916eac0e3119b782129fad66f091a54fd50e9affad

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pynetcor-0.1.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pynetcor-0.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5e69733c99129e03e7a815e8d88b0adf93eb39a4904fa8877ee5e04ad044a1aa
MD5 a6443805e60d9971e21f7ab3b03471e2
BLAKE2b-256 6437f26143362b3dc7b4e11d8ba4314559f47116d32aea21e2515662f902a42d

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 65a35747f2491bc2338e89a9a1fa6c31e940720f4623b85aea6e148b229c6185
MD5 07e738a75f2f87cf8cc03c051a668ce6
BLAKE2b-256 8ca41637f02e4fe44e51e4800f925902bc1115d138898f3110264aada91b6b07

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a9c842a7d77f35402b3ecd34f93bbde458c52c96ff53cf94581c4e6df7c73029
MD5 b6bc15d259b70e8c410991b18f9bbc98
BLAKE2b-256 104955d7ddda51e7f6a614ca0b956ec29b5bb576289d1c3b9e28e3d95bf9f753

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pynetcor-0.1.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pynetcor-0.1.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b9762110bfca83f4fd1c8144d5be8130d0bf5e1b390c3305c39cb73d3e35a1a1
MD5 9ebe67a955fdb0d821baf16dab0ee583
BLAKE2b-256 1819a7229b1919f6a3ac0db8feaba867d87faad5aca224921f159a4f28be354c

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea4f1ba9f0ac61802e72a47459441c79f41c0abe4688df75385d2b62e54ae867
MD5 acac2d0cd8498539e98cd50706d67152
BLAKE2b-256 9d3add573d6ff0fb342c47086a2d76a09bef99a493a9e8252eb9e6e42ca5e262

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1bc06c7412aff43cea52055040af8b043c4c54ba475945e58700e97eadd86e2a
MD5 6eb699ebb6a4f1a04b82a0f97e9da3e0
BLAKE2b-256 6b1ce3124890f5237c1c6a9e9fab3ad75aede489570760893f3c789577070099

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: pynetcor-0.1.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 7.8 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pynetcor-0.1.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ff2570e4e6ca36a2d2328dd4e377236398cb51aea6a67b38234ef91f4ea564c2
MD5 fbde5b7d617141db51cb16bd8485e2bb
BLAKE2b-256 25530ae096c68cad07408e1c08c5253a825fe05d9e7e813c5ee88e7d3bb6af16

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab980c7dec39148f4945e06bbf16c261f1060348d654531b76a69165eb117567
MD5 0f3f9e435fd82f13e28ad461a561977c
BLAKE2b-256 09ad7c4b9195a756ea364169ae2e1b0353f0d807dfa2c22fa238bac187da76cf

See more details on using hashes here.

File details

Details for the file pynetcor-0.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pynetcor-0.1.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b41f0455d85905db675d425acb9ddf208c2aaeb91ea5d32083baab83bf959d40
MD5 e23e28e893285d6639a80f11cf49879d
BLAKE2b-256 6c2c43e8d569733fa008e03fd869f932b5aa75df8fdd37fe87791c7e76236ea8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page