Skip to content

Instantly share code, notes, and snippets.

View Zsailer's full-sized avatar

Zachary Sailer Zsailer

View GitHub Profile
@Zsailer
Zsailer / draw_networkx_nodes_ellipses.py
Last active July 27, 2020 14:52
Drawing NetworkX plots with ellipses for nodes
import networkx as nx
def draw_networkx_nodes_ellipses(G, pos,
nodelist=None,
node_height=1,
node_width=2,
node_angle=0,
node_color='r',
node_shape='o',
alpha=1.0,
@Zsailer
Zsailer / README.md
Last active May 27, 2016 00:22
Resample the output a function until the value convergences to given tolerance

Resample function until convergence

Python function that will rerun a function until its output convergences. The output must be numerical values. It can been an int, float, list, or array. Requires numpy.

This method runs the function in chunks (N=sample_size). It calculates the mean and standard deviation of the total set of samples after each chunk. If the mean and standard deviation of the total set is relatively close (see rtol) the last iteration, the sampling is assumed to have converged.

@Zsailer
Zsailer / discrete_cmap.py
Created August 18, 2016 17:31 — forked from jakevdp/discrete_cmap.py
Small utility to create a discrete matplotlib colormap
# By Jake VanderPlas
# License: BSD-style
import matplotlib.pyplot as plt
import numpy as np
def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""
@Zsailer
Zsailer / README.md
Last active October 10, 2016 17:31
Proposal for D3 inspired JSON format for Dendropy's Tree Class

Dendropy's Tree class to JSON format

A proposed JSON format for Dendropy's Tree class. This is D3 inspired, and easily portable to all of D3's hierarchical visualization examples.

Example

For the following example, I'll use the simple string (taken from wikipedia) converted to a JSON format

(A:0.1,B:0.2,(C:0.3,D:0.4)E:0.5)F;  
@Zsailer
Zsailer / README.md
Last active August 3, 2017 23:21
Towards defining a tree JSON format

Towards defining a (phylogenetic) tree JSON Format

After a fair bit of digging, I was unable to find a single, defined JSON structure for phylogenetic data. With awesome visualization libraries (like D3) emerging, I think it is necessary to standardize a JSON grammar to allow libraries like DendroPy to access such visualizations.

In this document, I attempt to define this set of rules and grammar.

Metadata Keys

@Zsailer
Zsailer / hide_single_cell.py
Last active July 10, 2023 15:41
Hide a single cell in Jupyter notebook
from IPython.display import HTML
from IPython.display import display
# Taken from https://stackoverflow.com/questions/31517194/how-to-hide-one-specific-cell-input-or-output-in-ipython-notebook
tag = HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
@Zsailer
Zsailer / flavor1.py
Last active January 29, 2018 17:16
post-1
import pandas as pd
import pandas_flavor as pf
@pf.registor_dataframe_method
def check_columns(df):
# Required columns
required_cols = {'x', 'y', 'z'}
# Find columns missing from
if required_cols.issubset(df.columns) is False:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Zsailer
Zsailer / README.md
Created February 22, 2018 18:04
conda environment + jupyter kernel

Create conda environment.

conda create -n <kernel name> pip jupyter 

Activate environment.

source activate <kernel name>
@Zsailer
Zsailer / main.py
Last active May 30, 2018 21:39
PhyloVega Example API
import phylovega as phy
tree = phy.Tree(data).encode(
nodes=[],
edges=[],
node_color=[],
edge_color=[],