Skip to main content

A Python implementation of the SOM training functionality of FlowSOM

Project description

Build Status Coverage Status

pyFlowSOM

Python runner for the FlowSOM library.

Basic usage:

import pandas as pd
from pyFlowSOM import map_data_to_nodes, som

df = pd.read_csv('examples/example_som_input.csv')
example_som_input_arr = df.to_numpy()
node_output = som(example_som_input_arr, xdim=10, ydim=10, rlen=10)
clusters, dists = map_data_to_nodes(node_output, example_som_input_arr)

To put the data back into dataframes:

eno = pd.DataFrame(data=node_output, columns=df.columns)
eco = pd.DataFrame(data=clusters, columns=["cluster"])

To export to csv:

eno.to_csv('examples/example_node_output.csv', index=False)
eco.to_csv('examples/example_clusters_output.csv', index=False)

To plot the output as a heatmap:

import seaborn as sns

# Append results to the input data
example_som_input_df['cluster'] = clusters

# Find mean of each cluster
df_mean = example_som_input_df.groupby(['cluster']).mean()

# Make heatmap
sns_plot = sns.clustermap(df_mean, z_score=1, cmap="vlag", center=0, yticklabels=True)
sns_plot.figure.savefig(f"example_cluster_heatmap.png")

Develop

Continually build and test while developing. This will automatically create your virtual env

./build.sh && ./test.sh

The C code (pyFlowSOM/flosom.c) is wrapped using Cython (pyFlowSOM/cyFlowSOM.c).

Tests do an approximate exact comparison to cluster id groundtruth and an approximate comparison to node values only because of floating point differences. All randomness has stubbed out in in the y2kbugger/FlowSOM fork and works in tandem to the deterministic flag to the som function.

To regenerate test data, which may be required if you changed any sources of randomness:

python -m pyFlowSOM.generate_test_outputs

To generate heatmaps for manual comparison:

python -m pyFlowSOM.generate_test_heatmaps

To bump the version and deploy to pypi:

Just add the tag which matches the version you want to deploy:

git tag v0.1.4
git push --tags

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

pyFlowSOM-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (518.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyFlowSOM-0.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (511.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pyFlowSOM-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (485.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyFlowSOM-0.1.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (477.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pyFlowSOM-0.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (494.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyFlowSOM-0.1.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (487.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

Supported by

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