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 / ena_download.py
Last active February 6, 2024 16:31
Dump fastq-dump! Download NCBI-SRA FASTQs directly from the European Nucleotide Archive.
#!/usr/bin/env python
import hashlib
import os.path as op
import os
import re
import warnings
from contextlib import closing
from urllib.parse import urlsplit
from urllib.request import urlopen
@nvictus
nvictus / loadnpy.js
Last active November 4, 2023 18:47
NumPy binary file parser for javascript
// Client-side parser for .npy files
// See the specification: http://docs.scipy.org/doc/numpy-dev/neps/npy-format.html
var NumpyLoader = (function () {
function asciiDecode(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
function readUint16LE(buffer) {
var view = new DataView(buffer);
var val = view.getUint8(0);
@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 / 01-simplify_vcf_info.ipynb
Last active August 31, 2023 19:52
Extract info fields from a VCF dataframe
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nvictus
nvictus / filelike.py.ipynb
Created August 23, 2023 14:10
File-likes in pyoxbow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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:
@nvictus
nvictus / doi2bib
Last active February 27, 2023 23:48
Fetch reference citations in BibTeX, JSON or YAML from DOI
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import tempfile
import requests
import argparse
import textwrap
import sys
@nvictus
nvictus / ornstein_uhlenbeck.py
Last active January 20, 2022 02:37
Approximate and exact sampling of an OU noise process
import numpy as np
def ou_approx(t, theta=0.15, sigma=0.2, x0=0, xm=0):
"""
Ornstein-Uhlenbeck process sampled using an approximate updating formula, first-order in the time step.
The approximation gets worse as the time steps get larger.
Parameters
@nvictus
nvictus / cool.r
Last active August 27, 2021 15:59
coolR: a cooler reader for R
# Notes
# -----
# * Cooler's stored bin IDs are 0-based. However, for consistency with R, this API should take
# 1-based indexing as input for table row and matrix range queries.
# * See Ilya's implementation: https://github.com/dozmorovlab/HiCcompare/issues/9
library(hdf5r)
library(dplyr)
library(tibble)
library(purrr)
library(data.table)
@nvictus
nvictus / keybase.md
Created March 30, 2021 13:54
keybase.md

Keybase proof

I hereby claim:

  • I am nvictus on github.
  • I am nvictus (https://keybase.io/nvictus) on keybase.
  • I have a public key ASD5ZCiGIU56jaoWB80la1wXlnkF_bnTkhPPU21ajb-5eQo

To claim this, I am signing this object: