Skip to content

Instantly share code, notes, and snippets.


Heng Li lh3

View GitHub Profile
lh3 / Dockerfile
Created Mar 18, 2020
Tmp dockerfile
View Dockerfile
#creates a base image from condo
FROM continuumio/miniconda3
SHELL ["/bin/bash", "-c"]
COPY environment.yml .
#run environment
#RUN conda env create -f environment.yml
RUN conda init bash
View self-chain.c
// To compile:
// gcc -g -O2 example.c libminimap2.a -lz
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <zlib.h>
#include "minimap.h"
#include "kseq.h"
KSEQ_INIT(gzFile, gzread)
lh3 / fast-sqrtf.c
Created Aug 24, 2019
Fast square root
View fast-sqrtf.c
// a combination of inverse square root (see wiki) and inversion:
static inline float mg_sqrtf(float x)
union { float f; uint32_t i; } z = { x };
z.i = 0x5f3759df - (z.i >> 1);
z.f *= (1.5f - (x * 0.5f * z.f * z.f));
z.i = 0x7EEEEEEE - z.i;
return z.f;
lh3 / Makefile
Last active Oct 30, 2018
Position-specific gap open penalty
View Makefile
gg:ksw2_ggd.c cli.c ksw2.h
$(CC) -Wall -g -O2 -o $@ ksw2_ggd.c cli.c
rm -fr *.o *.dSYM gg
View refret.sql
checksum TEXT,
ac TEXT, -- INSDC sequence accession, when available
len INTEGER, -- could be of type "TEXT"; no need to implement "less than"
seq TEXT,
PRIMARY KEY (checksum) -- what about collisions?
CREATE INDEX seq_len ON seq (len)
CREATE INDEX seq_ac ON seq (ac) -- different checksums may have the same AC

NA12878 DirectRNA reads were obtained [here][raw-data] (passed reads only) and aligned with [minimap2][minimap2] v2.5 against the no_alt_analysis_set of GRCh38 plus SIRV contigs. It took <1 wall-clock hour across 16 CPU cores with command-line options: -cx splice -k14 --cs -uf -N20 -t16. Alignments were converted to BED with the misc/splice2bed.js script from minimap2 and then converted to BigBed. Ribosome-related genes (RPL*, RPS*, EEF* and RPSA) were excluded to reduce the file size. The final BigBed is hosted [at OSF][osf-prj].

A UCSC custom track is configured with

track type=bigBed name=NA12878-DirectRNA.minimap2-2.5 useScore=1 visibility=4 itemRgb="On" bigDataUrl=

You can access this track with the [following link][direct-link]. A GMAP alignment track is temporarily available [here][gmap]. This track contains 1/4 of reads. GMAP is still running. It will take 4–5 wall-clock

lh3 / x86-simd.c
Created Sep 5, 2017
Get supported SIMD instruction sets (x86 only)
View x86-simd.c
#include <stdio.h>
#define SIMD_SSE 0x1
#define SIMD_SSE2 0x2
#define SIMD_SSE3 0x4
#define SIMD_SSSE3 0x8
#define SIMD_SSE4_1 0x10
#define SIMD_SSE4_2 0x20
#define SIMD_AVX 0x40
#define SIMD_AVX2 0x80
View fraglen.c
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "kstring.h"
#include "sam.h"
#include "kbtree.h"
typedef struct {
int pos, n, sum;
lh3 / getopt.c
Last active Feb 11, 2022
Portable getopt/getopt_long from musl
View getopt.c
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "getopt.h"
char *optarg;
int optind=1, opterr=1, optopt, __optpos, optreset=0;
#define optpos __optpos