Skip to content

Instantly share code, notes, and snippets.

View nvictus's full-sized avatar

Nezar Abdennur nvictus

  • UMass Chan Medical School
  • Greater Boston Area
View GitHub Profile
@nvictus
nvictus / gillespie_nrm.py
Last active October 1, 2020 15:35
Next-Reaction Method variant of the Gillespie stochastic simulation algorithm.
from pqdict import pqdict
from numpy import array, zeros, log, seterr
from numpy.random import rand
from collections import Counter
from matplotlib import pyplot as plt
seterr(divide="ignore")
class Reaction(object):
@nvictus
nvictus / pqdict_dijkstra_example.py
Last active July 5, 2023 03:01
Python: Dijkstra's algorithm using the pqdict module
from pqdict import pqdict
def dijkstra(graph, source, target=None):
dist = {} # lengths of the shortest paths to each node
pred = {} # predecessor node in each shortest path
# Store distance scores in a priority queue dictionary
pq = pqdict.minpq()
for node in graph:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nvictus
nvictus / gist:240c9e9ee33e20d02a36
Created October 9, 2014 23:19
conda "workon" alias
CONDA_DIR="$HOME/miniconda"
alias workon='source $CONDA_DIR/bin/activate'
# function workon () {
# source "$CONDA_DIR/bin/activate" "$1"
# }
function __conda_user_setup () {
_workon_tab_completion_bash () {
@nvictus
nvictus / example-ucsc.ipynb
Last active September 2, 2016 06:56
UCSC genome browser to matplotlib
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nvictus
nvictus / lexbisect.py
Last active January 14, 2016 03:35
Bisection search on lexically sorted sequences in Python.
def lexbisect(arrays, values, side='left', lo=0, hi=None):
"""
Bisection search on lexically sorted arrays.
Parameters
----------
arrays : sequence of k 1-D array-like
Each "array" can be any sequence that supports scalar integer indexing,
as long as the arrays have the same length and their values are
lexsorted from left to right.
@nvictus
nvictus / cooler_example.ipynb
Last active August 11, 2016 00:23
cooler-example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nvictus
nvictus / runlength.py
Last active October 7, 2023 19:54
NumPy run-length encoding / decoding
"""Run Length Encoding utilities for NumPy arrays.
Authors
-------
- Nezar Abdennur
- Anton Goloborodko
"""
from __future__ import division, print_function
import numpy as np
@nvictus
nvictus / post_mortem_hook.py
Created August 7, 2016 07:15
Post mortem exception hook with ipdb
def set_postmortem_hook():
import sys, traceback, ipdb
def _excepthook(exc_type, value, tb):
traceback.print_exception(exc_type, value, tb)
print()
ipdb.pm()
sys.excepthook = _excepthook