Skip to content

Instantly share code, notes, and snippets.

View danielecook's full-sized avatar
😀
Things are going good

Daniel E Cook danielecook

😀
Things are going good
View GitHub Profile
@danielecook
danielecook / row_iterator.R
Last active April 19, 2020 15:02
R row iterator
rows <- function(tab, idx=TRUE) {
# Set idx to attach an index column
if (is.na(tab) || is.null(tab) || nrow(tab) == 0) {
return(list())
}
lapply(seq_len(nrow(tab)),
function(i) {
row <- unclass(tab[i,,drop=F])
if (idx) {
row$idx <- i
@danielecook
danielecook / bash-cheatsheet.sh
Created November 22, 2019 09:50 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@danielecook
danielecook / nextflow-bash.sh
Last active January 26, 2024 18:03
Useful nextflow bash functions
# Shortcut for going to work directories
# Usage: gw <workdir pattern>
# Replace the work directory below as needed
# Where workdir pattern is something like "ab/afedeu"
function gw {
path=`ls --color=none -d /path/to/work/directory/$1*`
cd $path
}
# Go work that fetches work dir from .nextflow.log
@andy-thomason
andy-thomason / Genomics_A_Programmers_Guide.md
Created May 14, 2019 13:32
Genomics a programmers introduction

Genomics - A programmer's guide.

Andy Thomason is a Senior Programmer at Genomics PLC. He has been witing graphics systems, games and compilers since the '70s and specialises in code performance.

https://www.genomicsplc.com

@Vindaar
Vindaar / callNimFromR.org
Created March 11, 2019 09:45
How to call Nim code from R using `.C` interface

Calling Nim from R

A super short introduction how to call Nim code from R using the .C interface. I’m not an R user normally, so I googled and used this post as a reference: https://www.r-bloggers.com/three-ways-to-call-cc-from-r/

Writing our Nim procedure

Let’s define a simple procedure, which we want Nim to do:

@elowy01
elowy01 / BCFtools cheat sheet
Last active November 11, 2024 12:50
BCFtools cheat sheet
*bcftools filter
*Filter variants per region (in this example, print out only variants mapped to chr1 and chr2)
qbcftools filter -r1,2 ALL.chip.omni_broad_sanger_combined.20140818.snps.genotypes.hg38.vcf.gz
*printing out info for only 2 samples:
bcftools view -s NA20818,NA20819 filename.vcf.gz
*printing stats only for variants passing the filter:
bcftools view -f PASS filename.vcf.gz
@sloanlance
sloanlance / jq_tsv_conversion.md
Last active September 13, 2024 10:08
jq: JSONL → TSV conversion

jq: JSONL → TSV conversion

What is TSV?

TSV means "tab-separated values". I prefer this format over CSV ("comma-separated values") because it doesn't require as much quoting. Many programs that can use CSV formatted data can also use TSV, although they may need to be explicitly told of the different format if it's not detected automatically.

However, in any of the jq scripts below, "@tsv" can usually be replaced with "@csv" to get CSV output instead.

@nevesnunes
nevesnunes / pdftitle.py
Last active April 7, 2024 07:24 — forked from hanjianwei/pdftitle.py
Extract title from pdf file.
#!/usr/bin/env python2.7
"""
Extract title from PDF file.
Dependencies:
pip install --user unidecode pyPDF PDFMiner
Usage:
find . -name "*.pdf" | xargs -I{} pdftitle -d tmp --rename {}
@stephenturner
stephenturner / keybindings.json
Created May 31, 2017 21:04
VSCode keybindings to replicate my most commonly used RStudio shortcuts (Mac)
// Place your key bindings in this file to overwrite the defaults
[
// RStudio: Copy lines up/down with alt+cmd+up/down
{
"key": "alt+cmd+down",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+down",
@itdaniher
itdaniher / rle.py
Last active October 23, 2021 11:26
Run Length Encoding, Two Ways
import numpy as np
import itertools
def rle(x):
where = np.flatnonzero
x = np.asarray(x)
n = len(x)
if n == 0:
return np.array([], dtype=int)
starts = np.r_[0, where(~np.isclose(x[1:], x[:-1], equal_nan=True)) + 1]