Code Monkey home page Code Monkey logo

agartland / hierdiff Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 3.0 753 KB

A package that is useful for clustering high-dimensional instances (e.g. T cell receptors) and testing whether clusters of instances are differentially abundant in two or more categorical conditions. The package provides d3/SVG rendering of scipy hierarchical clustering dendrograms with zooming, panning and tooltips. This uniquely allows for exploring large trees of datasets, conditioned on a categorical trait.

License: MIT License

Python 2.63% HTML 97.37%

hierdiff's Introduction

hierdiff

Build Status PyPI version Coverage Status

A package that is useful for clustering high-dimensional instances (e.g. T cell receptors) and testing whether clusters of instances are differentially abundant in two or more categorical conditions. The package provides d3/SVG rendering of scipy hierarchical clustering dendrograms with zooming, panning and tooltips. This uniquely allows for exploring large trees of datasets, conditioned on a categorical trait.

Installation

pip install hierdiff

Example

import hierdiff
from scipy.spatial.distance import squareform

"""Contains categorical variable column 'trait1' and
instance counts in 'count'"""
dat, pwdist = generate_data()

res, Z = hierdiff.hcluster_tally(dat,
				                  pwmat=squareform(pwdist),
				                  x_cols=['trait1'],
				                  count_col='count',
				                  method='complete')

res = hierdiff.cluster_association_test(res, method='fishers')

"""Plot frequency of trait at nodes with p-value < 0.05"""
html = plot_hclust_props(Z, title='test_props2',
                            res=res, alpha=0.05, alpha_col='pvalue')

example

hierdiff's People

Contributors

agartland avatar kmayerb avatar

Watchers

 avatar  avatar  avatar

hierdiff's Issues

plot_hclust_props() using prune_col, got error KeyError: 'members'

KeyError: 'members', probably a hold over before we harmonized to neighbors

Consider swapping 'neighbors' for 'members', there may be more issues, but this might be a place to start.

            if not prune_col is None:
                """Prune (don't print) if all member results are also prune=True"""
                prune = res.loc[res['cid'].isin(cid_res['members']), prune_col].all()
                if prune:
                    continue

if not prune_col is None:
"""Prune (don't print) if all member results are also prune=True"""
prune = res.loc[res['cid'].isin(cid_res['members']), prune_col].all()
if prune:
continue

KeyError                                  Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2888             try:
-> 2889                 return self._engine.get_loc(casted_key)
   2890             except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'members'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
<ipython-input-40-6f7a7c20e30d> in <module>
      6             alpha=0.00001, colors = ['blue','gray'],
      7             alpha_col='pvalue',
----> 8             prune_col = 'prune_me')

/opt/conda/lib/python3.7/site-packages/hierdiff/hier_plot.py in plot_hclust_props(Z, title, res, alpha_col, alpha, tooltip_cols, colors, prune_col)
     78                                                             tooltip_cols=tooltip_cols,
     79                                                             colors=colors,
---> 80                                                             prune_col=prune_col)
     81
     82     #lines_df = 100 * pd.DataFrame({'x1':np.random.rand(10), 'y1':np.random.rand(10), 'x2':np.random.rand(10), 'y2':np.random.rand(10)})

/opt/conda/lib/python3.7/site-packages/hierdiff/hier_plot.py in _hclust_paths(Z, height, width, margin, res, alpha_col, alpha, tooltip_cols, colors, min_count, prune_col)
    145             if not prune_col is None:
    146                 """Prune (don't print) if all member results are also prune=True"""
--> 147                 prune = res.loc[res['cid'].isin(cid_res['members']), prune_col].all()
    148                 if prune:
    149                     continue

/opt/conda/lib/python3.7/site-packages/pandas/core/series.py in __getitem__(self, key)
    880
    881         elif key_is_scalar:
--> 882             return self._get_value(key)
    883
    884         if (

/opt/conda/lib/python3.7/site-packages/pandas/core/series.py in _get_value(self, label, takeable)
    989
    990         # Similar to Index.get_value, but we do not fall back to positional
--> 991         loc = self.index.get_loc(label)
    992         return self.index._get_values_for_loc(self, loc, label)
    993

/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2889                 return self._engine.get_loc(casted_key)
   2890             except KeyError as err:
-> 2891                 raise KeyError(key) from err
   2892
   2893         if tolerance is not None:

KeyError: 'members'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.